Skip to content

HuaweiCloudDeveloper/gaussdb-rust

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

GaussDB-Rust

GaussDB and OpenGauss support for Rust.

gaussdb Latest Version

Documentation

A native, synchronous GaussDB client with full PostgreSQL compatibility.

tokio-gaussdb Latest Version

Documentation

A native, asynchronous GaussDB client with full PostgreSQL compatibility.

gaussdb-types Latest Version

Documentation

Conversions between Rust and GaussDB/PostgreSQL types.

gaussdb-native-tls Latest Version

Documentation

TLS support for gaussdb and tokio-gaussdb via native-tls.

gaussdb-openssl Latest Version

Documentation

TLS support for gaussdb and tokio-gaussdb via openssl.

Features

GaussDB Authentication Support

This library provides full support for GaussDB's enhanced authentication mechanisms:

  • SCRAM-SHA-256 Compatibility: Enhanced SCRAM-SHA-256 authentication with GaussDB/openGauss compatibility (v0.1.1+)
  • 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
  • Adaptive Authentication: Intelligent authentication method selection based on server type (v0.1.1+)

What's New in v0.1.1

SCRAM-SHA-256 Compatibility Fixes

  • βœ… Fixed SCRAM Authentication: Resolved "invalid message length: expected to be at end of iterator for sasl" error
  • βœ… GaussDB Message Parsing: Enhanced SASL message parser with GaussDB-specific format support
  • βœ… Dual Authentication Strategy: Automatic fallback from GaussDB-compatible to standard authentication
  • βœ… Runtime Conflict Resolution: Fixed "Cannot start a runtime from within a runtime" errors in async environments

Enhanced Features

  • πŸš€ Performance Optimized: Connection establishment time reduced to ~11.67ms average
  • πŸ” Better Diagnostics: Comprehensive error analysis and troubleshooting tools
  • πŸ§ͺ Extensive Testing: 184 tests with 100% pass rate on real GaussDB/openGauss environments
  • πŸ“Š Production Ready: Validated against openGauss 7.0.0-RC1 with high concurrency support

Quick Start

Basic Connection

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(())
}

Advanced Authentication

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(())
}

Compatibility

Database Support

Database Version Authentication Status
GaussDB 0.1.1+ SHA256, MD5_SHA256, MD5, SCRAM-SHA-256 βœ… Full Support
OpenGauss 3.0+ SHA256, MD5_SHA256, MD5, SCRAM-SHA-256 βœ… Full Support
PostgreSQL 10+ SCRAM-SHA-256, MD5 βœ… Full Support

Feature Compatibility

Feature GaussDB OpenGauss PostgreSQL
Basic SQL Operations βœ… βœ… βœ…
Transactions βœ… βœ… βœ…
Prepared Statements βœ… βœ… βœ…
COPY Operations βœ… βœ… βœ…
LISTEN/NOTIFY ⚠️ Limited ⚠️ Limited βœ…
Binary COPY ⚠️ Issues ⚠️ Issues βœ…

Running Tests

Prerequisites

The test suite requires GaussDB or OpenGauss to be running. The easiest way is with Docker:

  1. Install docker and docker-compose

    • On Ubuntu: sudo apt install docker.io docker-compose
    • On Windows: Install Docker Desktop
    • On macOS: Install Docker Desktop
  2. Make sure your user has Docker permissions

    • On Ubuntu: sudo usermod -aG docker $USER

Running Tests

  1. Change to the top-level directory of gaussdb-rust repo
  2. Start the test database:
    docker-compose up -d
  3. Run the test suite:
    cargo test
  4. Stop the test database:
    docker-compose stop

Test Configuration

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

Documentation

API Documentation

Guides and Examples

Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

Development Setup

  1. Clone the repository:

    git clone https://github.com/HuaweiCloudDeveloper/gaussdb-rust.git
    cd gaussdb-rust
  2. Install Rust (if not already installed):

    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  3. Run tests:

    cargo test

License

This project is licensed under either of

at your option.

Acknowledgments

This project is based on the excellent rust-postgres library by Steven Fackler. We extend our gratitude to the original authors and contributors.

Support

About

Native GaussDB driver for the Rust programming language

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 97.6%
  • Shell 2.4%