toasty-sql 0.2.0

SQL serialization layer for Toasty database drivers
Documentation
use super::{Ident, Params, ToSql};

use crate::{
    serializer::{ExprContext, Flavor},
    stmt,
};

impl ToSql for &stmt::ColumnDef {
    fn to_sql<P: Params>(self, cx: &ExprContext<'_>, f: &mut super::Formatter<'_, P>) {
        let name = Ident(&self.name);

        fmt!(cx, f, name " " self.ty);

        if self.not_null {
            fmt!(cx, f, " NOT NULL");
        }

        if self.auto_increment {
            match f.serializer.flavor {
                Flavor::Postgresql => fmt!(cx, f, " GENERATED BY DEFAULT AS IDENTITY"),
                Flavor::Mysql => fmt!(cx, f, " AUTO_INCREMENT"),
                Flavor::Sqlite => {
                    // Sqlite requires that only the primary key is auto
                    // increment. This is validated in ColumnsWithConstraints.
                    fmt!(cx, f, " PRIMARY KEY AUTOINCREMENT")
                }
            }
        }
    }
}