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
//! Connection management.
//!
//! `Db` wraps an embedded libSQL `Database`. Cheap to clone (it's a thin
//! handle); call `.conn()` to check out a connection for a single query.
//!
//! Migrations are NOT run by this module. Apply them via the framework CLI:
//!
//! ```bash
//! cargo reef migrate run
//! ```
//!
//! The runner lives in `cargo-reef`, not in your project. This means:
//! - Your project never has to maintain migration runner code
//! - Migration bug-fixes ship via cargo-reef updates, not your codebase
//! - Migrations are an explicit operational step (like `rails db:migrate`)
//!
//! For dev convenience until `cargo reef migrate run` ships, you can apply
//! the SQL files directly:
//!
//! ```bash
//! for f in migrations/*.sql; do sqlite3 ./data/reef.db < "$f"; done
//! ```
use Arc;
use Result;
use ;
use OnceCell;
// ---- Default global Db ----
//
// Lazy async-init singleton. This is the canonical "Option 2" pattern from
// Dioxus's [examples/07-fullstack/server_state.rs] — equivalent in shape to
// `dioxus::fullstack::Lazy<T>` but using std/tokio primitives directly so we
// don't pull in a Dioxus-specific wrapper for one global.
//
// Tests should construct their own `Db::new(":memory:")` instead of relying
// on this — that's the whole point of having `Db` be an explicit struct.
//
// If you want explicit per-fn dependency declarations (the "Option 4" pattern),
// declare an `AppState` struct, register it via `axum::Extension` in the
// dioxus::serve closure, and pull it into server fns with the macro's `state:`
// parameter:
//
// #[post("/api/foo", db: State<Db>)]
// pub async fn foo() -> Result<()> { db.conn()?... }
static DEFAULT_DB: = const_new;
/// Lazily-initialized default `Db` (uses `DATABASE_URL` or `./data/reef.db`).
pub async