use serde::{Deserialize, Serialize};
use crate::{AdapterError, SymbolTable};
mod memory;
mod sql;
#[cfg(feature = "sqlite")]
mod sqlite_backend;
#[cfg(feature = "postgres")]
mod postgres_backend;
pub use memory::MemoryDatabase;
pub use sql::{DatabaseStats, SchemaDatabaseSQL};
#[cfg(feature = "sqlite")]
pub use sqlite_backend::SQLiteDatabase;
#[cfg(feature = "postgres")]
pub use postgres_backend::PostgreSQLDatabase;
pub trait SchemaDatabase {
fn store_schema(&mut self, name: &str, table: &SymbolTable) -> Result<SchemaId, AdapterError>;
fn load_schema(&self, id: SchemaId) -> Result<SymbolTable, AdapterError>;
fn load_schema_by_name(&self, name: &str) -> Result<SymbolTable, AdapterError>;
fn list_schemas(&self) -> Result<Vec<SchemaMetadata>, AdapterError>;
fn delete_schema(&mut self, id: SchemaId) -> Result<(), AdapterError>;
fn search_schemas(&self, pattern: &str) -> Result<Vec<SchemaMetadata>, AdapterError>;
fn get_schema_history(&self, name: &str) -> Result<Vec<SchemaVersion>, AdapterError>;
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct SchemaId(pub u64);
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct SchemaMetadata {
pub id: SchemaId,
pub name: String,
pub version: u32,
pub created_at: u64,
pub updated_at: u64,
pub num_domains: usize,
pub num_predicates: usize,
pub num_variables: usize,
pub description: Option<String>,
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct SchemaVersion {
pub version: u32,
pub timestamp: u64,
pub description: String,
pub schema_id: SchemaId,
}
#[cfg(test)]
#[path = "../database_tests.rs"]
mod tests;