https://github.com/domnertech/domnertech-sqlclient
DomnerTech-SqlClient is for connect to SQL like MSSQL and PostgreSQL
https://github.com/domnertech/domnertech-sqlclient
domner-tech mssql pgsql
Last synced: 9 months ago
JSON representation
DomnerTech-SqlClient is for connect to SQL like MSSQL and PostgreSQL
- Host: GitHub
- URL: https://github.com/domnertech/domnertech-sqlclient
- Owner: DomnerTech
- License: mit
- Created: 2025-09-07T03:32:02.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-09-14T16:39:51.000Z (9 months ago)
- Last Synced: 2025-09-14T17:36:30.396Z (9 months ago)
- Topics: domner-tech, mssql, pgsql
- Language: Rust
- Homepage: https://crates.io/crates/domner_tech_sql_client
- Size: 80.1 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `DomnerTech-SqlClient`
DomnerTech-SqlClient is for connect to SQL like MSSQL and PostgreSQL
## `📦 Unified SQL Repo`
A lightweight async SQL repository abstraction for MSSQL (Tiberius) and PostgreSQL (tokio-postgres).
It provides a unified API for executing queries, commands, and bulk inserts across different databases using feature flags.
## `✨ Features`
- ✅ Unified API for MSSQL and PostgreSQL
- ✅ Async connection pooling (custom pool manager)
- ✅ Unified parameter binding (UnifiedToSql)
- ✅ Query execution with mapping support
- ✅ Bulk insert with safe parameterization
- ✅ Feature-flagged: compile only the driver you need
## `🚀 Installation`
Add this crate to your `Cargo.toml`:
```toml
[dependencies]
domner_tech_sql_client = { version = "0.1", features = ["mssql"] }
# or
domner_tech_sql_client = { version = "0.1", features = ["pgsql"] }
# or
domner_tech_sql_client = { version = "0.1", features = ["mssql, pgsql"] }
```
## Available features:
`mssql` → Enables [tiberius](https://crates.io/crates/tiberius) for SQL Server
`pgsql` → Enables [tokio-postgres](https://crates.io/crates/tokio-postgres) for PostgreSQL
## `âš¡ Usage`
### Initialize a pool
```rs
use domner_tech_sql_client::pool_manager::DbManager;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let manager = DbManager::new();
// For PostgreSQL
manager.init_pool(
"pg_pool",
"postgresql://postgres:admin@localhost:5432/mydb",
5
).await?;
// For MSSQL
manager.init_pool(
"mssql_pool",
"server=tcp:localhost,1433;User Id=sa;Password=your_password;TrustServerCertificate=true;",
5
).await?;
Ok(())
}
```
### Execute a query
```rs
use domner_tech_sql_client::{SqlRepo, CommandType};
use domner_tech_sql_client::pool_manager::{DbRow, DbManager};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let manager = DbManager::new();
manager.init_pool("pg_pool", "postgresql://postgres:admin@localhost:5432/mydb", 5).await?;
let mut client = manager.get_client("pg_pool").await?;
let rows = SqlRepo::execute_command_query(
&mut client,
"SELECT id, name FROM users WHERE id = $1",
&[&1],
CommandType::Text,
|row: &DbRow| {
#[cfg(feature = "pgsql")]
{
let id: i32 = row.get_pgsql(0).unwrap();
let name: String = row.get_pgsql(1).unwrap();
(id, name)
}
#[cfg(feature = "mssql")]
{
let id: Option = row.get_mssql("id").unwrap();
let name: Option = row.get_mssql("name").unwrap();
(id, name)
}
}
).await?;
println!("{:?}", rows);
Ok(())
}
```
### Bulk insert
```rs
let entities: Vec> = vec![
vec![&1, &"Alice"],
vec![&2, &"Bob"],
];
let affected = SqlRepo::execute_bulk_insert(
&mut client,
"users",
&["id", "name"],
&entities.iter().map(|e| e.as_slice()).collect::>(),
).await?;
```
## `🔧 Development`
- MSSQL support requires SQL Server running with TCP enabled.
- PostgreSQL support requires a `postgresql://` connection string.
- Run tests with the appropriate feature flag:
```bash
cargo test --features pgsql
cargo test --features mssql
```
## `📜 License`
Licensed under either of:
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)