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 => {
fmt!(cx, f, " PRIMARY KEY AUTOINCREMENT")
}
}
}
}
}