TypeDB values #
Lean representations of TypeDB 3 value types that keep every value exact: Decimal (TypeDB's
19-digit fixed point), Duration (months, days and nanoseconds, which do not normalise into each
other), DatetimeTZ (an instant plus the zone it was written in) and IID.
Value and Concept are the raw shapes the native layer produces. Their constructor order and
field order are mirrored by ffi/typedb_lean.c; change both together.
An exact decimal integer + fractional · 10⁻¹⁹ with fractional < 10¹⁹, TypeDB's
representation. Negative values have a negative integer and a non-negative fractional, so
-1.5 is ⟨-2, 5 · 10¹⁸⟩.
Instances For
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- TypeDB.instReprDecimal = { reprPrec := TypeDB.instReprDecimal.repr }
Equations
Equations
The value multiplied by 10¹⁹, as an integer.
Equations
- d.toScaled = d.integer.toInt * ↑TypeDB.Decimal.scale + ↑d.fractional.toNat
Instances For
The decimal n · 10⁻¹⁹; the integer part wraps around if it does not fit in Int64.
Equations
- TypeDB.Decimal.ofScaled n = { integer := Int64.ofInt (n.fdiv ↑TypeDB.Decimal.scale), fractional := UInt64.ofNat (n.fmod ↑TypeDB.Decimal.scale).toNat }
Instances For
Equations
Instances For
Equations
- TypeDB.Decimal.instOfNat n = { ofNat := TypeDB.Decimal.ofInt ↑n }
Equations
- TypeDB.Decimal.instAdd = { add := fun (a b : TypeDB.Decimal) => TypeDB.Decimal.ofScaled (a.toScaled + b.toScaled) }
Equations
- TypeDB.Decimal.instSub = { sub := fun (a b : TypeDB.Decimal) => TypeDB.Decimal.ofScaled (a.toScaled - b.toScaled) }
Equations
- TypeDB.Decimal.instNeg = { neg := fun (a : TypeDB.Decimal) => TypeDB.Decimal.ofScaled (-a.toScaled) }
Equations
- TypeDB.Decimal.instMul = { mul := fun (a b : TypeDB.Decimal) => TypeDB.Decimal.ofScaled ((a.toScaled * b.toScaled).tdiv ↑TypeDB.Decimal.scale) }
Equations
- TypeDB.Decimal.instOrd = { compare := fun (a b : TypeDB.Decimal) => compare a.toScaled b.toScaled }
Equations
- TypeDB.Decimal.instLT = { lt := fun (a b : TypeDB.Decimal) => a.toScaled < b.toScaled }
Equations
- TypeDB.Decimal.instLE = { le := fun (a b : TypeDB.Decimal) => a.toScaled ≤ b.toScaled }
Equations
Equations
Plain decimal notation with no trailing zeros, e.g. -1.5, 3.0.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- TypeDB.Decimal.instToString = { toString := TypeDB.Decimal.toString }
Parses [-]digits[.digits][dec] with at most 19 fractional digits.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- TypeDB.instReprDuration = { reprPrec := TypeDB.instReprDuration.repr }
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Equations
Equations
- TypeDB.Duration.nanosPerSecond = 1000000000
Instances For
ISO 8601 notation, as TypeQL writes duration literals: P1Y2M3DT4H5M6.5S.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- TypeDB.Duration.instToString = { toString := TypeDB.Duration.toISO }
Equations
- TypeDB.Duration.ofSeconds s = { nanos := UInt64.ofNat (s * TypeDB.Duration.nanosPerSecond) }
Instances For
Equations
- TypeDB.instDecidableEqZone.decEq (TypeDB.Zone.iana a) (TypeDB.Zone.iana b) = if h : a = b then h ▸ isTrue ⋯ else isFalse ⋯
- TypeDB.instDecidableEqZone.decEq (TypeDB.Zone.iana name) (TypeDB.Zone.fixed offsetSeconds) = isFalse ⋯
- TypeDB.instDecidableEqZone.decEq (TypeDB.Zone.fixed offsetSeconds) (TypeDB.Zone.iana name) = isFalse ⋯
- TypeDB.instDecidableEqZone.decEq (TypeDB.Zone.fixed a) (TypeDB.Zone.fixed b) = if h : a = b then h ▸ isTrue ⋯ else isFalse ⋯
Instances For
Equations
- TypeDB.instReprZone = { reprPrec := TypeDB.instReprZone.repr }
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- TypeDB.instInhabitedZone = { default := TypeDB.instInhabitedZone.default }
A TypeDB datetime-tz: the instant (UTC seconds and nanoseconds since the Unix epoch), the
zone it is expressed in, and the zone's UTC offset at that instant. The offset is what lets the
value be printed back as local time without loading zone rules.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- TypeDB.instReprDatetimeTZ = { reprPrec := TypeDB.instReprDatetimeTZ.repr }
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Instances For
Equations
Equations
- TypeDB.instReprIID = { reprPrec := TypeDB.instReprIID.repr }
Equations
- TypeDB.instReprIID.repr x✝ prec✝ = Std.Format.bracket "{ " (Std.Format.nil ++ Std.Format.text "hex" ++ Std.Format.text " := " ++ (Std.Format.nest 7 (repr x✝.hex)).group) " }"
Instances For
Equations
- TypeDB.instInhabitedIID = { default := TypeDB.instInhabitedIID.default }
Equations
- TypeDB.instOrdIID.ord { hex := a } { hex := b } = (compare a b).then Ordering.eq
Instances For
Equations
- TypeDB.instOrdIID = { compare := TypeDB.instOrdIID.ord }
Equations
- TypeDB.instToStringIID = { toString := TypeDB.IID.hex }
A value as the native layer reports it. Constructor and field order are mirrored by
ffi/typedb_lean.c.
- bool (b : Bool) : Value
- integer (i : Int64) : Value
- double (d : Float) : Value
- decimal (integer : Int64) (fractional : UInt64) : Value
- string (s : String) : Value
- date
(seconds : Int64)
: Value
A date, as the seconds since the Unix epoch of its midnight.
- datetime
(seconds : Int64)
(nanos : UInt32)
: Value
A datetime without zone, as UTC seconds and nanoseconds since the Unix epoch.
- datetimeTz
(seconds : Int64)
(nanos : UInt32)
(zone : String)
(offset : Int32)
(fixed : Bool)
: Value
offsetis only meaningful whenfixed; IANA zones report their name and offset 0. - duration (months days : UInt32) (nanos : UInt64) : Value
Instances For
Equations
- TypeDB.instReprValue = { reprPrec := TypeDB.instReprValue.repr }
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Equations
- TypeDB.instBEqValue.beq (TypeDB.Value.bool a) (TypeDB.Value.bool b) = (a == b)
- TypeDB.instBEqValue.beq (TypeDB.Value.integer a) (TypeDB.Value.integer b) = (a == b)
- TypeDB.instBEqValue.beq (TypeDB.Value.double a) (TypeDB.Value.double b) = (a == b)
- TypeDB.instBEqValue.beq (TypeDB.Value.decimal a a_1) (TypeDB.Value.decimal b b_1) = (a == b && a_1 == b_1)
- TypeDB.instBEqValue.beq (TypeDB.Value.string a) (TypeDB.Value.string b) = (a == b)
- TypeDB.instBEqValue.beq (TypeDB.Value.date a) (TypeDB.Value.date b) = (a == b)
- TypeDB.instBEqValue.beq (TypeDB.Value.datetime a a_1) (TypeDB.Value.datetime b b_1) = (a == b && a_1 == b_1)
- TypeDB.instBEqValue.beq (TypeDB.Value.datetimeTz a a_1 a_2 a_3 a_4) (TypeDB.Value.datetimeTz b b_1 b_2 b_3 b_4) = (a == b && (a_1 == b_1 && (a_2 == b_2 && (a_3 == b_3 && a_4 == b_4))))
- TypeDB.instBEqValue.beq (TypeDB.Value.duration a a_1 a_2) (TypeDB.Value.duration b b_1 b_2) = (a == b && (a_1 == b_1 && a_2 == b_2))
- TypeDB.instBEqValue.beq x✝¹ x✝ = false
Instances For
Equations
The TypeDB name of the value's type, used in decode errors.
Equations
- (TypeDB.Value.bool a).typeName = "boolean"
- (TypeDB.Value.integer a).typeName = "integer"
- (TypeDB.Value.double a).typeName = "double"
- (TypeDB.Value.decimal a a_1).typeName = "decimal"
- (TypeDB.Value.string a).typeName = "string"
- (TypeDB.Value.date a).typeName = "date"
- (TypeDB.Value.datetime a a_1).typeName = "datetime"
- (TypeDB.Value.datetimeTz a a_1 a_2 a_3 a_4).typeName = "datetime-tz"
- (TypeDB.Value.duration a a_1 a_2).typeName = "duration"
Instances For
A concept in an answer row. Constructor and field order are mirrored by ffi/typedb_lean.c.
Fields the decoder did not ask for (see Plan) are left as empty strings.
- entity (iid label : String) : Concept
- relation (iid label : String) : Concept
- attribute (label : String) (value : Value) : Concept
- value (v : Value) : Concept
- entityType (label : String) : Concept
- relationType (label : String) : Concept
- attributeType (label : String) : Concept
- roleType (label : String) : Concept
Instances For
Equations
- TypeDB.instReprConcept = { reprPrec := TypeDB.instReprConcept.repr }
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Equations
- TypeDB.instBEqConcept.beq (TypeDB.Concept.entity a a_1) (TypeDB.Concept.entity b b_1) = (a == b && a_1 == b_1)
- TypeDB.instBEqConcept.beq (TypeDB.Concept.relation a a_1) (TypeDB.Concept.relation b b_1) = (a == b && a_1 == b_1)
- TypeDB.instBEqConcept.beq (TypeDB.Concept.attribute a a_1) (TypeDB.Concept.attribute b b_1) = (a == b && a_1 == b_1)
- TypeDB.instBEqConcept.beq (TypeDB.Concept.value a) (TypeDB.Concept.value b) = (a == b)
- TypeDB.instBEqConcept.beq (TypeDB.Concept.entityType a) (TypeDB.Concept.entityType b) = (a == b)
- TypeDB.instBEqConcept.beq (TypeDB.Concept.relationType a) (TypeDB.Concept.relationType b) = (a == b)
- TypeDB.instBEqConcept.beq (TypeDB.Concept.attributeType a) (TypeDB.Concept.attributeType b) = (a == b)
- TypeDB.instBEqConcept.beq (TypeDB.Concept.roleType a) (TypeDB.Concept.roleType b) = (a == b)
- TypeDB.instBEqConcept.beq x✝¹ x✝ = false
Instances For
Equations
The type label of an instance, or the label of a type.
Equations
- (TypeDB.Concept.entity iid l).label? = some l
- (TypeDB.Concept.relation iid l).label? = some l
- (TypeDB.Concept.attribute l value).label? = some l
- (TypeDB.Concept.entityType l).label? = some l
- (TypeDB.Concept.relationType l).label? = some l
- (TypeDB.Concept.attributeType l).label? = some l
- (TypeDB.Concept.roleType l).label? = some l
- (TypeDB.Concept.value v).label? = none
Instances For
A short description used in decode errors.
Equations
- (TypeDB.Concept.entity a a_1).describe = "entity"
- (TypeDB.Concept.relation a a_1).describe = "relation"
- (TypeDB.Concept.attribute a a_1).describe = toString a_1.typeName ++ toString " attribute"
- (TypeDB.Concept.value a).describe = toString a.typeName ++ toString " value"
- (TypeDB.Concept.entityType a).describe = "entity type"
- (TypeDB.Concept.relationType a).describe = "relation type"
- (TypeDB.Concept.attributeType a).describe = "attribute type"
- (TypeDB.Concept.roleType a).describe = "role type"
Instances For
Conversions to and from Std.Time #
Equations
- TypeDB.Time.timestampOf seconds nanos = Std.Time.Timestamp.ofNanosecondsSinceUnixEpoch (Std.Time.Nanosecond.Offset.ofInt (seconds.toInt * 1000000000 + ↑nanos.toNat))
Instances For
UTC seconds and sub-second nanoseconds of a timestamp.
Equations
- TypeDB.Time.splitTimestamp t = (Int64.ofInt (t.toNanosecondsSinceUnixEpoch.val.fdiv 1000000000), UInt32.ofNat (t.toNanosecondsSinceUnixEpoch.val.fmod 1000000000).toNat)
Instances For
Equations
Instances For
Equations
Instances For
Equations
- TypeDB.Time.plainDateTimeOf seconds nanos = (Std.Time.DateTime.ofTimestamp (TypeDB.Time.timestampOf seconds nanos) Std.Time.TimeZone.ZoneRules.UTC).toPlainDateTime
Instances For
Equations
Instances For
Equations
Instances For
The local wall time in the value's zone.
Equations
Instances For
The value as a Std.Time.DateTime whose zone is fixed at the value's offset. The instant and
local time are exact; date arithmetic across a DST change needs toDateTimeWithRules.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The value as a Std.Time.DateTime with the full rules of its IANA zone.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The instant of a Std.Time.DateTime, at its current offset. Pass iana to keep the zone's
name, e.g. Europe/London; otherwise the value carries a fixed offset.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A local time in an IANA zone, resolved with the zone's rules.
Equations
- TypeDB.DatetimeTZ.ofLocal pdt iana = do let rules ← Std.Time.Database.defaultGetZoneRules iana pure (TypeDB.DatetimeTZ.ofDateTime (Std.Time.DateTime.ofPlainDateTime pdt rules) (some iana))
Instances For
A local time at a fixed UTC offset in seconds.
Equations
- One or more equations did not get rendered due to their size.