Skip to main content

SqlValue

Enum SqlValue 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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[]。

Fields

§element_type: &'static str

元素类型名(受控白名单,见枚举文档)。

§values: Vec<SqlValue>

元素值,按顺序绑定。

§

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§

Source§

impl SqlValue

以微秒构造 INTERVAL 值。

Source

pub fn interval_micros(micros: i64) -> Self

INTERVAL(微秒)。

Trait Implementations§

Source§

impl Clone for SqlValue

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 Debug for SqlValue

Source§

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

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

impl From<&str> for SqlValue

Source§

fn from(v: &str) -> Self

Converts to this type from the input type.
Source§

impl From<BigDecimal> for SqlValue

Source§

fn from(v: BigDecimal) -> Self

Converts to this type from the input type.
Source§

impl From<DateTime<Utc>> for SqlValue

Source§

fn from(v: DateTime<Utc>) -> Self

Converts to this type from the input type.
Source§

impl From<NaiveDate> for SqlValue

Source§

fn from(v: NaiveDate) -> Self

Converts to this type from the input type.
Source§

impl From<NaiveDateTime> for SqlValue

Source§

fn from(v: NaiveDateTime) -> Self

Converts to this type from the input type.
Source§

impl From<NaiveTime> for SqlValue

Source§

fn from(v: NaiveTime) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Option<T>> for SqlValue
where T: Into<SqlValue>,

Source§

fn from(v: Option<T>) -> Self

Converts to this type from the input type.
Source§

impl From<SqlExprParam> for SqlValue

Available on crate feature postgres only.
Source§

fn from(param: SqlExprParam) -> Self

Converts to this type from the input type.
Source§

impl From<String> for SqlValue

Source§

fn from(v: String) -> Self

Converts to this type from the input type.
Source§

impl From<TimeDelta> for SqlValue

Source§

fn from(v: Duration) -> Self

Converts to this type from the input type.
Source§

impl From<Uuid> for SqlValue

Source§

fn from(v: Uuid) -> Self

Converts to this type from the input type.
Source§

impl From<Value> for SqlValue

Source§

fn from(v: JsonValue) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<String>> for SqlValue

TEXT[] / VARCHAR[] 数组。

Source§

fn from(v: Vec<String>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<bool>> for SqlValue

BOOLEAN[] / BOOL[] 数组。

Source§

fn from(v: Vec<bool>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<f64>> for SqlValue

DOUBLE PRECISION[] / FLOAT8[] 数组。

Source§

fn from(v: Vec<f64>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<i64>> for SqlValue

BIGINT[] / INT8[] 数组。

Source§

fn from(v: Vec<i64>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for SqlValue

Source§

fn from(v: Vec<u8>) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for SqlValue

Source§

fn from(v: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for SqlValue

Source§

fn from(v: f32) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for SqlValue

Source§

fn from(v: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for SqlValue

Source§

fn from(v: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for SqlValue

Source§

fn from(v: i64) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for SqlValue

Source§

fn from(v: u64) -> Self

Converts to this type from the input type.

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more