Skip to content

Commit

Permalink
update sqlite directory and gitignore
Browse files Browse the repository at this point in the history
- Missed one place where the data directory changes in commit 668b460
- Updated gitignore to reflect new default data directory path
  • Loading branch information
szabodanika committed Jul 8, 2023
1 parent 668b460 commit a4ab033
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ target/
*.pdb

pasta_data/*
microbin_data/*
*.env
**/**/microbin-data
19 changes: 11 additions & 8 deletions src/util/db_sqlite.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use bytesize::ByteSize;
use rusqlite::{params, Connection};

use crate::{pasta::PastaFile, Pasta};

static DATABASE_PATH: &str = "pasta_data/database.sqlite";
use crate::{args::ARGS, pasta::PastaFile, Pasta};

pub fn read_all() -> Vec<Pasta> {
select_all_from_db()
Expand All @@ -14,7 +12,8 @@ pub fn update_all(pastas: &[Pasta]) {
}

pub fn rewrite_all_to_db(pasta_data: &[Pasta]) {
let conn = Connection::open(DATABASE_PATH).expect("Failed to open SQLite database!");
let conn = Connection::open(format!("{}/database.sqlite", ARGS.data_dir))
.expect("Failed to open SQLite database!");

conn.execute(
"
Expand Down Expand Up @@ -95,7 +94,8 @@ pub fn rewrite_all_to_db(pasta_data: &[Pasta]) {
}

pub fn select_all_from_db() -> Vec<Pasta> {
let conn = Connection::open(DATABASE_PATH).expect("Failed to open SQLite database!");
let conn = Connection::open(format!("{}/database.sqlite", ARGS.data_dir))
.expect("Failed to open SQLite database!");

conn.execute(
"
Expand Down Expand Up @@ -167,7 +167,8 @@ pub fn select_all_from_db() -> Vec<Pasta> {
}

pub fn insert(pasta: &Pasta) {
let conn = Connection::open(DATABASE_PATH).expect("Failed to open SQLite database!");
let conn = Connection::open(format!("{}/database.sqlite", ARGS.data_dir))
.expect("Failed to open SQLite database!");

conn.execute(
"
Expand Down Expand Up @@ -238,7 +239,8 @@ pub fn insert(pasta: &Pasta) {
}

pub fn update(pasta: &Pasta) {
let conn = Connection::open(DATABASE_PATH).expect("Failed to open SQLite database!");
let conn = Connection::open(format!("{}/database.sqlite", ARGS.data_dir))
.expect("Failed to open SQLite database!");

conn.execute(
"UPDATE pasta SET
Expand Down Expand Up @@ -283,7 +285,8 @@ pub fn update(pasta: &Pasta) {
}

pub fn delete_by_id(id: u64) {
let conn = Connection::open(DATABASE_PATH).expect("Failed to open SQLite database!");
let conn = Connection::open(format!("{}/database.sqlite", ARGS.data_dir))
.expect("Failed to open SQLite database!");

conn.execute(
"DELETE FROM pasta
Expand Down

0 comments on commit a4ab033

Please sign in to comment.