pub enum Backend {
Sqlite,
Postgres,
MySql,
}Expand description
支持的后端
Variants§
Implementations§
Source§impl Backend
impl Backend
Sourcepub const ID_MAX: usize = 128
pub const ID_MAX: usize = 128
Self::id_text 列能装多少个字符
Sourcepub const ID_SHORT_MAX: usize = 45
pub const ID_SHORT_MAX: usize = 45
Self::id_short 列能装多少个字符
pub fn from_url(url: &str) -> Backend
Sourcepub fn id_text(&self) -> &'static str
pub fn id_text(&self) -> &'static str
主键/索引列的字符串类型。
MySQL 不能对 TEXT 建索引(1170:要 key length),必须用定长 VARCHAR。
128 跟 DTM 的 varchar(128) 对齐;复合主键三列合计仍在 InnoDB 限内。
Sourcepub fn text(&self, n: usize) -> String
pub fn text(&self, n: usize) -> String
自由文本列(payload / url / 原因之类)。
⚠ MySQL 上只能用 VARCHAR:经 sqlx::Any 读 MySQL 的 TEXT
(含 LONGTEXT、MEDIUMTEXT、显式 CHARACTER SET utf8mb4)一律报
mismatched types; Rust type String is not compatible with SQL type BLOB。
五种写法实测下来只有 VARCHAR 能解成 String。
代价是有长度上限:n 要够装最长的内容。MySQL 单行还有 65535 字节的
总限制(utf8mb4 每字符 4 字节),所以别把每列都开得很大。
Sourcepub fn q(&self, template: &str) -> String
pub fn q(&self, template: &str) -> String
把 SQL 模板渲染成这个后端能吃的语句。
做三件事:
?→$1..$n(MySQL 保持?){INS}→INSERT IGNORE INTO(MySQL)/INSERT INTO(其它){NOCONFLICT}→ 空(MySQL)/ON CONFLICT DO NOTHING(其它)
Sourcepub fn create_index(
&self,
name: &str,
table: &str,
cols: &str,
) -> Option<String>
pub fn create_index( &self, name: &str, table: &str, cols: &str, ) -> Option<String>
建索引。MySQL 不支持 CREATE INDEX IF NOT EXISTS,只能靠
建表时内联 KEY,所以这里对 MySQL 返回 None。
Sourcepub fn inline_index(&self, name: &str, cols: &str) -> String
pub fn inline_index(&self, name: &str, cols: &str) -> String
建表时内联的索引定义。只有 MySQL 用得上(见 Self::create_index)。
Trait Implementations§
impl Copy for Backend
impl Eq for Backend
impl StructuralPartialEq for Backend
Auto Trait Implementations§
impl Freeze for Backend
impl RefUnwindSafe for Backend
impl Send for Backend
impl Sync for Backend
impl Unpin for Backend
impl UnsafeUnpin for Backend
impl UnwindSafe for Backend
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more