Expand description
Engine-side glue for the sqlrite-ask
crate — natural-language → SQL.
Compiled only when the ask feature is enabled (default-on for
the CLI binary, off for the WASM SDK and any
default-features = false library embedding).
§Why this lives in the engine, not in sqlrite-ask
Earlier (v0.1.18) sqlrite-ask itself owned the Connection
integration — it imported sqlrite-engine and exposed
ConnectionAskExt. That worked for library callers, but when
the engine’s REPL binary tried to depend on sqlrite-ask to
wire up the .ask meta-command we hit a hard cargo error:
cyclic package dependency: package `sqlrite-ask` depends on itself.
Cycle: sqlrite-ask → sqlrite-engine → sqlrite-askOptional / feature-gated deps don’t escape this — cargo’s static
cycle detection counts every potential edge in the graph. The
structural fix was to flip the dep direction: keep sqlrite-ask
pure (operates on &str schemas), put the engine integration
here. The dep flow is now one-way: sqlrite-engine[ask] →
sqlrite-ask. No cycle.
§What’s here
schema::dump_schema_for_database— walksDatabase.tablesalphabetically, emitsCREATE TABLE … (…);text the LLM grounds on. Determinism matters for prompt caching.ConnectionAskExt— extension trait addingConnection::askthat handles schema introspection +sqlrite_ask::ask_with_schemain one call.- Free functions
ask/ask_with_database/ask_with_provider/ask_with_database_and_provider— for callers who don’t want to bring the trait into scope, or who hold a&Databasedirectly (the REPL binary does this).
Modules§
- schema
- Schema introspection — turn an open
Connection(or rawDatabase) into the textual schema dump the LLM uses to ground its SQL generation.
Traits§
- Connection
AskExt - Extension trait adding
Connection::asktocrate::Connection. Bring it into scope withuse sqlrite::ConnectionAskExt;(the engine re-exports it at the crate root).
Functions§
- ask
- Free-function form of
ConnectionAskExt::ask. Equivalent — pick whichever shape reads better at the call site. - ask_
with_ database - Same as
ask, but takes the engine’s&Databasedirectly. - ask_
with_ database_ and_ provider - Lower-level entry taking
&Databaseand a provider. Canonical inner function — the others reduce to this one. - ask_
with_ provider - Lower-level entry — same flow as
askbut you supply the provider. For test harnesses + advanced callers driving custom backends.