Running queries #
All functions run inside a transaction body and need [Allows m need]: the transaction's mode
m must be at least the query's need.
execruns a query for its effect.querydecodes every row into anArray;query1?andqueryOnetake the first row.queryFold,queryFoldMandfor x in stream q do …decode rows one batch at a time, in memory that does not grow with the answer. Result streams never leave the transaction: they are released when the loop ends, breaks or throws.fetchdecodes the JSON documents of afetchquery withLean.FromJson.
UTC offsets of IANA zones need the zone's rules; they are loaded once per zone.
The raw answer of a query. Prefer the decoding functions.
Equations
- TypeDB.Tx.answer q = do let __do_lift ← TypeDB.Tx.ctx TypeDB.Tx.native (TypeDB.Native.txQuery __do_lift.handle q.text)
Instances For
def
TypeDB.Tx.foldRowsM
{m need : TxMode}
{α β : Type}
[m.Allows need]
(d : RowDecoder α)
(q : Query need)
(init : β)
(f : β → α → Tx m (ForInStep β))
:
Tx m β
Folds f over the decoded rows, one native batch at a time. f returns none to stop.
Equations
- One or more equations did not get rendered due to their size.
Instances For
def
TypeDB.Tx.queryWith
{m need : TxMode}
{α : Type}
[m.Allows need]
(d : RowDecoder α)
(q : Query need)
:
Every row, decoded with d, in answer order.
Equations
- TypeDB.queryWith d q = TypeDB.Tx.foldRowsM d q #[] fun (acc : Array α) (a : α) => pure (ForInStep.yield (acc.push a))
Instances For
The first row, if any.
Equations
- TypeDB.query1? q = TypeDB.Tx.foldRowsM TypeDB.FromRow.decoder q none fun (x : Option α) (a : α) => pure (ForInStep.done (some a))
Instances For
def
TypeDB.Tx.queryOne
{m need : TxMode}
{α : Type}
[m.Allows need]
[FromRow α]
(q : Query need)
:
Tx m α
The first row; fails if the answer is empty.
Equations
- TypeDB.queryOne q = do let __do_lift ← TypeDB.query1? q match __do_lift with | some a => pure a | none => TypeDB.Tx.fail (TypeDB.TypeDBError.decode "" "at least one row" "no rows")
Instances For
def
TypeDB.Tx.queryFold
{m need : TxMode}
{α β : Type}
[m.Allows need]
[FromRow α]
(q : Query need)
(init : β)
(f : β → α → β)
:
Tx m β
Folds over the rows in constant memory.
Equations
- TypeDB.queryFold q init f = TypeDB.Tx.foldRowsM TypeDB.FromRow.decoder q init fun (b : β) (a : α) => pure (ForInStep.yield (f b a))
Instances For
def
TypeDB.Tx.queryFoldM
{m need : TxMode}
{α β : Type}
[m.Allows need]
[FromRow α]
(q : Query need)
(init : β)
(f : β → α → Tx m β)
:
Tx m β
Equations
- TypeDB.queryFoldM q init f = TypeDB.Tx.foldRowsM TypeDB.FromRow.decoder q init fun (b : β) (a : α) => do let __do_lift ← f b a pure (ForInStep.yield __do_lift)
Instances For
def
TypeDB.Tx.queryPerValue
{m need : TxMode}
{α : Type}
[m.Allows need]
(d : RowDecoder α)
(q : Query need)
:
Rows decoded one native call per value (the unbatched path), for comparison with query.
Equations
- One or more equations did not get rendered due to their size.
Instances For
def
TypeDB.Tx.fetch
{m need : TxMode}
{α : Type}
[m.Allows need]
[Lean.FromJson α]
(q : Query need)
:
The documents of a fetch query, decoded with FromJson.
Equations
- One or more equations did not get rendered due to their size.
Instances For
A query whose rows are decoded lazily by a for loop inside the transaction.
- query : Query need
- decoder : RowDecoder α
Instances For
Equations
- TypeDB.stream q = { query := q, decoder := TypeDB.FromRow.decoder }
Instances For
def
TypeDB.Tx.streamWith
{need : TxMode}
{α : Type}
(d : RowDecoder α)
(q : Query need)
:
RowStream need α
Equations
- TypeDB.streamWith d q = { query := q, decoder := d }