| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
pub mod accounts; |
| 5 |
pub mod activity; |
| 6 |
pub mod flow; |
| 7 |
pub mod hooks; |
| 8 |
pub mod issues; |
| 9 |
pub mod notify; |
| 10 |
pub mod projects; |
| 11 |
pub mod proposals; |
| 12 |
pub mod releases; |
| 13 |
pub mod repos; |
| 14 |
pub mod runners; |
| 15 |
|
| 16 |
use sqlx::sqlite::{SqliteConnectOptions, SqliteJournalMode, SqlitePoolOptions, SqliteSynchronous}; |
| 17 |
use sqlx::SqlitePool; |
| 18 |
use std::path::Path; |
| 19 |
|
| 20 |
pub type Pool = SqlitePool; |
| 21 |
|
| 22 |
|
| 23 |
pub async fn open(path: &Path) -> anyhow::Result<Pool> { |
| 24 |
let options = SqliteConnectOptions::new() |
| 25 |
.filename(path) |
| 26 |
.create_if_missing(true) |
| 27 |
.journal_mode(SqliteJournalMode::Wal) |
| 28 |
.synchronous(SqliteSynchronous::Normal) |
| 29 |
.foreign_keys(true) |
| 30 |
.busy_timeout(std::time::Duration::from_secs(5)); |
| 31 |
let pool = SqlitePoolOptions::new().max_connections(8).connect_with(options).await?; |
| 32 |
sqlx::migrate!("./migrations").run(&pool).await?; |
| 33 |
Ok(pool) |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
pub fn now_ms() -> i64 { |
| 38 |
std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).map(|d| d.as_millis() as i64).unwrap_or(0) |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
pub async fn begin_write(pool: &Pool) -> sqlx::Result<sqlx::Transaction<'static, sqlx::Sqlite>> { |
| 46 |
pool.begin_with("BEGIN IMMEDIATE").await |
| 47 |
} |