use super::{Ident, ToSql};
use crate::{
serializer::{ExprContext, Flavor},
stmt,
};
impl ToSql for &stmt::ColumnDef {
fn to_sql(self, cx: &ExprContext<'_>, f: &mut super::Formatter<'_>) {
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 => {
fmt!(cx, f, " PRIMARY KEY AUTOINCREMENT")
}
}
}
if let Some(check) = &self.check {
fmt!(cx, f, " ");
check.to_sql(cx, f);
}
}
}
impl ToSql for &stmt::CheckConstraint {
fn to_sql(self, cx: &ExprContext<'_>, f: &mut super::Formatter<'_>) {
if let Some(name) = &self.name {
fmt!(cx, f, "CONSTRAINT " Ident(&name.0) " ");
}
fmt!(cx, f, "CHECK (" self.expr ")");
}
}