Skip to main content

ToSql

Trait ToSql 

Source
pub trait ToSql {
    // Required methods
    fn to_sql(&self) -> Result<SqlValue, TypeError>;
    fn sql_type(&self) -> &'static str;

    // Provided method
    fn encrypted_param_type(&self) -> Option<EncryptedParamType> { ... }
}
Expand description

Trait for types that can be converted to SQL values.

This trait is implemented for common Rust types to enable type-safe parameter binding in queries.

Required Methods§

Source

fn to_sql(&self) -> Result<SqlValue, TypeError>

Convert this value to a SQL value.

Source

fn sql_type(&self) -> &'static str

Get the SQL type name for this value.

Provided Methods§

Source

fn encrypted_param_type(&self) -> Option<EncryptedParamType>

The explicit SQL type a parameter must be declared and encrypted as, when the value alone cannot convey it.

Returns None for every type except the typed-parameter wrappers (e.g. numeric, datetime2, time). An Always Encrypted column requires the declared type — including precision, scale, or length — to match the column exactly, which a bare value cannot always express (a Decimal carries no precision; a NaiveDateTime is ambiguous between datetime and datetime2(n)). The driver uses this to declare the parameter for sp_describe_parameter_encryption and to normalize the value before encryption.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl ToSql for DateTime<FixedOffset>

Available on crate feature chrono only.
Source§

fn to_sql(&self) -> Result<SqlValue, TypeError>

Source§

fn sql_type(&self) -> &'static str

Source§

impl ToSql for DateTime<Utc>

Available on crate feature chrono only.
Source§

fn to_sql(&self) -> Result<SqlValue, TypeError>

Source§

fn sql_type(&self) -> &'static str

Source§

impl ToSql for Decimal

Available on crate feature decimal only.
Source§

fn to_sql(&self) -> Result<SqlValue, TypeError>

Source§

fn sql_type(&self) -> &'static str

Source§

impl ToSql for NaiveDate

Available on crate feature chrono only.
Source§

fn to_sql(&self) -> Result<SqlValue, TypeError>

Source§

fn sql_type(&self) -> &'static str

Source§

impl ToSql for NaiveDateTime

Available on crate feature chrono only.
Source§

fn to_sql(&self) -> Result<SqlValue, TypeError>

Source§

fn sql_type(&self) -> &'static str

Source§

impl ToSql for NaiveTime

Available on crate feature chrono only.
Source§

fn to_sql(&self) -> Result<SqlValue, TypeError>

Source§

fn sql_type(&self) -> &'static str

Source§

impl ToSql for String

Source§

fn to_sql(&self) -> Result<SqlValue, TypeError>

Source§

fn sql_type(&self) -> &'static str

Source§

impl ToSql for Uuid

Available on crate feature uuid only.
Source§

fn to_sql(&self) -> Result<SqlValue, TypeError>

Source§

fn sql_type(&self) -> &'static str

Source§

impl ToSql for Value

Available on crate feature json only.
Source§

fn to_sql(&self) -> Result<SqlValue, TypeError>

Source§

fn sql_type(&self) -> &'static str

Source§

impl ToSql for Vec<u8>

Source§

fn to_sql(&self) -> Result<SqlValue, TypeError>

Source§

fn sql_type(&self) -> &'static str

Source§

impl ToSql for [u8]

Source§

fn to_sql(&self) -> Result<SqlValue, TypeError>

Source§

fn sql_type(&self) -> &'static str

Source§

impl ToSql for bool

Source§

fn to_sql(&self) -> Result<SqlValue, TypeError>

Source§

fn sql_type(&self) -> &'static str

Source§

impl ToSql for f32

Source§

fn to_sql(&self) -> Result<SqlValue, TypeError>

Source§

fn sql_type(&self) -> &'static str

Source§

impl ToSql for f64

Source§

fn to_sql(&self) -> Result<SqlValue, TypeError>

Source§

fn sql_type(&self) -> &'static str

Source§

impl ToSql for i16

Source§

fn to_sql(&self) -> Result<SqlValue, TypeError>

Source§

fn sql_type(&self) -> &'static str

Source§

impl ToSql for i32

Source§

fn to_sql(&self) -> Result<SqlValue, TypeError>

Source§

fn sql_type(&self) -> &'static str

Source§

impl ToSql for i64

Source§

fn to_sql(&self) -> Result<SqlValue, TypeError>

Source§

fn sql_type(&self) -> &'static str

Source§

impl ToSql for str

Source§

fn to_sql(&self) -> Result<SqlValue, TypeError>

Source§

fn sql_type(&self) -> &'static str

Source§

impl ToSql for u8

Source§

fn to_sql(&self) -> Result<SqlValue, TypeError>

Source§

fn sql_type(&self) -> &'static str

Source§

impl<T: ToSql + ?Sized> ToSql for &T

Source§

impl<T: ToSql> ToSql for Option<T>

Implementors§

Source§

impl ToSql for Binary

Source§

impl ToSql for Char

Source§

impl ToSql for DateTime2

Available on crate feature chrono only.
Source§

impl ToSql for DateTimeLegacy

Available on crate feature chrono only.
Source§

impl ToSql for DateTimeOffset

Available on crate feature chrono only.
Source§

impl ToSql for Money

Available on crate feature decimal only.
Source§

impl ToSql for NChar

Source§

impl ToSql for Numeric

Available on crate feature decimal only.
Source§

impl ToSql for SmallDateTime

Available on crate feature chrono only.
Source§

impl ToSql for SmallMoney

Available on crate feature decimal only.
Source§

impl ToSql for Time

Available on crate feature chrono only.
Source§

impl ToSql for TypedNull