| d23464c0 Andy McCall ↶ |
1 |
|
| 2 |
|
| 3 |
|
| 19bb31ff Andy McCall ↶ |
4 |
pub mod accounts; |
| 25ab8c73 Andy McCall ↶ |
5 |
pub mod activity; |
| 42fa9554 Andy McCall ↶ |
6 |
pub mod flow; |
| b64e2537 Andy McCall ↶ |
7 |
pub mod hooks; |
| 18e381ea Andy McCall ↶ |
8 |
pub mod issues; |
| 9 |
pub mod notify; |
| e1ec9fbf Andy McCall ↶ |
10 |
pub mod projects; |
| de505df5 Andy McCall ↶ |
11 |
pub mod proposals; |
| 3f4b0ea6 Andy McCall ↶ |
12 |
pub mod releases; |
| d23464c0 Andy McCall ↶ |
13 |
pub mod repos; |
| b6b7e4cf Andy McCall ↶ |
14 |
pub mod runners; |
| d23464c0 Andy McCall ↶ |
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 |
} |
| 941abdd6 Andy McCall ↶ |
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 |
} |