Skip to main content

Backend

Enum Backend 

Source
pub enum Backend {
    Mysql,
    Postgres,
    Sqlite,
}
Expand description

支持的数据库后端

Variants§

§

Mysql

§

Postgres

§

Sqlite

Implementations§

Source§

impl Backend

Source

pub fn parse(s: &str) -> Result<Backend, String>

从字符串解析后端(未知 → Err)

Source

pub fn quote_ident(&self, ident: &str) -> String

双重引号标识符

仅用于别名 / 已物理名(t、r0、__present、__rn、fk、v… 等合成名)。 逻辑数据标识符(字段 / 关系字段 / 计算列 key / 表名)一律走 Backend::pcol。

Source

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 到双精度。

Source

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。

Source

pub fn placeholder(&self, _index: usize) -> String

占位符:SQLite/MySQL 用 ?,PostgreSQL 用 $n(调用方保证按顺序传入 index)

Source

pub fn as_str(&self) -> &'static str

后端标识(同 Debug,供绑定层序列化)

Source

pub fn supports_returning(&self) -> bool

MySQL 无 RETURNING —— 需由 Host 编排 UPDATE + find 两段;PG/SQLite 原生支持

Source

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 与文档约定引用。

Source

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 为点号各段(不含列名)。

Source

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)。

Source

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);仅适合数据迁移 / 功能脚本。

Trait Implementations§

Source§

impl Clone for Backend

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Backend

Source§

impl Debug for Backend

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Backend

Source§

impl PartialEq for Backend

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Backend

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.