From 523a3f6ec45c4ac4ee8ac1ca5706eb8edaf6cb6c Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 26 May 2019 00:09:56 -0400 Subject: [PATCH] move transaction handling to rust code --- src/db.rs | 6 ++++-- src/init.sql | 4 ---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/db.rs b/src/db.rs index bf0c896..c030ecd 100644 --- a/src/db.rs +++ b/src/db.rs @@ -13,8 +13,10 @@ impl DbHandle { .as_ref() .map(|path: &String| PathBuf::from(path)) .unwrap_or_else(|| dirs::home_dir().unwrap().join(".foil").to_path_buf()); - let conn: Connection = Connection::open(path).unwrap(); - conn.execute_batch(DB_INIT_QUERY).unwrap(); + let mut conn: Connection = Connection::open(path).unwrap(); + let tx = conn.transaction().unwrap(); + tx.execute_batch(DB_INIT_QUERY).unwrap(); + tx.commit(); DbHandle { conn: conn } } } diff --git a/src/init.sql b/src/init.sql index 21f07d9..2e3c049 100644 --- a/src/init.sql +++ b/src/init.sql @@ -1,5 +1,3 @@ -BEGIN TRANSACTION; - CREATE TABLE IF NOT EXISTS encrypted_values ( id INTEGER PRIMARY KEY AUTOINCREMENT, iv TEXT, @@ -23,5 +21,3 @@ CREATE TABLE IF NOT EXISTS accounts( user INTEGER NOT NULL, password INTEGER NOT NULL ); - -END TRANSACTION;