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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
//! # MoteDB
//!
//! AI-native embedded multimodal database for embodied intelligence (robots,
//! AR glasses, industrial arms). A single embedded Rust library providing
//! columnar storage with ACID transactions, vector search, full-text search,
//! and spatial indexing.
//!
//! ## Status
//!
//! Pre-1.0. The [`Database`] embedding API and the storage/transaction engine
//! are stable and heavily tested. The SQL surface and the FFI bindings
//! ([`ffi`], [`tokenizers`]) are still evolving โ see the crate README for the
//! supported SQL subset. The internal modules ([`storage`], [`index`], [`txn`],
//! [`database`]) are exposed for advanced/embedded use but their exact types
//! are **not** part of the stable API yet.
//!
//! ## Quick start
//!
//! ```no_run
//! use motedb::{Database, QueryResult};
//!
//! let db = Database::create("my_data")?;
//! db.execute("CREATE TABLE t (id INT PRIMARY KEY, v INT)")?;
//! db.execute("INSERT INTO t VALUES (1, 100)")?;
//! let r = db.execute("SELECT * FROM t")?;
//! if let QueryResult::Select { rows, .. } = r.materialize()? {
//! println!("{:?}", rows);
//! }
//! # Ok::<(), motedb::StorageError>(())
//! ```
//!
//! ## Architecture
//!
//! - **Storage:** append-only columnar segments (source of truth) + WAL for
//! durability, with Snappy/Zstd compression and mmap zero-copy reads.
//! - **Indexes:** DiskANN/Vamana (vector) + i-Octree (spatial) + inverted
//! index (text) + B+Tree (column/timestamp).
//! - **Transactions:** MVCC version store with snapshot isolation and
//! write-ahead logging for crash recovery.
//!
//! ## Performance (indicative, Apple Silicon)
//!
//! On a 300K-row ร 4-column workload vs SQLite WAL: COUNT/SUM under WHERE
//! ~5ร, ORDER BY + LIMIT ~2.5ร, PK point lookup sub-microsecond. See
//! `BENCHMARK.md` and the docs for methodology and full numbers.
// Crate-wide clippy allowances for lint classes that are design choices in a
// columnar DB rather than bugs. Per-site cleanups are still welcome, but these
// fire often enough on the hot paths that we silence them globally rather than
// annotate every signature.
// ๐ง jemalloc: background thread returns freed memory to OS (RSS plateaus instead of growing forever)
use Jemalloc;
static GLOBAL: Jemalloc = Jemalloc;
/// Explicitly purge jemalloc's dirty pages back to the OS.
/// Fsync the parent directory of a file path. This ensures that a file rename
/// or creation is durable across crashes on POSIX systems (Linux ext4/xfs,
/// macOS APFS). Without this, a rename is not guaranteed to survive a crash
/// even if the file itself was fsync'd.
/// Call after bulk operations (CREATE INDEX, compaction) that create
/// large transient allocations, to keep RSS low on edge devices.
/// No-op when jemalloc is not enabled.
// โโ Logging โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
// The crate emits log records via the `log` crate facade (our
// `debug_log!`/`info_log!`/`warn_log!`/`error_log!` macros delegate to
// `log::debug!`/`info!`/`warn!`/`error!`). The library installs NO global
// logger โ that is the application's responsibility (e.g. `env_logger::init()`
// or a `tracing` subscriber). With no logger installed, all logging is
// compiled to a no-op (zero runtime cost). With one installed, the app
// controls verbosity, e.g. `RUST_LOG=motedb=info`.
//
// This replaces the prior hand-rolled macros that unconditionally `eprintln!`'d
// to stderr (`warn_log!`) or produced nothing in release builds (`debug_log!`),
// which gave production deployments zero useful observability.
/// Debug-level log. Compiled in but a no-op unless a logger is installed and
/// debug level is enabled for the `motedb` target.
/// Info-level log (e.g. lifecycle events: open/close/checkpoint).
/// Warn-level log (degraded-but-functional conditions, retries, fallbacks).
/// Error-level log (operation failed; the calling path returns an error too).
// โ ๏ธ EXPERIMENTAL: the C ABI in `ffi` is incomplete (no open_with_config,
// no transaction/batch APIs, no error reporting, execute() returns a Debug
// string). There is no C header file and no versioned symbol scheme yet.
// Do not rely on it for production bindings until it stabilizes โ it will
// change without a SemVer bump. Tracked as a pre-1.0 limitation.
// ๐ P1: Row cache for performance
// ๐ Modular database module (refactored from database_legacy.rs)
// ๅ
้จ API ๅ
่ฃ
ๅฑ
pub use ;
pub use ;
// ไธป่ฆๅฏนๅค API (now using modular database)
pub use Database; // ็ฎๅ API ๅ
่ฃ
pub use TableRegistry;
pub use ;
pub use ;
// ๐ ๅฏผๅบๅ่ฏๅจๆไปถ็ณป็ป๏ผๆนไพฟ็จๆท็ดๆฅไฝฟ็จ๏ผ