-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
kirkbyers
committed
Mar 18, 2024
1 parent
c7db200
commit 7c6355e
Showing
1 changed file
with
22 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,25 @@ | ||
use libsql::{Builder, Database, Error}; | ||
use libsql::{params, Builder, Connection, Database, Error}; | ||
|
||
pub async fn new_local_db(path: &str) -> Result<Database, Error> { | ||
Builder::new_local(path).build().await | ||
let db = Builder::new_local(path).build().await?; | ||
let conn = db.connect()?; | ||
init_schema(&conn).await?; | ||
|
||
Ok(db) | ||
} | ||
|
||
async fn init_schema(conn: &Connection) -> Result<(), Error> { | ||
conn.execute( | ||
r#" | ||
CREATE TABLE IF NOT EXISTS subscriptions ( | ||
id uuid NOT NULL PRIMARY KEY, | ||
email TEXT NOT NULL UNIQUE, | ||
name TEXT NOT NULL, | ||
subscribed_at timestampz NOT NULL | ||
); | ||
"#, | ||
params!([]) | ||
) | ||
.await?; | ||
Ok(()) | ||
} |