use super::SqlDialect;
use crate::types::{DatabaseType, sql_hints::ScalarFieldType};
impl DatabaseType {
#[must_use]
pub fn json_field_expr(self, key: &str) -> String {
match self {
Self::PostgreSQL => format!("data->>'{key}'"),
}
}
#[must_use]
pub fn dialect(self) -> &'static dyn SqlDialect {
match self {
Self::PostgreSQL => &super::PostgresDialect,
}
}
#[must_use]
pub fn typed_json_field_expr(self, key: &str, field_type: ScalarFieldType) -> String {
let base = self.json_field_expr(key);
self.dialect().cast_expr_as(&base, field_type).into_owned()
}
}
#[cfg(test)]
mod tests;