Allow creating and updating tasks on the backend. (#2)
Create hurl tests along with the necessary api code to resolve them. Reviewed-on: #2 Co-authored-by: Drew Galbraith <drew@tiramisu.one> Co-committed-by: Drew Galbraith <drew@tiramisu.one>
This commit is contained in:
parent
82d524a62f
commit
d32f6be813
10 changed files with 306 additions and 28 deletions
|
|
@ -2,20 +2,10 @@ use anyhow::Result;
|
|||
use sqlx::{SqlitePool, sqlite::SqliteConnectOptions};
|
||||
use std::str::FromStr;
|
||||
|
||||
/// Database configuration
|
||||
pub struct DatabaseConfig {
|
||||
pub database_url: String,
|
||||
}
|
||||
|
||||
impl Default for DatabaseConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
database_url: "sqlite:local.db".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a SQLx connection pool
|
||||
pub async fn create_pool(config: &DatabaseConfig) -> Result<SqlitePool> {
|
||||
let options = SqliteConnectOptions::from_str(&config.database_url)?.create_if_missing(true);
|
||||
|
||||
|
|
@ -26,12 +16,6 @@ pub async fn create_pool(config: &DatabaseConfig) -> Result<SqlitePool> {
|
|||
Ok(pool)
|
||||
}
|
||||
|
||||
/// Initialize database with connection pool
|
||||
pub async fn initialize_database() -> Result<SqlitePool> {
|
||||
let config = DatabaseConfig::default();
|
||||
create_pool(&config).await
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub async fn create_test_pool() -> Result<SqlitePool> {
|
||||
let options = SqliteConnectOptions::from_str("sqlite::memory:")?.create_if_missing(true);
|
||||
|
|
@ -42,4 +26,3 @@ pub async fn create_test_pool() -> Result<SqlitePool> {
|
|||
|
||||
Ok(pool)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue