Skip to main content

drizzle_postgres/traits/
column.rs

1use drizzle_core::SQLColumn;
2
3use crate::values::PostgresValue;
4/// A column of a `PostgreSQL` table, with its auto-increment settings.
5///
6/// Implemented by `#[PostgresTable]` for every column type it generates.
7pub trait PostgresColumn<'a>: SQLColumn<'a, PostgresValue<'a>> {
8    /// `true` for a `serial` column.
9    const SERIAL: bool = false;
10    /// `true` for a `bigserial` column.
11    const BIGSERIAL: bool = false;
12    /// `true` for a `GENERATED ... AS IDENTITY` column.
13    const GENERATED_IDENTITY: bool = false;
14    /// `true` = GENERATED ALWAYS AS IDENTITY, `false` = GENERATED BY DEFAULT AS IDENTITY.
15    /// Only meaningful when `GENERATED_IDENTITY` is `true`.
16    const IDENTITY_ALWAYS: bool = true;
17}
18
19impl<'a, T> PostgresColumn<'a> for &T
20where
21    T: PostgresColumn<'a>,
22    for<'r> &'r T: SQLColumn<'a, PostgresValue<'a>>,
23{
24    const SERIAL: bool = T::SERIAL;
25    const BIGSERIAL: bool = T::BIGSERIAL;
26    const GENERATED_IDENTITY: bool = T::GENERATED_IDENTITY;
27    const IDENTITY_ALWAYS: bool = T::IDENTITY_ALWAYS;
28}