Expand description
Traits dealing with DuckDB data types.
DuckDB uses a dynamic type system. Implementations of
the ToSql and FromSql traits are provided for the basic types that
DuckDB provides methods for:
- Strings (
Stringand&str) - Blobs (
Vec<u8>and&[u8]) - Numbers
The number situation is a little complicated due to the fact that all
numbers in DuckDB are stored as INTEGER (i64) or REAL (f64).
ToSql and FromSql are implemented for all primitive number types.
FromSql has different behaviour depending on the SQL and Rust types, and
the value.
INTEGERto integer: returns anError::IntegralValueOutOfRangeerror if the value does not fit in the Rust type.REALto integer: always returns anError::InvalidColumnTypeerror.INTEGERto float: casts usingasoperator. Never fails.REALto float: casts usingasoperator. Never fails.
ToSql always succeeds except when storing a u64 or usize value that
cannot fit in an INTEGER (i64). Also note that DuckDB ignores column
types, so if you store an i64 in a column with type REAL it will be
stored as an INTEGER, not a REAL.
If the time feature is enabled, implementations are
provided for time::OffsetDateTime that use the RFC 3339 date/time format,
"%Y-%m-%dT%H:%M:%S.%fZ", to store time values as strings. These values
can be parsed by SQLite’s builtin
datetime functions. If you
want different storage for datetimes, you can use a newtype.
ToSql and FromSql are also implemented for Option<T> where T
implements ToSql or FromSql for the cases where you want to know if
a value was NULL (which gets translated to None).
Structs§
- Empty struct that can be used to fill in a query parameter as
NULL.
Enums§
- Enum listing possible errors from
FromSqltrait. - An absolute length of time in seconds, milliseconds, microseconds or nanoseconds. Copy from arrow::datatypes::TimeUnit
ToSqlOutputrepresents the possible output types for implementers of theToSqltrait.- DuckDB data types. See Fundamental Datatypes.
- Owning dynamic type value. Value’s type is typically dictated by DuckDB (not by the caller).
- A non-owning static type value. Typically the memory backing this value is owned by SQLite.
Traits§
- A trait for types that can be created from a DuckDB value.
- A trait for types that can be converted into DuckDB values. Returns [
Error::ToSqlConversionFailure] if the conversion fails.
Type Aliases§
- Result type for implementors of the
FromSqltrait.