Skip to content

Commit 8db3edf

Browse files
feat: duckdb configuration options
Signed-off-by: Henry Gressmann <[email protected]>
1 parent 3fdf367 commit 8db3edf

File tree

5 files changed

+82
-47
lines changed

5 files changed

+82
-47
lines changed

Cargo.lock

Lines changed: 45 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config.example.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,8 @@ port=9042
2020
# # If you don't want to automatically download the database, you can specify a path to a local file
2121
# # Otherwise, the database will be downloaded automatically and stored in the data_dir
2222
# maxmind_db_path="./GeoLite2-City.mmdb"
23+
24+
[duckdb]
25+
# See https://liwan.dev/guides/duckdb
26+
# threads=2
27+
# memory_limit=2G

src/app/db.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::config::DuckdbConfig;
12
use crate::utils::refinery_duckdb::DuckDBConnection;
23
use crate::utils::refinery_sqlite::RqlConnection;
34

@@ -9,6 +10,7 @@ use std::path::PathBuf;
910

1011
pub(super) fn init_duckdb(
1112
path: &PathBuf,
13+
duckdb_config: Option<DuckdbConfig>,
1214
mut migrations_runner: Runner,
1315
) -> Result<r2d2::Pool<DuckdbConnectionManager>> {
1416
let conn = DuckdbConnectionManager::file(path)?;
@@ -22,6 +24,16 @@ pub(super) fn init_duckdb(
2224
conn.pragma_update(None, "autoinstall_known_extensions", &"false")?;
2325
conn.pragma_update(None, "autoload_known_extensions", &"false")?;
2426
conn.pragma_update(None, "enable_fsst_vectors", &"true")?;
27+
28+
if let Some(duckdb_config) = duckdb_config {
29+
if let Some(memory_limit) = duckdb_config.memory_limit {
30+
conn.pragma_update(None, "memory_limit", &memory_limit)?;
31+
}
32+
33+
if let Some(threads) = duckdb_config.threads {
34+
conn.pragma_update(None, "threads", &threads.to_string())?;
35+
}
36+
}
2537
}
2638

2739
Ok(pool)

src/app/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ impl Liwan {
5050

5151
tracing::debug!("Initializing databases");
5252
let conn_app = db::init_sqlite(&folder.join("liwan-app.sqlite"), embedded::app::migrations::runner())?;
53-
let conn_events = db::init_duckdb(&folder.join("liwan-events.duckdb"), embedded::events::migrations::runner())?;
53+
let conn_events = db::init_duckdb(
54+
&folder.join("liwan-events.duckdb"),
55+
config.duckdb.clone(),
56+
embedded::events::migrations::runner(),
57+
)?;
5458

5559
Ok(Self {
5660
#[cfg(feature = "geoip")]

0 commit comments

Comments
 (0)