A lightweight ORM #
deriving Entity and deriving Relation map a Lean structure to a TypeDB entity or relation
type (TypeDB.ORM.Deriving). The mapping is Lean-first: the structure is the source of truth,
Schema.define generates the TypeQL define for it, and verifySchema checks a live database
against it.
Fields map by their type:
τwith a TypeDB value type: an owned attribute, required (@card(1..1));Option τ: an optional attribute;Array τ: a multi-valued attribute (@card(0..));Key τ: the type's key (@key);Role "r" (Ref β)orRole "r" (Array (Ref β)): in a relation, the instances playing roler;Attr "l" τ: overrides the attribute label, which is otherwise the field name in kebab-case.
A structure that extends a mapped structure maps to a subtype (sub) and inherits its
attributes, roles and key. @[typedb "label"] on the structure sets the type label.
Instances are referenced by Ref α: by key value (Ref.key) or by IID (Ref.iid). insert
returns an IID reference.
Marks the field holding the type's key attribute. Transparent: a Key String is a String.
Equations
- TypeDB.Key α = α
Instances For
Marks a relation field holding the player(s) of role name.
Equations
- TypeDB.Role _name α = α
Instances For
Sets the TypeDB attribute label of a field.
Equations
- TypeDB.Attr _label α = α
Instances For
Equations
- One or more equations did not get rendered due to their size.
- TypeDB.ORM.instDecidableEqTarget.decEq (TypeDB.ORM.Target.key typeLabel keyAttr literal) (TypeDB.ORM.Target.iid iid) = isFalse ⋯
- TypeDB.ORM.instDecidableEqTarget.decEq (TypeDB.ORM.Target.iid iid) (TypeDB.ORM.Target.key typeLabel keyAttr literal) = isFalse ⋯
- TypeDB.ORM.instDecidableEqTarget.decEq (TypeDB.ORM.Target.iid a) (TypeDB.ORM.Target.iid b) = if h : a = b then h ▸ isTrue ⋯ else isFalse ⋯
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- TypeDB.ORM.instReprTarget = { reprPrec := TypeDB.ORM.instReprTarget.repr }
Equations
Equations
Equations
- TypeDB.ORM.instHashableTarget.hash (TypeDB.ORM.Target.key a a_1 a_2) = mixHash (mixHash (mixHash 0 (hash a)) (hash a_1)) (hash a_2)
- TypeDB.ORM.instHashableTarget.hash (TypeDB.ORM.Target.iid a) = mixHash 1 (hash a)
Instances For
Equations
- TypeDB.instReprRef.repr x✝ prec✝ = Std.Format.bracket "{ " (Std.Format.nil ++ Std.Format.text "target" ++ Std.Format.text " := " ++ (Std.Format.nest 10 (repr x✝.target)).group) " }"
Instances For
Equations
- TypeDB.instReprRef = { reprPrec := TypeDB.instReprRef.repr }
Equations
- TypeDB.instInhabitedRef = { default := TypeDB.instInhabitedRef.default }
Equations
Equations
- TypeDB.instBEqRef = { beq := fun (a b : TypeDB.Ref α) => a.target == b.target }
Equations
- TypeDB.ORM.instReprKind = { reprPrec := TypeDB.ORM.instReprKind.repr }
Equations
- TypeDB.ORM.instReprKind.repr TypeDB.ORM.Kind.entity prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ ≥ 1024 then 1 else 2) (Std.Format.text "TypeDB.ORM.Kind.entity")).group prec✝
- TypeDB.ORM.instReprKind.repr TypeDB.ORM.Kind.relation prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ ≥ 1024 then 1 else 2) (Std.Format.text "TypeDB.ORM.Kind.relation")).group prec✝
Instances For
Equations
Equations
- TypeDB.ORM.instToStringKind = { toString := fun (x : TypeDB.ORM.Kind) => match x with | TypeDB.ORM.Kind.entity => "entity" | TypeDB.ORM.Kind.relation => "relation" }
Equations
- TypeDB.ORM.instReprCard.repr TypeDB.ORM.Card.one prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ ≥ 1024 then 1 else 2) (Std.Format.text "TypeDB.ORM.Card.one")).group prec✝
- TypeDB.ORM.instReprCard.repr TypeDB.ORM.Card.opt prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ ≥ 1024 then 1 else 2) (Std.Format.text "TypeDB.ORM.Card.opt")).group prec✝
- TypeDB.ORM.instReprCard.repr TypeDB.ORM.Card.many prec✝ = Repr.addAppParen (Std.Format.nest (if prec✝ ≥ 1024 then 1 else 2) (Std.Format.text "TypeDB.ORM.Card.many")).group prec✝
Instances For
Equations
- TypeDB.ORM.instReprCard = { reprPrec := TypeDB.ORM.instReprCard.repr }
Equations
Equations
- TypeDB.ORM.instDecidableEqShape.decEq (TypeDB.ORM.Shape.attr a a_1) (TypeDB.ORM.Shape.attr b b_1) = if h : a = b then h ▸ if h : a_1 = b_1 then h ▸ isTrue ⋯ else isFalse ⋯ else isFalse ⋯
- TypeDB.ORM.instDecidableEqShape.decEq (TypeDB.ORM.Shape.attr valueType card) (TypeDB.ORM.Shape.role player many) = isFalse ⋯
- TypeDB.ORM.instDecidableEqShape.decEq (TypeDB.ORM.Shape.role player many) (TypeDB.ORM.Shape.attr valueType card) = isFalse ⋯
- TypeDB.ORM.instDecidableEqShape.decEq (TypeDB.ORM.Shape.role a a_1) (TypeDB.ORM.Shape.role b b_1) = if h : a = b then h ▸ if h : a_1 = b_1 then h ▸ isTrue ⋯ else isFalse ⋯ else isFalse ⋯
Instances For
Equations
- TypeDB.ORM.instReprShape = { reprPrec := TypeDB.ORM.instReprShape.repr }
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- TypeDB.ORM.instReprFieldSpec = { reprPrec := TypeDB.ORM.instReprFieldSpec.repr }
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Equations
- TypeDB.ORM.instValueTypeString = { name := "string" }
Equations
- TypeDB.ORM.instValueTypeBool = { name := "boolean" }
Equations
- TypeDB.ORM.instValueTypeInt64 = { name := "integer" }
Equations
- TypeDB.ORM.instValueTypeInt = { name := "integer" }
Equations
- TypeDB.ORM.instValueTypeNat = { name := "integer" }
Equations
- TypeDB.ORM.instValueTypeFloat = { name := "double" }
Equations
- TypeDB.ORM.instValueTypeDecimal = { name := "decimal" }
Equations
- TypeDB.ORM.instValueTypeDuration = { name := "duration" }
Equations
- TypeDB.ORM.instValueTypePlainDate = { name := "date" }
Equations
- TypeDB.ORM.instValueTypePlainDateTime = { name := "datetime" }
Equations
- TypeDB.ORM.instValueTypeDatetimeTZ = { name := "datetime-tz" }
Equations
- TypeDB.ORM.instValueTypeDateTime = { name := "datetime-tz" }
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- One or more equations did not get rendered due to their size.
Equations
- TypeDB.Ref.iid i = { target := TypeDB.ORM.Target.iid i }
Instances For
A reference by key value. Only types with a key attribute have one.
Equations
- TypeDB.Ref.key k = { target := TypeDB.ORM.Target.key (TypeDB.ORM.Mapped.label α) (TypeDB.ORM.Keyed.keyAttr α) (TypeDB.render k) }
Instances For
Equations
- r.iid? = match r.target with | TypeDB.ORM.Target.iid i => some i | TypeDB.ORM.Target.key typeLabel keyAttr literal => none
Instances For
The field data of one instance from its attributes and role players. Fields that share a role take its players in order: a single field one player, an array field the rest.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The attributes and role players of every instance matched by pattern (which binds $x):
two queries, whatever the number of instances.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Decodes the instances matched by pattern with the given fields.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Helpers the deriving handlers call: each is typed by a field's projection, so generated code never spells out field types.
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- TypeDB.ORM.columnOf x✝ name = TypeDB.FromColumn.column name
Instances For
Marks a structure derived as a TypeDB entity type (deriving Entity).
- mapped : Nonempty (ORM.Mapped α)
Instances
Marks a structure derived as a TypeDB relation type (deriving Relation).
- mapped : Nonempty (ORM.Mapped α)
Instances
Operations on mapped types #
Inserts the value and returns an IID reference to it. Fails if a referenced role player does not exist, in which case nothing is inserted.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The instance a reference points to, or none.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Every instance of the type (and its subtypes), with an IID reference to each.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Replaces the value(s) of one attribute.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Deletes the instance.
Equations
- One or more equations did not get rendered due to their size.
Instances For
How many instances of the type (and its subtypes) exist.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Polymorphic decoding #
A sum type whose constructors wrap mapped types, decoded by each instance's concrete type.
Derive it with deriving Polymorphic; the first constructor's type is the root that is
queried.
- root : String
- isRelation : Bool
- variants : Array (String × Array ORM.FieldSpec × (Array ORM.FieldData → Except String α))
Fields and decoder for the constructor of concrete type
label.
Instances
Every instance of the root type, each decoded into the constructor of its concrete type. Instances of an unmapped subtype decode as the closest constructor listed first.
Equations
- One or more equations did not get rendered due to their size.