use sqlx::SqlitePool;
use sqlx::sqlite::SqlitePoolOptions;
pub(crate) async fn test_pool() -> SqlitePool {
let pool = SqlitePoolOptions::new()
.max_connections(1)
.connect("sqlite::memory:")
.await
.expect("memory pool");
sqlx::migrate!("./migrations").run(&pool).await.expect("migrations");
let now = chrono::Utc::now().to_rfc3339();
sqlx::query("INSERT INTO projects (id, name, path, created_at) VALUES ('p1', 'p1', '/tmp', ?)")
.bind(&now)
.execute(&pool)
.await
.expect("project row");
for sid in ["s1", "s2"] {
sqlx::query(
"INSERT INTO sessions (id, project_id, workspace_path, created_at) \
VALUES (?, 'p1', '/tmp', ?)",
)
.bind(sid)
.bind(&now)
.execute(&pool)
.await
.expect("session row");
}
pool
}