#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Dialect {
Sqlite,
Postgres,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Construct {
JsonEach,
JsonTree,
WithoutRowId,
Strict,
JsonArrowText,
JsonArrow,
JsonContains,
JsonContained,
JsonExists,
Jsonb,
Returning,
Ilike,
GenRandomUuid,
NowFn,
}
impl Construct {
pub fn lexeme(self) -> &'static str {
match self {
Construct::JsonEach => "json_each",
Construct::JsonTree => "json_tree",
Construct::WithoutRowId => "without rowid",
Construct::Strict => "strict",
Construct::JsonArrowText => "->>",
Construct::JsonArrow => "->",
Construct::JsonContains => "@>",
Construct::JsonContained => "<@",
Construct::JsonExists => "?",
Construct::Jsonb => "jsonb",
Construct::Returning => "returning",
Construct::Ilike => "ilike",
Construct::GenRandomUuid => "gen_random_uuid",
Construct::NowFn => "now",
}
}
pub fn dialect(self) -> Dialect {
match self {
Construct::JsonEach
| Construct::JsonTree
| Construct::WithoutRowId
| Construct::Strict => Dialect::Sqlite,
_ => Dialect::Postgres,
}
}
pub fn supported_by(self, dialect: Dialect) -> bool {
self.dialect() == dialect
}
}
pub fn first_unsupported(constructs: &[Construct], dialect: Dialect) -> Option<Construct> {
constructs
.iter()
.copied()
.find(|c| !c.supported_by(dialect))
}