use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(transparent)]
pub struct DriverId(String);
impl DriverId {
pub fn new(id: impl Into<String>) -> Self {
Self(id.into())
}
pub fn as_str(&self) -> &str {
&self.0
}
}
impl std::fmt::Display for DriverId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(&self.0)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum Support {
No,
ReadOnly,
Yes,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub struct DriverCapabilities {
pub read_tables: bool,
pub write_rows: bool,
pub create_table: bool,
pub drop_table: bool,
pub create_database: bool,
pub alter_table: bool,
pub rename_table: bool,
pub atomic_batch: bool,
pub passwords: bool,
pub autonumber: Support,
pub relationships: Support,
pub native_queries: Support,
pub macros: Support,
pub vba: Support,
pub triggers: Support,
pub stored_procedures: Support,
}
impl DriverCapabilities {
pub fn none() -> Self {
Self {
read_tables: false,
write_rows: false,
create_table: false,
drop_table: false,
create_database: false,
alter_table: false,
rename_table: false,
atomic_batch: false,
passwords: false,
autonumber: Support::No,
relationships: Support::No,
native_queries: Support::No,
macros: Support::No,
vba: Support::No,
triggers: Support::No,
stored_procedures: Support::No,
}
}
pub fn full() -> Self {
Self {
read_tables: true,
write_rows: true,
create_table: true,
drop_table: true,
create_database: true,
alter_table: true,
rename_table: true,
atomic_batch: false,
passwords: true,
autonumber: Support::No,
relationships: Support::Yes,
native_queries: Support::ReadOnly,
macros: Support::ReadOnly,
vba: Support::ReadOnly,
triggers: Support::No,
stored_procedures: Support::No,
}
}
pub fn unsupported(driver: &DriverId, what: &str) -> String {
format!("unsupported: the {driver} driver cannot {what}")
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct DriverInfo {
pub id: DriverId,
pub format: Option<super::DatabaseFormat>,
pub capabilities: DriverCapabilities,
}