From 399c35ad56526e406e33bfc6d7f5a861f3f9936f Mon Sep 17 00:00:00 2001 From: Keuin Date: Thu, 29 Feb 2024 00:41:45 +0800 Subject: explicitly set sqlite connection as readonly --- src/main.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 6bb7488..eb1bf74 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,7 @@ use futures_util::future::join_all; use futures_util::TryStreamExt; use serde_derive::{Deserialize, Serialize}; use sqlx::{Column, Row, SqlitePool}; +use sqlx::sqlite::SqliteConnectOptions; use sqlx::sqlite::SqlitePoolOptions; use tokio::task::JoinError; use tracing::{debug, info}; @@ -36,8 +37,11 @@ impl RelationReader { if cfg.fields.is_empty() { return Err(anyhow!("relation does not have any field")); } - // TODO make this configurable - match SqlitePoolOptions::new().max_connections(50).connect(&cfg.connect).await { + let opts = SqliteConnectOptions::new() + .filename(&cfg.connect).read_only(true) + .create_if_missing(false); + match SqlitePoolOptions::new() + .max_connections(50).connect_with(opts).await { Ok(p) => Ok(RelationReader { cfg: cfg.clone(), db: p, -- cgit v1.2.3