dameng
A pure-Rust driver for Dameng Database (DM8).
Features
- Pure-Rust protocol — full DM8 binary wire protocol (STARTUP, LOGIN, EXEC, OPE, FETCH, COMMIT, ROLLBACK)
- SQLx-style parameter binding —
&[&id, &name]with automatic type conversion - Transaction support —
TransactionAPI with automatic rollback onDrop - Rich type system — INT, BIGINT, VARCHAR, FLOAT, DOUBLE, DECIMAL, DATE, TIME, TIMESTAMP, BLOB, CLOB, and more
- Safe — parameterized queries prevent SQL injection
- TLS support — optional SSL/TLS encrypted connections
Installation
[]
= "0.1"
Quick Start
Connect
use Client;
let mut client = new;
client.connect?;
Query
let rs = client.query?;
for row in rs.iter
Parameterized Queries (SQLx style)
let id: i32 = 1;
let name: &str = "Alice";
let rs = client.query_with_params?;
DML (INSERT / UPDATE / DELETE)
let affected = client.execute_with_params?;
println!;
Transactions
let mut tx = client.transaction?;
tx.execute_with_params?;
tx.execute_with_params?;
// Commit — tx is consumed, Client borrow is released
tx.commit?;
// Client is immediately available for reuse
client.close?;
All operations within a transaction execute as an atomic unit. If a Transaction is dropped without an explicit commit() or rollback(), a ROLLBACK is sent automatically.
Full CRUD Example
use Client;
API Reference
Client
| Method | Returns | Description |
|---|---|---|
Client::new(host, port) |
Client |
Create a new client |
connect(username, password) |
Result<()> |
Connect to the database |
close() |
Result<()> |
Close the connection |
transaction() |
Result<Transaction> |
Begin a new transaction |
execute(sql) |
Result<u64> |
Execute DML, returns affected rows |
execute_with_params(sql, params) |
Result<u64> |
Execute DML with parameters |
query(sql) |
Result<ResultSet> |
Execute a SELECT query |
query_with_params(sql, params) |
Result<ResultSet> |
Execute a SELECT query with parameters |
begin() |
Result<()> |
Disable auto-commit (low-level) |
Transaction
| Method | Returns | Description |
|---|---|---|
commit(self) |
Result<()> |
Commit and consume the transaction, releasing the Client |
rollback(self) |
Result<()> |
Rollback and consume the transaction, releasing the Client |
execute(sql) |
Result<u64> |
DML within the transaction |
execute_with_params(sql, params) |
Result<u64> |
DML with parameters within the transaction |
query(sql) |
Result<ResultSet> |
SELECT within the transaction |
query_with_params(sql, params) |
Result<ResultSet> |
SELECT with parameters within the transaction |
ResultSet
| Method / Field | Description |
|---|---|
iter() |
Returns an iterator over the rows |
columns |
Column metadata: Vec<Column> |
rows |
Row data: Vec<Row> |
total_row_count |
Total row count reported by the server |
QueryRow
| Method | Description |
|---|---|
get::<T>(idx) |
Get a column value by type (recommended) |
get_i32(idx) / get_i64(idx) |
Get an integer value |
get_str(idx) |
Get a string value |
get_f64(idx) |
Get a float value |
get_opt_str(idx) |
Get an optional string (NULL-safe) |
Type Mapping
| Rust Type | DM Type | ToDmValue |
|---|---|---|
i8 |
TINYINT | DmValue::TinyInt |
i16 |
SMALLINT | DmValue::SmallInt |
i32 |
INT | DmValue::Int |
i64 |
BIGINT | DmValue::BigInt |
f32 |
FLOAT | DmValue::Float |
f64 |
DOUBLE | DmValue::Double |
bool |
BIT | DmValue::Boolean |
&str / String |
VARCHAR | DmValue::Text |
Vec<u8> |
VARBINARY | DmValue::Bytea |
rust_decimal::Decimal |
DECIMAL | — |
chrono::NaiveDate |
DATE | — |
chrono::NaiveDateTime |
TIMESTAMP | — |
Connection Configuration
use ;
// Via DSN
let opts = from_dsn?;
let mut client = connect_with?;
// Or manually
let mut client = new;
client.auto_commit = false;
client.isolation_level = Serializable;
client.connect?;
Project Structure
rust-dameng/
├── dameng/ # Sync driver (main crate)
├── dameng-protocol/ # Wire protocol (message encode/decode + frame format)
├── dameng-types/ # Type system (DmValue + ToDmValue + encoding)
├── tokio-dameng/ # Async driver (in development)
├── dameng-macros/ # Procedural macros (in development)
├── integration-test/ # Integration tests
└── examples/ # Usage examples
License
MIT
Publishing to crates.io
This is a workspace with multiple sub-crates. Publish them in dependency order:
1. Update Cargo.toml metadata
Each sub-crate needs repository, keywords, categories, readme, and dependencies should use version numbers instead of paths:
[]
= "https://github.com/yourname/rust-dameng-ex"
= "https://docs.rs/dameng"
= "../README.md"
= ["dameng", "database", "sql", "dm8"]
= ["database"]
[]
# Use version instead of path for publishing
= "0.1"
= "0.1"
Files to update: dameng-types/Cargo.toml, dameng-protocol/Cargo.toml, dameng/Cargo.toml.
2. Publish in order
# Login
# Dry-run checks
# Publish (no external deps first)
3. Version management
- Use
0.1.0as the initial version; bump to1.0.0once the API stabilizes - Published versions cannot be deleted — use
cargo yankto deprecate - Always run
cargo publish --dry-runbefore publishing
4. Get your API token
- Sign in to crates.io with GitHub
- Go to Account Settings → API Tokens → New Token
- Run
cargo loginand paste the token