| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
pub mod accounts; |
| 5 |
pub mod repos; |
| 6 |
|
| 7 |
use sqlx::sqlite::{SqliteConnectOptions, SqliteJournalMode, SqlitePoolOptions, SqliteSynchronous}; |
| 8 |
use sqlx::SqlitePool; |
| 9 |
use std::path::Path; |
| 10 |
|
| 11 |
pub type Pool = SqlitePool; |
| 12 |
|
| 13 |
|
| 14 |
pub async fn open(path: &Path) -> anyhow::Result<Pool> { |
| 15 |
let options = SqliteConnectOptions::new() |
| 16 |
.filename(path) |
| 17 |
.create_if_missing(true) |
| 18 |
.journal_mode(SqliteJournalMode::Wal) |
| 19 |
.synchronous(SqliteSynchronous::Normal) |
| 20 |
.foreign_keys(true) |
| 21 |
.busy_timeout(std::time::Duration::from_secs(5)); |
| 22 |
let pool = SqlitePoolOptions::new().max_connections(8).connect_with(options).await?; |
| 23 |
sqlx::migrate!("./migrations").run(&pool).await?; |
| 24 |
Ok(pool) |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
pub fn now_ms() -> i64 { |
| 29 |
std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).map(|d| d.as_millis() as i64).unwrap_or(0) |
| 30 |
} |