//! SQLite helpers for `# db` CRUD and W2 data-layer capabilities.
//!
//! - **连接池**:进程级 `Pool` 复用连接(WAL + busy_timeout + foreign_keys),
//! 避免每请求重连与并发写 `database is locked`。
//! - **事务**:`begin` 把连接从池中借出并独占,`commit` / `rollback` 后归还。
//! - **查询表达力**:where 支持 OR 组、`in` / `between` / `is null`。
//! - **分页**:`select` 支持 `offset`,返回 `{rows, total}`。
use rusqlite::{types::ValueRef, Connection, OptionalExtension, params_from_iter};
use serde_json::{json, Map, Value};
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::{Arc, Mutex};
/// Process-wide pool: url → shared connection. Connections are reused across
/// calls instead of reopening per request.
static POOL: Mutex