Skip to main content

Creating Objects

This page uses Wasm code blocks so you can run the examples directly in the browser.

The create statement can be used to populate the database by creating objects of a given type. Each new objects can thereby be assigned initial values for specified attributes (properties).

Example:

create type Person;
create function name(Person) -> Charstring as stored;
create function income(Person) -> Real as stored;
create Person(name, income) instances
("Venus",350),
("Serena",390)

The attributes can be any updatable OSQL function having the created type as its only argument, here name() and income(). For each new object a comma-separated list of initial values for the specified attributes functions can be specified as in the example.

Each initializer can have an optional variable name, which will be bound to the new object. The variable name can subsequently be used as a reference to the object.

Example:

create Person(name, income) instances
:pelle ("Per",383);
income(:pelle)

Expressions can be used when specifying initial values, for example:

create Person (name,income) instances
:kalle ("Kalle "+"Persson" , 200*1.5);
name(:kalle);
income(:kalle)

The types of the initial values must match the declared result types of the corresponding functions.

It is possible to specify null for a value when no initialization is desired for the corresponding function. Bag valued functions are initialized using the syntax bag(e1,...).

In Section Updates more ways of changing the contents of the database are described.

Deleting objects​

Objects are deleted from the database with the delete statement.

Example:

delete :pelle

The system will automatically remove the deleted object from all stored functions where it is referenced. Deleted objects are printed as:

#[OID nnn *DELETED*]