Skip to main content

Create statement

Must specify all attributes that don't have default values:

create user(name = 'Bob', company = company @ { .name == 'Amazon' });

You don't need to specify the attribute name if it's matched by name or type:

val name = 'Bob';
create user(name, company @ { company.name == 'Amazon' });

Can use the created object:

val new_company = create company(name = 'Amazon');
val new_user = create user(name = 'Bob', new_company);
print('Created new user:', new_user);

Inserting multiple records:

A new variant of the "create" expression allows for the insertion of multiple database records with a single SQL statement, improving efficiency compared to inserting records one by one. It accepts a list of structs representing records of a specific type. If the list is empty, no SQL statement is executed. The expression returns a list of the inserted entities, maintaining the same size and order as the input list.

create MyEntity(list<struct<MyEntity>>): list<MyEntity>;