use crate::{ adapter::Document, database::{Binding, Context, Kind, Registry, Settings, Sql, Storage}, task::{Limits, Runtime}, }; use std::{ path::PathBuf, sync::atomic::{AtomicU64, Ordering}, }; mod cache; mod configuration; mod isolation; mod lifecycle; mod performance; #[cfg(feature = "postgres")] mod postgres; static NEXT: AtomicU64 = AtomicU64::new(0); struct Directory(PathBuf); impl Directory { fn new() -> Self { let directory = Self(std::env::temp_dir().join(format!( "dever-tenant-{}-{}", std::process::id(), NEXT.fetch_add(1, Ordering::Relaxed) ))); std::fs::create_dir(&directory.0).unwrap(); directory } } impl Drop for Directory { fn drop(&mut self) { std::fs::remove_dir_all(&self.0).unwrap(); } } fn runtime() -> Runtime { Runtime::new(Limits { threads: 2, workers: 2, tasks: 32, }) .unwrap() } fn settings(tenant: bool, pools: usize) -> Settings { let mut document = serde_json::json!({"database":{"default":{"type":"sqlite","path":"platform.db","tenant_directory":"tenants","max_connections":2,"max_page_size":1,"wait_timeout_ms":100}}}); if tenant { document["tenant"] = serde_json::json!({"database":"default","max_pools":pools,"idle_timeout_ms":10}); } Settings::load(&Document::parse(document.to_string()).unwrap()).unwrap() } fn bindings() -> [Binding; 4] { [ Binding { storage: Storage::Tenant, component: "shop", database: None, table: "items", schema: Sql::same("CREATE TABLE items(id BIGINT PRIMARY KEY, value TEXT NOT NULL)"), plan: None, references: &[], }, Binding { storage: Storage::Global, component: "platform", database: None, table: "accounts", schema: Sql::same("CREATE TABLE accounts(id BIGINT PRIMARY KEY)"), plan: None, references: &[], }, Binding { storage: Storage::Authorization, component: "dever", database: None, table: "roles", schema: Sql::same("CREATE TABLE roles(id BIGINT PRIMARY KEY)"), plan: None, references: &[], }, Binding { storage: Storage::Control, component: "dever", database: None, table: "permissions", schema: Sql::same("CREATE TABLE permissions(id BIGINT PRIMARY KEY)"), plan: None, references: &[], }, ] }