diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2024-09-20 23:30:47 -0400 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2024-09-20 23:30:47 -0400 |
| commit | a284e93ae79354a071f23113af916e0b3c89cd47 (patch) | |
| tree | 927063c51cf2c2ab8c6c252803bfb0093a17200f /src/repo/pool.rs | |
| parent | a4dcc4b5c53966f3c4366e414a3e39d094f21404 (diff) | |
Put database prep somewhere tests can call it.
Diffstat (limited to 'src/repo/pool.rs')
| -rw-r--r-- | src/repo/pool.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/repo/pool.rs b/src/repo/pool.rs new file mode 100644 index 0000000..b4aa6fc --- /dev/null +++ b/src/repo/pool.rs @@ -0,0 +1,18 @@ +use std::str::FromStr; + +use sqlx::sqlite::{SqliteConnectOptions, SqlitePool, SqlitePoolOptions}; + +pub async fn prepare(url: &str) -> sqlx::Result<SqlitePool> { + let pool = create(url).await?; + sqlx::migrate!().run(&pool).await?; + Ok(pool) +} + +async fn create(database_url: &str) -> sqlx::Result<SqlitePool> { + let options = SqliteConnectOptions::from_str(database_url)? + .create_if_missing(true) + .optimize_on_close(true, /* analysis_limit */ None); + + let pool = SqlitePoolOptions::new().connect_with(options).await?; + Ok(pool) +} |
