rs-db 0.1.0
One small API for databases: connect with a connection string, execute, query rows as typed values, transactions, JSON rows. The interface behind the rs-db-* connectors.
Install
cargo add rs-db --registry rupm
In Ruststudio: Packages, search for rs-db, Install.
Owner: Rust Studio. Licence: MIT OR Apache-2.0. Total downloads: 0. Published 2026-11-23.
Versions
- 0.1.0 2026-11-23
README
# rs-db
One small API for databases. A connector crate wraps one driver and implements the `Connector` trait, so a program talks
to SQLite, PostgreSQL, MySQL, SQL Server, MongoDB or Redis the same way:
| Database | Crate (rupm) | .NET package (NuGet) | Driver inside |
|---|---|---|---|
| SQLite | `rs-db-sqlite` | `Ruststudio.Db.Sqlite` | rusqlite (SQLite bundled) |
| PostgreSQL | `rs-db-postgres` | `Ruststudio.Db.Postgres` | postgres |
| MySQL / MariaDB | `rs-db-mysql` | `Ruststudio.Db.MySql` | mysql |
| SQL Server | `rs-db-sqlserver` | `Ruststudio.Db.SqlServer` | tiberius |
| MongoDB | `rs-db-mongodb` | `Ruststudio.Db.MongoDb` | mongodb |
| Redis / Valkey | `rs-db-redis` | `Ruststudio.Db.Redis` | redis |
You normally add a connector crate, not this one: every connector re-exports `rs-db`.
```
cargo add rs-db-sqlite --registry rupm
```
## The API
```rust
use rs_db_sqlite::{transaction, Connector, SqliteConnector};
fn main() -> rs_db_sqlite::Result<()> {
let mut db = SqliteConnector::connect("app.db")?; // the engine's own connection string
db.execute("CREATE TABLE IF NOT EXISTS item (id INTEGER PRIMARY KEY, name TEXT NOT NULL)")?;
let changed = db.execute("INSERT INTO item (name) VALUES ('first')")?; // rows changed
let rows = db.query("SELECT id, name FROM item")?; // column names + typed values
for row in rows.iter() {
println!("{} {}", row.get("id").unwrap(), row.get("name").unwrap());
}
println!("{}", rows.to_json()); // [{"id":1,"name":"first"}]
transaction(&mut db, |db| db.execute("DELETE FROM item"))?; // commit on Ok, roll back on Err
println!("{changed} row added");
db.close()
}
```
- `Connector`: `connect(&str)`, `execute(&str) -> u64`, `query(&str) -> Rows`, `begin` / `commit` / `rollback`
(engines without transactions answer `ErrorKind::Unsupported`), `close()`, `engine()`.
- `Rows`: `columns`, `rows`, `len()`, `get(row, "column")`, `scalar()`, `iter()`, `to_json()`.
- `Value`: `Null`, `Bool`, `Int(i64)`, `Float(f64)`, `Text`, `Bytes`.
- `Error`: `kind` (`Connect`, `Query`, `Unsupported`, `Input`), `engine`, and `message`, which is the engine's own text.
- `rs_db::json`: rows as JSON without a JSON library. `rs_db::ffi`: the C functions behind the .NET packages.
The API is blocking: no async runtime is needed to call it. `rs-db` itself has no dependencies.
## A runnable example
`examples/memory.rs` is a complete connector in one file (a key/value store in memory, with transactions) and a program
that uses it. It needs no database:
```
cargo run --example memory
```
## Not in 0.1
- Bound parameters: statements are sent as text, so never build one from input you do not trust. Every connector has
`inner()`, which gives the driver's own connection with its parameter support.
- Connection pools, async, streaming of large results.
## Licence
MIT OR Apache-2.0.