Skip to content

Commit

Permalink
define default values for app as constants
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoh committed Jan 9, 2025
1 parent ff948cf commit b6c45a7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 7 additions & 3 deletions packages/duckdb-server-rust/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ async fn handle_get(
}
}

pub const DEFAULT_DB_PATH: &str = ":memory:";
pub const DEFAULT_CONNECTION_POOL_SIZE: u32 = 10;
pub const DEFAULT_CACHE_SIZE: usize = 1000;

#[axum::debug_handler]
async fn handle_post(
State(state): State<Arc<AppState>>,
Expand All @@ -49,10 +53,10 @@ pub fn app(
) -> Result<Router> {
// Database and state setup
let db = ConnectionPool::new(
dp_path.unwrap_or(":memory:"),
connection_pool_size.unwrap_or(10),
dp_path.unwrap_or(DEFAULT_DB_PATH),
connection_pool_size.unwrap_or(DEFAULT_CONNECTION_POOL_SIZE),
)?;
let cache = lru::LruCache::new(cache_size.unwrap_or(1000).try_into()?);
let cache = lru::LruCache::new(cache_size.unwrap_or(DEFAULT_CACHE_SIZE).try_into()?);

let state = Arc::new(AppState {
db: Box::new(db),
Expand Down
10 changes: 7 additions & 3 deletions packages/duckdb-server-rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ use std::{net::IpAddr, net::Ipv4Addr, net::SocketAddr, path::PathBuf};
use tokio::net;

Check warning on line 7 in packages/duckdb-server-rust/src/main.rs

View workflow job for this annotation

GitHub Actions / Test in Rust

Diff in /home/runner/work/mosaic/mosaic/packages/duckdb-server-rust/src/main.rs
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};

use crate::app::DEFAULT_DB_PATH;
use crate::app::DEFAULT_CONNECTION_POOL_SIZE;
use crate::app::DEFAULT_CACHE_SIZE;

mod app;
mod bundle;
mod cache;
Expand All @@ -19,7 +23,7 @@ mod websocket;
#[command(version, about, long_about = None)]
struct Args {
/// Path of database file (e.g., "database.db". ":memory:" for in-memory database)
#[arg(default_value = ":memory:")]
#[arg(default_value = DEFAULT_DB_PATH)]
database: String,

/// HTTP Address
Expand All @@ -31,11 +35,11 @@ struct Args {
port: u16,

/// Max connection pool size
#[arg(long, default_value_t = 10)]
#[arg(long, default_value_t = DEFAULT_CONNECTION_POOL_SIZE)]
connection_pool_size: u32,

/// Max number of cache entries
#[arg(long, default_value_t = 1000)]
#[arg(long, default_value_t = DEFAULT_CACHE_SIZE)]
cache_size: usize,
}

Expand Down

0 comments on commit b6c45a7

Please sign in to comment.