Skip to main content

DrizzlePostgresColumn

Trait DrizzlePostgresColumn 

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

Source

const SQL_TYPE: &'static str

Column type used in DDL: "text", "integer", or the native enum type name.

Provided Associated Constants§

Source

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.

Source

const NEEDS_CREATE_TYPE: bool = false

Whether this requires a CREATE TYPE (native PG enum).

Source

const SCHEMA: &'static str = "public"

Schema the custom type lives in (native PG enums with #[postgres_enum(schema = "...")]). Defaults to public.

Required Associated Types§

Source

type SQLType: DataType

Drizzle SQL type marker for this column.

Use one of the built-in PostgreSQL markers, such as Text, Int4, Bytea, Boolean, Numeric, Enum, or Any.

Required Methods§

Source

fn encode(&self) -> PostgresValue<'_>

Converts the value to a borrowed PostgresValue for binding.

Provided Methods§

Source

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".

Implementors§