pub trait DrizzlePostgresColumn: Sized {
type SQLType: DataType;
const SQL_TYPE: &'static str;
const DDL_TYPE: &'static str = Self::SQL_TYPE;
const NEEDS_CREATE_TYPE: bool = false;
const SCHEMA: &'static str = "public";
// Required method
fn encode(&self) -> PostgresValue<'_>;
// Provided method
fn encode_owned(self) -> OwnedPostgresValue { ... }
}Expand description
A custom Rust type that can be used as a PostgreSQL column type
(variant without a driver feature).
Without postgres-sync or tokio-postgres there is no row type, so this
version has no decode method. Enum derives still compile, but the table
macro does not generate row-decoding TryFrom impls.
The blanket From<Self> for PostgresValue owns the encoded value because
insert/update models may store SQL fragments after the source value is
dropped. Call encode() directly when you need an immediate borrowed value.
Override encode_owned() when consuming self can avoid cloning owned data.
Required Associated Constants§
Provided Associated Constants§
Sourceconst DDL_TYPE: &'static str = Self::SQL_TYPE
const DDL_TYPE: &'static str = Self::SQL_TYPE
SQL_TYPE as CREATE TABLE writes it. Native
enums quote and schema-qualify their type ("app"."Mood"); other
types use SQL_TYPE unchanged.
Sourceconst NEEDS_CREATE_TYPE: bool = false
const NEEDS_CREATE_TYPE: bool = false
Whether this requires a CREATE TYPE (native PG enum).
Required Associated Types§
Required Methods§
Sourcefn encode(&self) -> PostgresValue<'_>
fn encode(&self) -> PostgresValue<'_>
Converts the value to a borrowed PostgresValue for binding.
Provided Methods§
Sourcefn encode_owned(self) -> OwnedPostgresValue
fn encode_owned(self) -> OwnedPostgresValue
Convert self to an owned PostgreSQL value for stored bind parameters.
The default implementation owns the borrowed result of encode.
Override this for wrappers that can move an internal string or byte buffer
directly into the SQL parameter.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".