Crates.io | welds-connections |
lib.rs | welds-connections |
version | |
source | src |
created_at | 2024-03-06 01:55:09.379194+00 |
updated_at | 2025-04-14 01:49:47.712686+00 |
description | An async ORM for (postgres, mssql, mysql, sqlite) |
homepage | |
repository | https://github.com/weldsorm/welds |
max_upload_size | |
id | 1164261 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
It allows you to talk to sqlx and tiberius over traits in a simple common way.
/// The common trait for database connections and transactions.
pub trait Client {
/// Execute a sql command. returns the number of rows that were affected
async fn execute(&self, sql: &str, params: &[&(dyn Param + Sync)]) -> Result<ExecuteResult>;
/// Runs SQL and returns a collection of rows from the database.
async fn fetch_rows(&self, sql: &str, params: &[&(dyn Param + Sync)]) -> Result<Vec<Row>>;
/// Run several `fetch_rows` command on the same connection in the connection pool
async fn fetch_many(&self, args: &[Fetch]) -> Result<Vec<Vec<Row>>>;
// Returns what syntax (dialect) of SQL the backend is expecting
fn syntax(&self) -> Syntax;
}
Thats it.
Thats All this crate is.
You get this for:
MySql and its transactions
Postgres and its transactions
Sqlite and its transactions
Mssql and its transactions
You can get a transaction with the TransactStart Trait.
use welds_connections::{Client, TransactStart};
#[tokio::main]
async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
let url = "sqlite://./test.sqlite";
let client = welds_connections::connect(url).await?;
let transaction = client.begin().await?;
transaction.rollback.await?;
}
use welds_connections::{Client, TransactStart};
#[tokio::main]
async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
let url = "sqlite://./test.sqlite";
let client = welds_connections::connect(url).await?;
let sql = "SELECT name from people where name like ?";
let filter = "James%".to_string();
let rows = client.fetch_rows(sql, &[&filter]).await?;
for row in rows {
let name: String = row.get("name").unwrap();
println!("ROW: {:?}", &name);
}
}