pub enum Backend {
Mysql,
Postgres,
Sqlite,
}Expand description
支持的数据库后端
Variants§
Implementations§
Source§impl Backend
impl Backend
Sourcepub fn quote_ident(&self, ident: &str) -> String
pub fn quote_ident(&self, ident: &str) -> String
双重引号标识符
仅用于别名 / 已物理名(t、r0、__present、__rn、fk、v… 等合成名)。
逻辑数据标识符(字段 / 关系字段 / 计算列 key / 表名)一律走 Backend::pcol。
Sourcepub fn double_type(&self) -> &'static str
pub fn double_type(&self) -> &'static str
双精度浮点类型名(§9.7「数值归 double」)
SUM/AVG 的结果在不同后端原生精度不同:MySQL AVG(<int 列>) 只保留 4 位小数
(DECIMAL(scale+4)),PG AVG(<int 列>) 返回精确 numeric,均与 Mongo $avg
的 IEEE-754 double 存在差异。故 SQL 侧 AVG 前先把入参 CAST 到双精度。
Sourcepub fn qualified_table(
&self,
database: Option<&str>,
schema: Option<&str>,
table: &str,
) -> String
pub fn qualified_table( &self, database: Option<&str>, schema: Option<&str>, table: &str, ) -> String
表名 → SQL:database / schema 可选限定(空串按 None 处理)。
PG 用 schema 限定("schema"."table";database 由连接承载,禁跨库限定);
MySQL/SQLite 用 database 限定("db"."table")。表名走 [physical_of](物理名)。
见设计 §3.2 / §6.4。
Sourcepub fn placeholder(&self, _index: usize) -> String
pub fn placeholder(&self, _index: usize) -> String
占位符:SQLite/MySQL 用 ?,PostgreSQL 用 $n(调用方保证按顺序传入 index)
Sourcepub fn supports_returning(&self) -> bool
pub fn supports_returning(&self) -> bool
MySQL 无 RETURNING —— 需由 Host 编排 UPDATE + find 两段;PG/SQLite 原生支持
Sourcepub fn json_type_name(&self) -> &'static str
pub fn json_type_name(&self) -> &'static str
JSON 列的方言类型名(object/array 字段落单列存储的契约,见 §4.5 / 不足清单 #3)
⚠️ 跨方言对齐:object/array 字段在 SQL 后端以单列存 JSON 文本 ——
MySQL JSON / PG jsonb / SQLite TEXT(JSON1 扩展)。core 不写 DDL(铁律 6),
此常量供示例 DDL、introspection 与文档约定引用。
Sourcepub fn json_extract_scalar(&self, col: &str, path: &[&str]) -> String
pub fn json_extract_scalar(&self, col: &str, path: &[&str]) -> String
JSON 点号路径 → 标量提取表达式(U3 对象点号路径过滤 / U4 排序用)
- MySQL:
JSON_UNQUOTE(JSON_EXTRACT(col, '$.a.b')) - PG:
(col #>> '{a,b}') - SQLite:
json_extract(col, '$.a.b')
三者统一为「提取后标量(数值/字符串)」,供比较与 ORDER BY 使用;
col 须为已按后端引号化的列标识符,path 为点号各段(不含列名)。
Sourcepub fn json_array_contains(&self, col: &str, ph: &str) -> String
pub fn json_array_contains(&self, col: &str, ph: &str) -> String
JSON 数组「包含元素」谓词(U1:{tags: "x"} ⇒ 数组含 "x")
- MySQL:
JSON_CONTAINS(col, CAST(? AS JSON))(候选是值的 JSON 字面量,如"x"/1) - PG:
col @> ?::jsonb(候选是单元素数组的 JSON 文本,如["x"]) - SQLite:
EXISTS (SELECT 1 FROM json_each(col) WHERE json_each.value = ?)(候选是标量原值)
ph 为已生成的占位符(? / $n),参数由调用方按上述契约绑定(见 filter::json_cond)。
Sourcepub fn json_value_eq(&self, col: &str, ph: &str, negate: bool) -> String
pub fn json_value_eq(&self, col: &str, ph: &str, negate: bool) -> String
JSON 整值等值比较(U1 数组整体等值 / U2 对象结构等值)
- MySQL:
col [<>] CAST(? AS JSON);PG:col [<>] ?::jsonb;SQLite:json(col) [<>] json(?)
⚠️ 跨后端语义差异(已知不对齐点,调用方须告警、禁静默,见「自动反馈原则」):
MySQL JSON / PG jsonb 的对象比较是键序无关的(存储即规范化),
而 MongoDB 的对象等值匹配字段顺序敏感、SQLite(json() 文本 minify)保留键序。
故 object 字段(U2)在 MySQL/PG 上可能比 Mongo/SQLite 命中更多行 ——
不建议用于业务查询,建议改用对象点号路径(U3);仅适合数据迁移 / 功能脚本。