use std::sync::Arc;
use super::DatabaseAdapter;
use crate::{
types::{
DatabaseType, JsonbValue,
sql_hints::{OrderByClause, SqlProjectionHint},
},
where_clause::WhereClause,
};
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct RelayPageResult {
pub rows: Vec<JsonbValue>,
pub total_count: Option<u64>,
}
impl RelayPageResult {
#[must_use]
pub const fn new(rows: Vec<JsonbValue>, total_count: Option<u64>) -> Self {
Self { rows, total_count }
}
#[must_use]
pub fn rows(&self) -> &[JsonbValue] {
&self.rows
}
#[must_use]
pub fn into_rows(self) -> Vec<JsonbValue> {
self.rows
}
#[must_use]
pub const fn total_count(&self) -> Option<u64> {
self.total_count
}
}
#[derive(Debug, Clone, Copy)]
pub struct DatabaseCapabilities {
pub database_type: DatabaseType,
pub supports_locale_collation: bool,
pub requires_custom_collation: bool,
pub recommended_collation: Option<&'static str>,
}
impl DatabaseCapabilities {
#[must_use]
pub const fn from_database_type(db_type: DatabaseType) -> Self {
match db_type {
DatabaseType::PostgreSQL => Self {
database_type: db_type,
supports_locale_collation: true,
requires_custom_collation: false,
recommended_collation: Some("icu"),
},
DatabaseType::MySQL => Self {
database_type: db_type,
supports_locale_collation: false,
requires_custom_collation: false,
recommended_collation: Some("utf8mb4_unicode_ci"),
},
DatabaseType::SQLite => Self {
database_type: db_type,
supports_locale_collation: false,
requires_custom_collation: true,
recommended_collation: Some("NOCASE"),
},
DatabaseType::SQLServer => Self {
database_type: db_type,
supports_locale_collation: true,
requires_custom_collation: false,
recommended_collation: Some("Latin1_General_100_CI_AI_SC_UTF8"),
},
}
}
#[must_use]
pub const fn collation_strategy(&self) -> &'static str {
match self.database_type {
DatabaseType::PostgreSQL => "ICU collations (locale-specific)",
DatabaseType::MySQL => "UTF8MB4 collations (general)",
DatabaseType::SQLite => "NOCASE (limited)",
DatabaseType::SQLServer => "Language-specific collations",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum MutationStrategy {
FunctionCall,
DirectSql,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum DirectMutationOp {
Insert,
Update,
Delete,
}
#[derive(Debug)]
pub struct DirectMutationContext<'a> {
pub operation: DirectMutationOp,
pub table: &'a str,
pub columns: &'a [String],
pub values: &'a [serde_json::Value],
pub inject_columns: &'a [String],
pub return_type: &'a str,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum CursorValue {
Int64(i64),
Uuid(String),
}
#[derive(Debug, Clone, Copy)]
pub struct ProjectionRequest<'a> {
pub view: &'a str,
pub projection: Option<&'a SqlProjectionHint>,
pub where_clause: Option<&'a WhereClause>,
pub order_by: Option<&'a [OrderByClause]>,
pub limit: Option<u32>,
pub offset: Option<u32>,
}
impl<'a> ProjectionRequest<'a> {
#[must_use]
pub const fn new(view: &'a str) -> Self {
Self {
view,
projection: None,
where_clause: None,
order_by: None,
limit: None,
offset: None,
}
}
}
pub type BoxDatabaseAdapter = Box<dyn DatabaseAdapter>;
pub type ArcDatabaseAdapter = Arc<dyn DatabaseAdapter>;