//! SQLite through `sqlx` (hub spec §3.1, §17.2): WAL, foreign keys on, //! migrations embedded and applied at start. One module per table group. pub mod accounts; pub mod activity; pub mod hooks; pub mod issues; pub mod notify; pub mod proposals; pub mod repos; use sqlx::sqlite::{SqliteConnectOptions, SqliteJournalMode, SqlitePoolOptions, SqliteSynchronous}; use sqlx::SqlitePool; use std::path::Path; pub type Pool = SqlitePool; /// Open (creating if needed) and migrate the database at `path`. pub async fn open(path: &Path) -> anyhow::Result { let options = SqliteConnectOptions::new() .filename(path) .create_if_missing(true) .journal_mode(SqliteJournalMode::Wal) .synchronous(SqliteSynchronous::Normal) .foreign_keys(true) .busy_timeout(std::time::Duration::from_secs(5)); let pool = SqlitePoolOptions::new().max_connections(8).connect_with(options).await?; sqlx::migrate!("./migrations").run(&pool).await?; Ok(pool) } /// Milliseconds since the epoch, the hub's timestamp unit (as `oxy`'s). pub fn now_ms() -> i64 { std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).map(|d| d.as_millis() as i64).unwrap_or(0) }