Struct sea_query::extension::postgres::TypeCreateStatement[][src]

pub struct TypeCreateStatement { /* fields omitted */ }
This is supported on crate feature backend-postgres only.

Implementations

Create enum as custom type

use sea_query::{extension::postgres::Type, *};

enum FontFamily {
    Type,
    Serif,
    Sans,
    Monospace,
}

impl Iden for FontFamily {
    fn unquoted(&self, s: &mut dyn std::fmt::Write) {
        write!(
            s,
            "{}",
            match self {
                Self::Type => "font_family",
                Self::Serif => "serif",
                Self::Sans => "sans",
                Self::Monospace => "monospace",
            }
        )
        .unwrap();
    }
}

assert_eq!(
    Type::create()
        .as_enum(FontFamily::Type)
        .values(vec![
            FontFamily::Serif,
            FontFamily::Sans,
            FontFamily::Monospace
        ])
        .to_string(PostgresQueryBuilder),
    r#"CREATE TYPE "font_family" AS ENUM ('serif', 'sans', 'monospace')"#
);

Build corresponding SQL statement and return SQL string

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.