Refined sqlez, implemented 60% of workspace serialization sql
This commit is contained in:
parent
6b214acbc4
commit
0186289420
11 changed files with 569 additions and 433 deletions
|
@ -1,5 +1,4 @@
|
|||
pub mod kvp;
|
||||
mod migrations;
|
||||
pub mod workspace;
|
||||
|
||||
use std::fs;
|
||||
|
@ -11,8 +10,9 @@ use indoc::indoc;
|
|||
use kvp::KVP_MIGRATION;
|
||||
use sqlez::connection::Connection;
|
||||
use sqlez::thread_safe_connection::ThreadSafeConnection;
|
||||
|
||||
use workspace::items::ITEM_MIGRATIONS;
|
||||
use workspace::pane::PANE_MIGRATIONS;
|
||||
|
||||
pub use workspace::*;
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -35,32 +35,21 @@ impl Db {
|
|||
.expect("Should be able to create the database directory");
|
||||
let db_path = current_db_dir.join(Path::new("db.sqlite"));
|
||||
|
||||
Db(
|
||||
ThreadSafeConnection::new(db_path.to_string_lossy().as_ref(), true)
|
||||
.with_initialize_query(indoc! {"
|
||||
PRAGMA journal_mode=WAL;
|
||||
PRAGMA synchronous=NORMAL;
|
||||
PRAGMA foreign_keys=TRUE;
|
||||
PRAGMA case_sensitive_like=TRUE;
|
||||
"})
|
||||
.with_migrations(&[KVP_MIGRATION, WORKSPACES_MIGRATION, PANE_MIGRATIONS]),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn persisting(&self) -> bool {
|
||||
self.persistent()
|
||||
Db(initialize_connection(ThreadSafeConnection::new(
|
||||
db_path.to_string_lossy().as_ref(),
|
||||
true,
|
||||
)))
|
||||
}
|
||||
|
||||
/// Open a in memory database for testing and as a fallback.
|
||||
pub fn open_in_memory(db_name: &str) -> Self {
|
||||
Db(ThreadSafeConnection::new(db_name, false)
|
||||
.with_initialize_query(indoc! {"
|
||||
PRAGMA journal_mode=WAL;
|
||||
PRAGMA synchronous=NORMAL;
|
||||
PRAGMA foreign_keys=TRUE;
|
||||
PRAGMA case_sensitive_like=TRUE;
|
||||
"})
|
||||
.with_migrations(&[KVP_MIGRATION, WORKSPACES_MIGRATION, PANE_MIGRATIONS]))
|
||||
Db(initialize_connection(ThreadSafeConnection::new(
|
||||
db_name, false,
|
||||
)))
|
||||
}
|
||||
|
||||
pub fn persisting(&self) -> bool {
|
||||
self.persistent()
|
||||
}
|
||||
|
||||
pub fn write_to<P: AsRef<Path>>(&self, dest: P) -> Result<()> {
|
||||
|
@ -68,3 +57,18 @@ impl Db {
|
|||
self.backup_main(&destination)
|
||||
}
|
||||
}
|
||||
|
||||
fn initialize_connection(conn: ThreadSafeConnection) -> ThreadSafeConnection {
|
||||
conn.with_initialize_query(indoc! {"
|
||||
PRAGMA journal_mode=WAL;
|
||||
PRAGMA synchronous=NORMAL;
|
||||
PRAGMA foreign_keys=TRUE;
|
||||
PRAGMA case_sensitive_like=TRUE;
|
||||
"})
|
||||
.with_migrations(&[
|
||||
KVP_MIGRATION,
|
||||
WORKSPACES_MIGRATION,
|
||||
PANE_MIGRATIONS,
|
||||
ITEM_MIGRATIONS,
|
||||
])
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue