Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Invalid query method for setting journal_mode #212

Merged
merged 2 commits into from Dec 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 23 additions & 12 deletions core/src/db/client.rs
Expand Up @@ -4,6 +4,11 @@ use tracing::trace;

use crate::{config::get_config_dir, prisma};

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
struct JournalModeQueryResult {
journal_mode: String,
}

/// Creates the PrismaClient. Will call `create_data_dir` as well
pub async fn create_client() -> prisma::PrismaClient {
let config_dir = get_config_dir()
Expand Down Expand Up @@ -36,23 +41,29 @@ pub async fn create_client() -> prisma::PrismaClient {
.await
};

let enable_wal_var = std::env::var("ENABLE_WAL").ok();
let enable_wal = std::env::var("ENABLE_WAL")
.unwrap_or_else(|_| "false".to_string())
.unwrap_or_else(|_| "true".to_string())
.parse()
.unwrap_or_else(|error| {
tracing::error!(?error, "Failed to parse ENABLE_WAL");
false
tracing::error!(?error, enable_wal_var, "Failed to parse ENABLE_WAL");
true
});
let journal_value = if enable_wal { "WAL" } else { "DELETE" };

if enable_wal {
let _affected_rows = client
._execute_raw(raw!("PRAGMA journal_mode=WAL;"))
.exec()
.await
.unwrap_or_else(|error| {
tracing::error!(?error, "Failed to enable WAL mode");
0
});
let result = client
._query_raw::<JournalModeQueryResult>(raw!(&format!(
"PRAGMA journal_mode={journal_value};"
)))
.exec()
.await
.unwrap_or_else(|error| {
tracing::error!(?error, "Failed to set journal mode");
vec![]
});

if let Some(journal_mode) = result.first() {
tracing::debug!(?journal_mode, "Journal mode set");
}

client
Expand Down