Crud Functions

Persistent operations (Create, Read, Update and Delete) are performed using the functions documented on this page.

createMultiple

available since: 1.0.0

createMultiple persists multiple objects at once, enabling cyclic references. It acts as if all inserts happen at once. Unlike create, it takes a map of values. The keys are freely assignable by the user. Refs in the inserted objects can point to the assigned map keys and will be rewritten to their final ID.

struct {
  • in :refmodel(T)
  • values :mapT
}
maprefT

Example:

Query:
e.createMultiple(e.tag(d.string("myModel")), {
  • a: f.function(["refs"], e.data(d.struct({
    • myString: d.string("a"),
    • myInt: d.int32(1),
    • myBool: d.bool(true),
    }
    )
    )
    )
    ,
  • b: f.function(["refs"], e.data(d.struct({
    • myString: d.string("b"),
    • myInt: d.int32(2),
    • myBool: d.bool(false),
    }
    )
    )
    )
    ,
}
)
Result:
{ "a": [ "XhLaWkGPNTXywfAQ", "tBsyChQtmiBhXbRd" ], "b": [ "XhLaWkGPNTXywfAQ", "HDLenLovpAByZJNo" ] }
Notes:

This query is based on the examples in the create expression. Yields a map with the same keys as the value map but with references to the persisted objects instead of their values.

all

available since: 1.0.0

Takes a reference to a model and returns an unordered list of the objects in said model. Note that the output will be trimmed to 1000 elements. However, list manipulation operations (such as filtering and mapping) will affect the entire list.

refmodel(T)listT

Example:

Query:
e.all(e.tag(d.string("_tag")))
Result:
[ { "model": [ "FCyAReCEenjhJqsb", "CwdniKJtBtIlEYzI" ], "tag": "_tag" }, { "model": [ "FCyAReCEenjhJqsb", "GLEhvScBdSWYZBRW" ], "tag": "_expression" }, { "model": [ "FCyAReCEenjhJqsb", "FCyAReCEenjhJqsb" ], "tag": "_model" }, { "model": [ "FCyAReCEenjhJqsb", "ReUjWMdaHvGAJvzZ" ], "tag": "_role" }, { "model": [ "FCyAReCEenjhJqsb", "JPHNleKUAeTnXqlb" ], "tag": "_user" }, { "model": [ "FCyAReCEenjhJqsb", "sOolKDIdxgMuyQcg" ], "tag": "_migration" } ]
Notes:

yields a list of objects in the _tag model.

zero

available since: 1.0.0

zero is a "special" niladic function that can be used in expressions where a concrete return type is expected, which is not a ref. In these scenarios, zero() will return an empty "skeleton" value with the correct structure and type expected.

any

Example:

Query:
e.get({
  • scope: "record",
}
)
Result:
{ "bar": 0, "foo": "" }

get

available since: 1.0.0

get takes a ref and returns a single persistent object or returns an error if the object was not found.

refTT

Example:

Query:
e.get(e.refTo(e.first(e.all(e.tag(d.string("_tag"))))))
Result:
{ "model": [ "RdVuJLdTKaxCcBHo", "FMuBhfUuaTIpSYsF" ], "tag": "_tag" }
Notes:

This example yields the first object of the _tag type. You may get the same result with a shorter query (eg. all(tag(_tag))) but this example is about the get param

update

available since: 1.0.0

changes the value of an existing persistent object. It takes a struct argument with two fields: ref and value. Field ref must be a ref to the object to replace with argument value. It yields a ref to the object in question.

struct {
  • ref :refT
  • value :T
}
refT

Example:

Query:
e.update({
  • ref: e.refTo(e.first(e.all(e.tag(d.string("myModel"))))),
  • value: e.data(d.struct({
    • myString: d.string("my updated string content"),
    • myInt: d.int32(777),
    • myBool: d.bool(false),
    }
    )
    )
    ,
}
)
Result:
[ "XhLaWkGPNTXywfAQ", "kLccoTYVQihppuJy" ]
Notes:

This query is based on the examples in the create expression. Will change the value of the first object of our example model with tag 'myModel'

delete

available since: 1.0.0

removes a persisted object from a model's collection permanently. It takes a ref to the object to delete and returns the deleted object.

refTT

Example:

Query:
e.delete(e.refTo(e.first(e.all(e.tag(d.string("myModel"))))))
Result:
{ "myBool": false, "myInt": 777, "myString": "my updated string content" }
Notes:

This query is based on the examples in the create expression. Will delete the first object of our example model with tag 'myModel'

create

available since: 1.0.0

persists an object in a model's collection. Field in must be a ref to the model in which to persist the value in field value. It returns a ref to the newly created object.

struct {
  • in :refmodel(T)
  • value :T
}
refT

Example:

Query:
e.create(e.tag(d.string("_model")), f.function(["param"], e.data(m.struct({
  • myString: m.string(),
  • myInt: m.int32(),
  • myBool: m.bool(),
}
)
)
)
)
Result:
[ "RdVuJLdTKaxCcBHo", "eCGXRjxwHUkQnmzC" ]
Notes:

This example persists a new object of the type _model and yields a ref e.g. ["PTmcyzYCwsaoKsjy","NuqdLqlTbjUfSjkf"] to the persisted object

Example:

Query:
e.create(e.tag(d.string("_tag")), f.function(["param"], e.data(d.struct({
  • tag: d.string("myModel"),
  • model: d.expr({
    • scope: "myNewModel",
    }
    )
    ,
}
)
)
)
)
Result:
[ "FMuBhfUuaTIpSYsF", "HsdnBnrjGtkGsxEK" ]
Notes:

It's possible to nest expressions. This example creates the same model as above, and additionally a new _tag called 'myModel' to that model

Example:

Query:
e.create(e.tag(d.string("myModel")), f.function(["param"], e.data(d.struct({
  • myString: d.string("my string content"),
  • myInt: d.int32(333),
  • myBool: d.bool(true),
}
)
)
)
)
Result:
[ "XhLaWkGPNTXywfAQ", "kLccoTYVQihppuJy" ]
Notes:

Based on the last example, we can now create records in our new model 'myModel'