#[non_exhaustive]pub enum SqlValue {
Show 23 variants
Null,
Bool(bool),
Int(i64),
Float(f64),
String(String),
Bytes(Vec<u8>),
Json(Value),
DateTime(NaiveDateTime),
Timestamp(i64),
Decimal(BigDecimal),
Uuid(Uuid),
DateTimeTz(DateTime<Utc>),
Date(NaiveDate),
Time(NaiveTime),
Interval(i64),
Array(Vec<SqlValue>),
TypedArray {
element_type: &'static str,
values: Vec<SqlValue>,
},
Inet(String),
Cidr(String),
MacAddr(String),
MacAddr8(String),
Range(String),
Multirange(String),
}Expand description
SQL 值类型(PostgreSQL)
与 MySQL 后端的 SqlValue 结构一致,独立定义以保持 postgres 模块自包含,
避免跨方言耦合。变体集合与 From 转换均与 MySQL 版本保持对齐。
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Null
Bool(bool)
Int(i64)
Float(f64)
String(String)
Bytes(Vec<u8>)
Json(Value)
DateTime(NaiveDateTime)
Timestamp(i64)
Decimal(BigDecimal)
NUMERIC / DECIMAL,按精确十进制绑定,避免经 f64 丢精度。
Uuid(Uuid)
UUID(uuid 扩展类型)。
DateTimeTz(DateTime<Utc>)
TIMESTAMPTZ(带时区)。
Date(NaiveDate)
DATE。
Time(NaiveTime)
TIME。
Interval(i64)
INTERVAL,单位为微秒。
Array(Vec<SqlValue>)
PostgreSQL 数组(type[]),元素按顺序作为单个数组绑定参数传输,
不展开为多个标量参数。可承载的 From 转换见 Vec<i64> / Vec<String> /
Vec<f64> / Vec<bool>。
元素类型按首个非 NULL 元素推断;空数组/全 NULL 数组没有类型线索,
类型敏感场景请用 SqlValue::TypedArray。
TypedArray
带显式元素类型的 PostgreSQL 数组(如 int4[] / bytea[])。
element_type 是受控的内置类型名(int2/int4/int8/float4/float8/
bool/text/varchar/bytea/uuid/date/time/timestamp/
timestamptz/numeric/jsonb/inet/cidr/macaddr/macaddr8),
决定绑定使用的 Rust 数组类型;空数组与全 NULL 数组也能按真实列类型绑定,
不再退化为 text[]。
Inet(String)
PostgreSQL inet 文本值;渲染时追加 ::inet。
Cidr(String)
PostgreSQL cidr 文本值;渲染时追加 ::cidr。
MacAddr(String)
PostgreSQL macaddr 文本值;渲染时追加 ::macaddr。
MacAddr8(String)
PostgreSQL macaddr8 文本值;渲染时追加 ::macaddr8。
Range(String)
范围文本值(如 [1,10));按文本绑定并追加 ::int4range。
目前仅内置默认的 32 位整数范围转换;其它范围类型需要在 SQL 文本中显式
指定转换($1::tsrange 等)。
Multirange(String)
多范围文本值(如 {[1,10),[20,30)});按文本绑定并追加
::int4multirange(PostgreSQL 14+)。
Implementations§
Trait Implementations§
Source§impl From<BigDecimal> for SqlValue
impl From<BigDecimal> for SqlValue
Source§fn from(v: BigDecimal) -> Self
fn from(v: BigDecimal) -> Self
Source§impl From<NaiveDateTime> for SqlValue
impl From<NaiveDateTime> for SqlValue
Source§fn from(v: NaiveDateTime) -> Self
fn from(v: NaiveDateTime) -> Self
Source§impl From<SqlExprParam> for SqlValue
Available on crate feature postgres only.
impl From<SqlExprParam> for SqlValue
postgres only.Source§fn from(param: SqlExprParam) -> Self
fn from(param: SqlExprParam) -> Self
Auto Trait Implementations§
impl Forget for SqlValue
impl Freeze for SqlValue
impl Move for SqlValue
impl RefUnwindSafe for SqlValue
impl Send for SqlValue
impl Sync for SqlValue
impl Unpin for SqlValue
impl UnsafeUnpin for SqlValue
impl UnwindSafe for SqlValue
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> ⓘ
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> ⓘ
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