diff --git a/src/api_test.rs b/src/api_test.rs index ae2d105c..9a651dbd 100644 --- a/src/api_test.rs +++ b/src/api_test.rs @@ -14,7 +14,15 @@ use sqlx::{ use std::str::FromStr; pub async fn run_api_tests(table: &str, database: &str) -> Result<(), sqlx::Error> { - let config = valve(table, database, &ValveCommand::Config, false, "table").await?; + let config = valve( + table, + database, + &ValveCommand::Config, + false, + false, + "table", + ) + .await?; let config: SerdeValue = serde_json::from_str(config.as_str()).unwrap(); let config = config.as_object().unwrap(); diff --git a/src/lib.rs b/src/lib.rs index e2f4c05c..a494acf7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -982,12 +982,16 @@ pub enum ValveCommand { /// optionally create and/or load it according to the value of `command` (see [ValveCommand]). /// If the `verbose` flag is set to true, output status messages while loading. If `config_table` /// is given and `table_table` indicates a database, query the table called `config_table` for the -/// table table information. Returns the configuration map as a String. +/// table table information. Returns the configuration map as a String. If `initial_load` is set to +/// true, then (SQLite only) the database settings will be tuned for initial loading. Note that +/// these settings are unsafe and should be used for initial loading only, as data integrity will +/// not be guaranteed in the case of an interrupted transaction. pub async fn valve( table_table: &str, database: &str, command: &ValveCommand, verbose: bool, + initial_load: bool, config_table: &str, ) -> Result { let parser = StartParser::new(); @@ -1025,6 +1029,20 @@ pub async fn valve( sqlx_query("PRAGMA foreign_keys = ON") .execute(&pool) .await?; + if initial_load { + // These pragmas are unsafe but they are used during initial loading since data + // integrity is not a priority in this case. + sqlx_query("PRAGMA journal_mode = OFF") + .execute(&pool) + .await?; + sqlx_query("PRAGMA synchronous = 0").execute(&pool).await?; + sqlx_query("PRAGMA cache_size = 1000000") + .execute(&pool) + .await?; + sqlx_query("PRAGMA temp_store = MEMORY") + .execute(&pool) + .await?; + } } let (sorted_table_list, constraints_config) = configure_db( diff --git a/src/main.rs b/src/main.rs index 19a737e5..7e61aba4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,6 +22,7 @@ async fn main() -> Result<(), sqlx::Error> { let mut create_only = false; let mut config_table = String::new(); let mut verbose = false; + let mut initial_load = false; let mut source = String::new(); let mut destination = String::new(); @@ -65,6 +66,14 @@ async fn main() -> Result<(), sqlx::Error> { r#"Write the SQL used to create the database to stdout after configuring it, and then while loading the database, write progress messages to stderr."#, ); + ap.refer(&mut initial_load).add_option( + &["--initial_load"], + StoreTrue, + r#"(SQLite only) When this flag is set, the database settings will be tuned for initial + loading. Note that these settings are unsafe and should be used for initial loading + only, as data integrity will not be guaranteed in the case of an interrupted + transaction."#, + ); ap.refer(&mut source).add_argument( "SOURCE", Store, @@ -109,6 +118,7 @@ async fn main() -> Result<(), sqlx::Error> { &String::from(":memory:"), &ValveCommand::Config, false, + false, &config_table, ) .await?; @@ -141,6 +151,7 @@ async fn main() -> Result<(), sqlx::Error> { &destination, &ValveCommand::Create, verbose, + false, &config_table, ) .await?; @@ -150,6 +161,7 @@ async fn main() -> Result<(), sqlx::Error> { &destination, &ValveCommand::Load, verbose, + initial_load, &config_table, ) .await?;