Skip to content

Commit

Permalink
Throw error is database cant open
Browse files Browse the repository at this point in the history
  • Loading branch information
Sytten committed Sep 10, 2024
1 parent 07ed328 commit 4eb0d32
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/modules/sqlite/open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ use either::Either;
use rquickjs::{Ctx, FromJs, Null, Object, Result, Value};
use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions};

use crate::utils::result::ResultExt;

use super::Database;

static IN_MEMORY_DB_SEQ: AtomicUsize = AtomicUsize::new(0);

pub async fn open(options: OpenOptions) -> Result<Database> {
pub async fn open(ctx: Ctx<'_>, options: OpenOptions) -> Result<Database> {
let mut connect_options = SqliteConnectOptions::new();
connect_options = connect_options
.foreign_keys(options.foreign_keys)
Expand Down Expand Up @@ -40,7 +42,10 @@ pub async fn open(options: OpenOptions) -> Result<Database> {
.max_connections(options.max_connections)
.min_connections(options.min_connections);

let pool = pool_options.connect_with(connect_options).await.unwrap();
let pool = pool_options
.connect_with(connect_options)
.await
.or_throw_msg(&ctx, "Unable to open database")?;
Ok(Database::new(pool))
}

Expand Down

0 comments on commit 4eb0d32

Please sign in to comment.