GaussDB and OpenGauss support for Rust.
A native, synchronous GaussDB client with full PostgreSQL compatibility.
A native, asynchronous GaussDB client with full PostgreSQL compatibility.
Conversions between Rust and GaussDB/PostgreSQL types.
TLS support for gaussdb and tokio-gaussdb via native-tls.
TLS support for gaussdb and tokio-gaussdb via openssl.
This library provides full support for GaussDB's enhanced authentication mechanisms:
- SHA256 Authentication: GaussDB's secure SHA256-based authentication
- MD5_SHA256 Authentication: Hybrid authentication combining MD5 and SHA256
- Standard PostgreSQL Authentication: Full compatibility with MD5, SCRAM-SHA-256, and other PostgreSQL auth methods
use tokio_gaussdb::{NoTls, Error};
#[tokio::main]
async fn main() -> Result<(), Error> {
// Connect to GaussDB with SHA256 authentication
let (client, connection) = tokio_gaussdb::connect(
"host=localhost user=gaussdb password=Gaussdb@123 dbname=postgres port=5433",
NoTls,
).await?;
// Spawn the connection task
tokio::spawn(async move {
if let Err(e) = connection.await {
eprintln!("connection error: {}", e);
}
});
// Execute a simple query
let rows = client.query("SELECT $1::TEXT", &[&"hello world"]).await?;
let value: &str = rows[0].get(0);
println!("Result: {}", value);
Ok(())
}
use tokio_gaussdb::{Config, NoTls};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Configure connection with specific authentication
let mut config = Config::new();
config
.host("localhost")
.port(5433)
.user("gaussdb")
.password("Gaussdb@123")
.dbname("postgres");
let (client, connection) = config.connect(NoTls).await?;
// Handle connection...
tokio::spawn(async move {
if let Err(e) = connection.await {
eprintln!("connection error: {}", e);
}
});
// Your application logic here
Ok(())
}
Database | Version | Authentication | Status |
---|---|---|---|
GaussDB | 2.0+ | SHA256, MD5_SHA256, MD5 | ✅ Full Support |
OpenGauss | 3.0+ | SHA256, MD5_SHA256, MD5 | ✅ Full Support |
PostgreSQL | 10+ | SCRAM-SHA-256, MD5 | ✅ Full Support |
Feature | GaussDB | OpenGauss | PostgreSQL |
---|---|---|---|
Basic SQL Operations | ✅ | ✅ | ✅ |
Transactions | ✅ | ✅ | ✅ |
Prepared Statements | ✅ | ✅ | ✅ |
COPY Operations | ✅ | ✅ | ✅ |
LISTEN/NOTIFY | ✅ | ||
Binary COPY | ✅ |
The test suite requires GaussDB or OpenGauss to be running. The easiest way is with Docker:
-
Install
docker
anddocker-compose
- On Ubuntu:
sudo apt install docker.io docker-compose
- On Windows: Install Docker Desktop
- On macOS: Install Docker Desktop
- On Ubuntu:
-
Make sure your user has Docker permissions
- On Ubuntu:
sudo usermod -aG docker $USER
- On Ubuntu:
- Change to the top-level directory of
gaussdb-rust
repo - Start the test database:
docker-compose up -d
- Run the test suite:
cargo test
- Stop the test database:
docker-compose stop
The test suite supports both GaussDB and OpenGauss environments. Connection strings are automatically configured for:
- Host: localhost
- Port: 5433 (GaussDB/OpenGauss default)
- User: gaussdb
- Password: Gaussdb@123
- Database: postgres
- gaussdb - Synchronous client API
- tokio-gaussdb - Asynchronous client API
- gaussdb-types - Type conversion utilities
- gaussdb-protocol - Low-level protocol implementation
- GaussDB Connection Guide
- Authentication Methods
- Migration from rust-postgres
- GaussDB vs PostgreSQL Differences
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
-
Clone the repository:
git clone https://github.com/HuaweiCloudDeveloper/gaussdb-rust.git cd gaussdb-rust
-
Install Rust (if not already installed):
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
-
Run tests:
cargo test
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
This project is based on the excellent rust-postgres library by Steven Fackler. We extend our gratitude to the original authors and contributors.
- GitHub Issues - Bug reports and feature requests
- Documentation - API documentation and guides
- Examples - Code examples and tutorials