Skip to content

somnia v0.6.0

Choose a tag to compare

@github-actions github-actions released this 21 Jun 12:10
· 13 commits to main since this release

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 the SurrealEdge
    impl (edge name from #[table(...)]), replacing the hand-written
    impl SurrealEdge. The derive also renders FLEXIBLE on #[field(flexible)]
    fields (DEFINE FIELD … FLEXIBLE TYPE …).
  • Control flow (P2) — IfExpr (IF … THEN … ELSE IF … ELSE … END) as a
    DynExpr usable in any expression position, and a For builder
    (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), and DefineParam ($-prefixed, raw or typed value), each with a
    ::remove(...) inverse. New derived field attributes #[field(assert = "…")],
    #[field(readonly)], and #[field(permissions = "…")] render into the
    generated DEFINE FIELD. Validated against the live engine.
  • SELECT extras (P2) — VALUE mode, OMIT, SPLIT, WITH INDEX/WITH NOINDEX hints, TIMEOUT, and EXPLAIN[ FULL] modifiers on Select;
    subqueries (Select<T> now implements DynExpr, rendering parenthesized — use
    it in a WHERE, as a scalar operand, or as FROM (<subquery>) via
    from_subquery); in_expr() / not_in_expr() (IN / NOT IN) on columns and
    idents; and RETURN <projection> on INSERT (now renders the actual field list
    plus a returning() enum setter) and RelateEdge (return_field / returning).
    Subquery parameters merge into the parent's $param map. PARALLEL is omitted —
    SurrealDB 3.1 rejects it on SELECT.
  • Transactions (P2) — a Transaction builder wraps pushed statements in
    BEGIN TRANSACTION; … ; COMMIT TRANSACTION; (or CANCEL TRANSACTION via
    .cancel()), giving atomic, roll-back-on-error semantics that the
    ;-concatenated Batch doesn'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() on Select/Create/
    Update/Delete (and then_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. A LetVar builder emits
    LET $var = <expr>, and SomniaClient::query_with_params() binds and runs the
    pair. The inline to_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, $param binding, subqueries, SELECT
    modifiers, DEFINE EVENT/FUNCTION, IfExpr/For, #[derive(SurrealEdge)]).
    Docs only.