CreateClass

CreateClass( param_object )
CreateClass( param_object )
CreateClass( param_object )
CreateClass( param_object )
create_class( param_object )
create_class name
CreateClass( param_object )
CreateClass( param_object )

Description

The CreateClass function is used to create a class which groups instance objects. Once the class has been created, it is possible to create instances in the class. You cannot create a class and insert records into that class in the same transaction.

Parameters

Argument Type Definition and Requirements

param_object

Object

The param_object fields are described below.

param_object

Field Name Field Type Definition and Requirements

name

String

The name of a class. Classes cannot be named any of the following reserved words: events, set, self, instances, or _.

data

Object

Optional - This is user-defined metadata for the class. It is provided for the developer to store information at the class level.

history_days

Long

Optional - The number of days instance history is retained for this class. Setting history_days to null retains this class’s history forever. It defaults to 30 days.

ttl_days

Long

Optional - The number of days instances are retained for this class. Instances which have not been updated within the configured TTL duration are removed. Setting ttl_days to null retains instances forever. The default is null.

permissions

Object

Optional - Provides the ability to enable permissions at the class level. See class permissions for additional details.

Returns

An object containing the fields returned by the CreateClass function is described below.

Field Name Field Type Definition and Requirements

ref

Reference

The reference is an automatically generated identifier within the database to uniquely identify the class that was created.

name

String

The name of the class that was created.

ts

Long

The timestamp associated with the creation of the instance.

history_days

Long

The number of days to retain history.

Examples

The query below creates a class called "boons" with defaults.

curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "create_class": { "object": { "name": "boons" } } }'
client.Query(CreateClass(Obj("name", "boons")));
System.out.println(
      client.query(
            CreateClass(Obj("name", Value("boons")))
      ).get());
result, _ := client.Query(f.CreateClass(f.Obj{"name": "boons"}))

fmt.Println(result)
client.query(CreateClass(Obj("name" -> "boons")))
client.query(q.create_class({"name": "boons"}))
$client.query do
  create_class name: 'boons'
end
client.query(CreateClass(Obj("name" => "boons")))
client.query(q.CreateClass({ name: "boons" }))
  .then((ret) => console.log(ret))
HTTP/1.1 201 Created
{
  "resource": {
    "ref": { "@ref": "classes/boons" },
    "class": { "@ref": "classes" },
    "ts": 1509244539971619,
    "history_days": 30,
    "name": "boons"
  }
}
{
  "ref": { "@ref": "classes/boons" },
  "class": { "@ref": "classes" },
  "ts": 1509244539971619,
  "history_days": 30,
  "name": "boons"
}
{
  ref: ref(id = "boons", class = ref(id = "classes")),
  ts: 1526674566802938,
  history_days: 30,
  name: "boons"
}
map[ref:{boons 0xc4201f2fa0 <nil>} ts:1527277025406385 history_days:30 name:boons]
{
  "ref": { "@ref": "classes/boons" },
  "class": { "@ref": "classes" },
  "ts": 1509244539971619,
  "history_days": 30,
  "name": "boons"
}
{
  "ref": { "@ref": "classes/boons" },
  "class": { "@ref": "classes" },
  "ts": 1509244539971619,
  "history_days": 30,
  "name": "boons"
}
{
  "ref": { "@ref": "classes/boons" },
  "class": { "@ref": "classes" },
  "ts": 1509244539971619,
  "history_days": 30,
  "name": "boons"
}
{
  "ref": { "@ref": "classes/boons" },
  "class": { "@ref": "classes" },
  "ts": 1509244539971619,
  "history_days": 30,
  "name": "boons"
}
{ ref: Ref(id=boons, class=Ref(id=classes)),
  ts: 1527274777496292,
  history_days: 30,
  name: 'boons' }

Was this article helpful?

We're sorry to hear that.
Tell us how we can improve! documentation@fauna.com

Thank you for your feedback!