init basic database folder structure
This commit is contained in:
19
public/database/Cargo.toml
Normal file
19
public/database/Cargo.toml
Normal file
@@ -0,0 +1,19 @@
|
||||
[package]
|
||||
name = "database"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[lib]
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
shared = { path = "../shared" }
|
||||
migration = { path = "../migration" }
|
||||
chrono = { version = "0.4", features = ["serde"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
tokio = { version = "1.47.0", features = ["full"] }
|
||||
sea-orm = { version = "2.0.0-rc", features = [ "sqlx-postgres", "sqlx-mysql", "sqlx-sqlite", "runtime-tokio-rustls", "macros", "mock", "with-chrono", "with-json", "with-uuid", "sqlite-use-returning-for-3_35", "mariadb-use-returning" ] }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
22
public/database/src/lib.rs
Normal file
22
public/database/src/lib.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
use sea_orm::ConnectOptions;
|
||||
|
||||
pub async fn get_connection<T: FnOnce(&mut ConnectOptions) -> &mut ConnectOptions>(
|
||||
connection_string: &str,
|
||||
option_fn: Option<T>,
|
||||
) -> Result<sea_orm::DatabaseConnection, sea_orm::DbErr> {
|
||||
use sea_orm::Database;
|
||||
|
||||
let mut opt = ConnectOptions::new(connection_string.to_string());
|
||||
opt.max_connections(10)
|
||||
.min_connections(0)
|
||||
.connect_timeout(std::time::Duration::from_secs(8))
|
||||
.idle_timeout(std::time::Duration::from_secs(8))
|
||||
.test_before_acquire(true)
|
||||
.sqlx_logging(false);
|
||||
|
||||
if let Some(option_fn) = option_fn {
|
||||
option_fn(&mut opt);
|
||||
}
|
||||
|
||||
Database::connect(opt).await
|
||||
}
|
||||
Reference in New Issue
Block a user