1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
//! Engine-side glue for the [`sqlrite-ask`](https://crates.io/crates/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:
//!
//! ```text
//! cyclic package dependency: package `sqlrite-ask` depends on itself.
//! Cycle: sqlrite-ask → sqlrite-engine → sqlrite-ask
//! ```
//!
//! Optional / 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`] — walks `Database.tables`
//! alphabetically, emits `CREATE TABLE … (…);` text the LLM grounds
//! on. Determinism matters for prompt caching.
//! - [`ConnectionAskExt`] — extension trait adding `Connection::ask`
//! that handles schema introspection + `sqlrite_ask::ask_with_schema`
//! in 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 `&Database` directly (the REPL binary does this).
// Schema dump is always available (no sqlrite-ask dep). The
// `ConnectionAskExt` trait + free helper functions below are gated
// under the engine's `ask` feature because they pull in `sqlrite-ask`
// (HTTP transport).
use ;
use crateConnection;
use crateDatabase;
// Re-export the public surface from sqlrite-ask. Lets callers reach
// these without listing `sqlrite-ask` as a direct dep — convenient
// for the Tauri desktop app, the SDK adapters, and any Rust embedder
// who already pulls the engine in. They can keep saying
// `use sqlrite::ask::AskConfig` instead of dragging the second crate
// in just for one type. Gated under `ask` because that's the feature
// that pulls `sqlrite-ask` into the dep graph in the first place.
pub use ;
/// Extension trait adding `Connection::ask` to
/// [`crate::Connection`]. Bring it into scope with
/// `use sqlrite::ConnectionAskExt;` (the engine re-exports it at
/// the crate root).
///
/// Gated under the `ask` feature — pulls in `sqlrite-ask` and its
/// HTTP transport. WASM and other lean builds skip this entirely.
/// Free-function form of [`ConnectionAskExt::ask`]. Equivalent —
/// pick whichever shape reads better at the call site.
/// Same as [`ask`], but takes the engine's `&Database` directly.
///
/// Used by the REPL binary's `.ask` meta-command, which holds a
/// `&mut Database` rather than a `&Connection`.
/// Lower-level entry — same flow as [`ask`] but you supply the
/// provider. For test harnesses + advanced callers driving custom
/// backends.
/// Lower-level entry taking `&Database` and a provider. Canonical
/// inner function — the others reduce to this one.