Remove wal and shm files.
This commit is contained in:
parent
18d4ded010
commit
9100f08f5c
23
src/main.rs
23
src/main.rs
@ -1,5 +1,6 @@
|
|||||||
use sqlx::sqlite::SqliteConnectOptions;
|
use sqlx::sqlite::SqliteConnectOptions;
|
||||||
use sqlx::sqlite::SqlitePool;
|
use sqlx::sqlite::SqlitePool;
|
||||||
|
use sqlx::Connection;
|
||||||
use sqlx::Row;
|
use sqlx::Row;
|
||||||
use std::{env, str::FromStr};
|
use std::{env, str::FromStr};
|
||||||
use tokio::process::Command;
|
use tokio::process::Command;
|
||||||
@ -33,14 +34,21 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
let url = format!("sqlite://{}", db_path.as_path().display());
|
let url = format!("sqlite://{}", db_path.as_path().display());
|
||||||
|
|
||||||
let pool =
|
let mut dbconn = sqlx::SqliteConnection::connect_with(
|
||||||
SqlitePool::connect_with(SqliteConnectOptions::from_str(&url)?.create_if_missing(true))
|
&SqliteConnectOptions::from_str(&url)?
|
||||||
.await?;
|
.create_if_missing(true)
|
||||||
sqlx::migrate!("./migrations").run(&pool).await?;
|
// Use the normal journal mode to avoid those pesky shm and wal files
|
||||||
|
.journal_mode(sqlx::sqlite::SqliteJournalMode::Delete),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
// let pool =
|
||||||
|
// SqlitePool::connect_with(SqliteConnectOptions::from_str(&url)?.create_if_missing(true))
|
||||||
|
// .await?;
|
||||||
|
sqlx::migrate!("./migrations").run(&mut dbconn).await?;
|
||||||
|
|
||||||
let profiles_created: u64 = sqlx::query(r#"INSERT OR IGNORE INTO profile (name) VALUES (?)"#)
|
let profiles_created: u64 = sqlx::query(r#"INSERT OR IGNORE INTO profile (name) VALUES (?)"#)
|
||||||
.bind(&profile)
|
.bind(&profile)
|
||||||
.execute(&pool)
|
.execute(&mut dbconn)
|
||||||
.await?
|
.await?
|
||||||
.rows_affected();
|
.rows_affected();
|
||||||
if profiles_created != 0 {
|
if profiles_created != 0 {
|
||||||
@ -58,7 +66,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let already_watched_count: i64 = sqlx::query(r#"SELECT count(*) FROM watched WHERE path = ? AND profile = (SELECT id FROM PROFILE WHERE name = ?)"#)
|
let already_watched_count: i64 = sqlx::query(r#"SELECT count(*) FROM watched WHERE path = ? AND profile = (SELECT id FROM PROFILE WHERE name = ?)"#)
|
||||||
.bind(f.path().as_os_str().to_str())
|
.bind(f.path().as_os_str().to_str())
|
||||||
.bind(&profile)
|
.bind(&profile)
|
||||||
.fetch_one(&pool).await?.try_get("count(*)")?;
|
.fetch_one(&mut dbconn).await?.try_get("count(*)")?;
|
||||||
|
|
||||||
println!("Already watched count: {}", already_watched_count);
|
println!("Already watched count: {}", already_watched_count);
|
||||||
if already_watched_count > 0 {
|
if already_watched_count > 0 {
|
||||||
@ -78,7 +86,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let insert: u64 = sqlx::query(r#"INSERT INTO watched (profile, path, watched_at) SELECT (SELECT id FROM PROFILE WHERE name = ?) profile, ? path, DATETIME('now') watched_at"#)
|
let insert: u64 = sqlx::query(r#"INSERT INTO watched (profile, path, watched_at) SELECT (SELECT id FROM PROFILE WHERE name = ?) profile, ? path, DATETIME('now') watched_at"#)
|
||||||
.bind(&profile)
|
.bind(&profile)
|
||||||
.bind(f.path().as_os_str().to_str())
|
.bind(f.path().as_os_str().to_str())
|
||||||
.execute(&pool).await?.rows_affected();
|
.execute(&mut dbconn).await?.rows_affected();
|
||||||
println!("Insert: {:?}", insert);
|
println!("Insert: {:?}", insert);
|
||||||
assert!(insert == 1);
|
assert!(insert == 1);
|
||||||
continue;
|
continue;
|
||||||
@ -89,6 +97,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dbconn.close().await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user