Repository navigation
somnia v0.6.0
Completes the P2 ("completeness") roadmap tier — transactions, parameter
binding, SELECT extras, more schema DDL, control flow, and the edge derive.
Every change is API-additive, but the breadth of new functionality earns a minor
bump (update your dependency to somnia = "0.6").
Added (0.6.0)
- Edge derive (P2) —
#[derive(SurrealEdge)]generates theSurrealEdge
impl (edge name from#[table(...)]), replacing the hand-written
impl SurrealEdge. The derive also rendersFLEXIBLEon#[field(flexible)]
fields (DEFINE FIELD … FLEXIBLE TYPE …). - Control flow (P2) —
IfExpr(IF … THEN … ELSE IF … ELSE … END) as a
DynExprusable in any expression position, and aForbuilder
(FOR $item IN <array> { <body> }). Both validated against the live engine. - More schema DDL (P2) — standalone builders
DefineEvent,DefineFunction
(fn::-prefixed, typed args, return type, body),DefineAnalyzer(tokenizers +
filters), andDefineParam($-prefixed, raw or typed value), each with a
::remove(...)inverse. New derived field attributes#[field(assert = "…")],
#[field(readonly)], and#[field(permissions = "…")]render into the
generatedDEFINE FIELD. Validated against the live engine. SELECTextras (P2) —VALUEmode,OMIT,SPLIT,WITH INDEX/WITH NOINDEXhints,TIMEOUT, andEXPLAIN[FULL] modifiers onSelect;
subqueries (Select<T>now implementsDynExpr, rendering parenthesized — use
it in aWHERE, as a scalar operand, or asFROM (<subquery>)via
from_subquery);in_expr()/not_in_expr()(IN/NOT IN) on columns and
idents; andRETURN <projection>onINSERT(now renders the actual field list
plus areturning()enum setter) andRelateEdge(return_field/returning).
Subquery parameters merge into the parent's$parammap.PARALLELis omitted —
SurrealDB 3.1 rejects it onSELECT.- Transactions (P2) — a
Transactionbuilder wraps pushed statements in
BEGIN TRANSACTION; … ; COMMIT TRANSACTION;(orCANCEL TRANSACTIONvia
.cancel()), giving atomic, roll-back-on-error semantics that the
;-concatenatedBatchdoesn't. Verified atomic against a live engine. - Parameters /
LET(P2) — an opt-in$param-binding mode alongside the
default inline rendering.to_surrealql_with_params()onSelect/Create/
Update/Delete(andthen_select_params()on the mutations) returns
(String, BTreeMap<String, serde_json::Value>), auto-binding each literal as
$p0,$p1, ….Param::new("name", value)declares an explicit named
placeholder for reuse across a query. ALetVarbuilder emits
LET $var = <expr>, andSomniaClient::query_with_params()binds and runs the
pair. The inlineto_surrealql()path is unchanged.
Changed (0.6.0)
- README — documented the P1 features (graph traversal,
#[index(...)]/
DefineIndex, richer field types) and added a "More query power" section
covering the P2 surface (transactions,$parambinding, subqueries,SELECT
modifiers,DEFINE EVENT/FUNCTION,IfExpr/For,#[derive(SurrealEdge)]).
Docs only.