Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. entity: The keyword 'entity' keyword tells the C3 AI Suite this is a 'Persistable' type
  2. schema name: The schema names is the name of the database table, where the C3.a Type's data are stored. When defining a new Persistable type, you need to add the keywords 'schema name' followed by your chosen table name, in your .c3type file. (e.g., in the C3.ai Type LightBulb, we have 'schema name "LGHT_BLB"', where "LGHT_BLB" is our chosen table name). Please note, extended C3.ai Types DO NOT NEED a scheme name. Schema names CANNOT exceed 30 characters. 

To learn more about 'Persistable' Types, please see the C3.ai Resources below: 

...

Fields

As discussed above, a C3.ai Type mainly consists of two components: fields and methods.

Fields are attributes or properties Each field of a C3 Type is defined by first giving the field name .ai Type. To define a field on C3.ai Type, use the following syntax: field name, followed by a colon ':', followed by a Type.

The name must follow a set of conventions: – Name conventions here –

Depending on the Type of the field, the field is grouped into some broad categories.

Primitive Fields

Primitive Fields use types which are PrimitiveTypes. These are simple data types usually directly supported by database technologies such as SQL. These fields are stored directly within the main type's table.

Reference Fields

Reference Fields use another defined C3 Type. This reference is implemented in the main Type's table as a foreign key into the referenced Type's table, (The 'id' field!).

Collection Fields

ValueType (e.g., "lumens: int"). By convention, field names are camelCase.

A C3.ai Type can have many different kinds of fields. Here are the four most commonly used fields.

  • Primitive Fields 
  • Reference Fields 
  • Collection Fields 
  • Calculated Fields 

Primitive Fields

Like many other programming languages, the C3 AI Suite has primitive fields (e.g., int, boolean, byte, double, datetime, string, longstring). Primitive fields are stored in a particular C3.ai type's database table. 

Reference Fields

Reference fields point (or refer) to other C3.ai Types. Reference fields link (or join) two C3.ai Types together. Under the covers, the Reference field stores a pointer (i.e., foreign key reference or ID) to record of another C3.ai Type. To define a Reference field, use the following syntax: field name, followed by colon ':', followed by Type Name (e.g., "building: Building"). 

Collection Fields

Collection Fields contain a list of values or records. There are four categories of collections fields:Collection Fields are groups of Types. There are four broad categories of collections which can be used.

  • array: denoted by `[MyType]` (contains an array of references to 'MyType')
  • map: denoted by `map<int, MyType>` (the left argument is the key which can be any primitive type, while the ; right argument can be any C3.ai Type.)
  • set: denoted by `set<MyType>`
  • stream: denoted by `stream<MyType>`. (This is a read-once type of collection).

When we define a field which is a collection of MyType, we can also specify which MyTypes get added by using Collection fields can also be used to model one-to-many and many-to-many relationships between two C3.aiTypes. To do so, we sue the Foreign Key Collection Notation, which specifies the foreign key, by which two C3.ai Types (i.e., ThisType and AnotherType) are joined. To define this annotation, use the following syntax - "fieldName :   `[AnotherType]` (fkey, key)" ; where (1) 'fkey' is a field on `AnotherType' to use as the foreign key; (2) 'key' is an optional field on ThisType, whose records should match those of the 'fkey' field on 'AnotherType' (defaults to `id` field of ThisType, if not specified). In other words, the Collection field will contain pointers to all records in AnotherType, where ThisType.key == AnotherType.fkey.

In shown in the example code and diagram below, the field bulbMeasurements, contains a list of all the SmartBulbMeasurementSeries records, where SmartBulb.id == SmartBulbMeasurements.smartBulb (e.g., a list of various measurements relevant to a SmartBulb, like temperature or power). 


Please see the 'Foreign Key Collection and Schema Names" section in the following C3.ai Develop Documentation for more details: . If for example, we're trying to define the new type TheType, and we want a collection to have type [MyType], but we don't want all MyTypes to be in this collection, we can use the notation `(thetype, id)` which specifies that C3 Should only use MyTypes whose 'thetype' property matches TheType's id property. Please see the section 'Foreign Key Collection Notation and Schema Names' in the following C3.ai documentation where this concept is explained better: https://developer.c3.ai/docs/7.12.17/topic/mda-fields

...

...