Bump version to 0.1.5 and add database pool accessors for SQLite and Postgres
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -747,7 +747,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "k-core"
|
||||
version = "0.1.4"
|
||||
version = "0.1.5"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"chrono",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "k-core"
|
||||
version = "0.1.4"
|
||||
version = "0.1.5"
|
||||
edition = "2024"
|
||||
|
||||
[features]
|
||||
|
||||
20
src/db.rs
20
src/db.rs
@@ -110,7 +110,25 @@ pub async fn connect(config: &DatabaseConfig) -> Result<DatabasePool, sqlx::Erro
|
||||
}
|
||||
}
|
||||
|
||||
// Re-export specific connectors if you still need manual control
|
||||
impl DatabasePool {
|
||||
#[cfg(feature = "sqlite")]
|
||||
pub fn sqlite_pool(&self) -> Option<&Pool<Sqlite>> {
|
||||
if let DatabasePool::Sqlite(pool) = self {
|
||||
Some(pool)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "postgres")]
|
||||
pub fn postgres_pool(&self) -> Option<&Pool<Postgres>> {
|
||||
if let DatabasePool::Postgres(pool) = self {
|
||||
Some(pool)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "sqlite")]
|
||||
pub async fn connect_sqlite(url: &str) -> Result<Pool<Sqlite>, sqlx::Error> {
|
||||
sqlx::sqlite::SqlitePoolOptions::new().connect(url).await
|
||||
|
||||
Reference in New Issue
Block a user