|
1 | | -# Rust-Postgres |
| 1 | +# GaussDB-Rust |
2 | 2 |
|
3 | | -PostgreSQL support for Rust. |
| 3 | +GaussDB and OpenGauss support for Rust. |
4 | 4 |
|
5 | | -## postgres [](https://crates.io/crates/postgres) |
| 5 | +## gaussdb [](https://crates.io/crates/gaussdb) |
6 | 6 |
|
7 | | -[Documentation](https://docs.rs/postgres) |
| 7 | +[Documentation](https://docs.rs/gaussdb) |
8 | 8 |
|
9 | | -A native, synchronous PostgreSQL client. |
| 9 | +A native, synchronous GaussDB client with full PostgreSQL compatibility. |
10 | 10 |
|
11 | | -## tokio-postgres [](https://crates.io/crates/tokio-postgres) |
| 11 | +## tokio-gaussdb [](https://crates.io/crates/tokio-gaussdb) |
12 | 12 |
|
13 | | -[Documentation](https://docs.rs/tokio-postgres) |
| 13 | +[Documentation](https://docs.rs/tokio-gaussdb) |
14 | 14 |
|
15 | | -A native, asynchronous PostgreSQL client. |
| 15 | +A native, asynchronous GaussDB client with full PostgreSQL compatibility. |
16 | 16 |
|
17 | | -## postgres-types [](https://crates.io/crates/postgres-types) |
| 17 | +## gaussdb-types [](https://crates.io/crates/gaussdb-types) |
18 | 18 |
|
19 | | -[Documentation](https://docs.rs/postgres-types) |
| 19 | +[Documentation](https://docs.rs/gaussdb-types) |
20 | 20 |
|
21 | | -Conversions between Rust and Postgres types. |
| 21 | +Conversions between Rust and GaussDB/PostgreSQL types. |
22 | 22 |
|
23 | | -## postgres-native-tls [](https://crates.io/crates/postgres-native-tls) |
| 23 | +## gaussdb-native-tls [](https://crates.io/crates/gaussdb-native-tls) |
24 | 24 |
|
25 | | -[Documentation](https://docs.rs/postgres-native-tls) |
| 25 | +[Documentation](https://docs.rs/gaussdb-native-tls) |
26 | 26 |
|
27 | | -TLS support for postgres and tokio-postgres via native-tls. |
| 27 | +TLS support for gaussdb and tokio-gaussdb via native-tls. |
28 | 28 |
|
29 | | -## postgres-openssl [](https://crates.io/crates/postgres-openssl) |
| 29 | +## gaussdb-openssl [](https://crates.io/crates/gaussdb-openssl) |
30 | 30 |
|
31 | | -[Documentation](https://docs.rs/postgres-openssl) |
| 31 | +[Documentation](https://docs.rs/gaussdb-openssl) |
32 | 32 |
|
33 | | -TLS support for postgres and tokio-postgres via openssl. |
| 33 | +TLS support for gaussdb and tokio-gaussdb via openssl. |
34 | 34 |
|
35 | | -# Running test suite |
| 35 | +# Features |
36 | 36 |
|
37 | | -The test suite requires postgres to be running in the correct configuration. The easiest way to do this is with docker: |
| 37 | +## GaussDB Authentication Support |
38 | 38 |
|
39 | | -1. Install `docker` and `docker-compose`. |
40 | | - 1. On ubuntu: `sudo apt install docker.io docker-compose`. |
41 | | -1. Make sure your user has permissions for docker. |
42 | | - 1. On ubuntu: ``sudo usermod -aG docker $USER`` |
43 | | -1. Change to top-level directory of `rust-postgres` repo. |
44 | | -1. Run `docker-compose up -d`. |
45 | | -1. Run `cargo test`. |
46 | | -1. Run `docker-compose stop`. |
| 39 | +This library provides full support for GaussDB's enhanced authentication mechanisms: |
| 40 | + |
| 41 | +- **SHA256 Authentication**: GaussDB's secure SHA256-based authentication |
| 42 | +- **MD5_SHA256 Authentication**: Hybrid authentication combining MD5 and SHA256 |
| 43 | +- **Standard PostgreSQL Authentication**: Full compatibility with MD5, SCRAM-SHA-256, and other PostgreSQL auth methods |
| 44 | + |
| 45 | +## Quick Start |
| 46 | + |
| 47 | +### Basic Connection |
| 48 | + |
| 49 | +```rust |
| 50 | +use tokio_gaussdb::{NoTls, Error}; |
| 51 | + |
| 52 | +#[tokio::main] |
| 53 | +async fn main() -> Result<(), Error> { |
| 54 | + // Connect to GaussDB with SHA256 authentication |
| 55 | + let (client, connection) = tokio_gaussdb::connect( |
| 56 | + "host=localhost user=gaussdb password=Gaussdb@123 dbname=postgres port=5433", |
| 57 | + NoTls, |
| 58 | + ).await?; |
| 59 | + |
| 60 | + // Spawn the connection task |
| 61 | + tokio::spawn(async move { |
| 62 | + if let Err(e) = connection.await { |
| 63 | + eprintln!("connection error: {}", e); |
| 64 | + } |
| 65 | + }); |
| 66 | + |
| 67 | + // Execute a simple query |
| 68 | + let rows = client.query("SELECT $1::TEXT", &[&"hello world"]).await?; |
| 69 | + let value: &str = rows[0].get(0); |
| 70 | + println!("Result: {}", value); |
| 71 | + |
| 72 | + Ok(()) |
| 73 | +} |
| 74 | +``` |
| 75 | + |
| 76 | +### Advanced Authentication |
| 77 | + |
| 78 | +```rust |
| 79 | +use tokio_gaussdb::{Config, NoTls}; |
| 80 | + |
| 81 | +#[tokio::main] |
| 82 | +async fn main() -> Result<(), Box<dyn std::error::Error>> { |
| 83 | + // Configure connection with specific authentication |
| 84 | + let mut config = Config::new(); |
| 85 | + config |
| 86 | + .host("localhost") |
| 87 | + .port(5433) |
| 88 | + .user("gaussdb") |
| 89 | + .password("Gaussdb@123") |
| 90 | + .dbname("postgres"); |
| 91 | + |
| 92 | + let (client, connection) = config.connect(NoTls).await?; |
| 93 | + |
| 94 | + // Handle connection... |
| 95 | + tokio::spawn(async move { |
| 96 | + if let Err(e) = connection.await { |
| 97 | + eprintln!("connection error: {}", e); |
| 98 | + } |
| 99 | + }); |
| 100 | + |
| 101 | + // Your application logic here |
| 102 | + Ok(()) |
| 103 | +} |
| 104 | +``` |
| 105 | + |
| 106 | +## Compatibility |
| 107 | + |
| 108 | +### Database Support |
| 109 | + |
| 110 | +| Database | Version | Authentication | Status | |
| 111 | +|----------|---------|----------------|--------| |
| 112 | +| GaussDB | 2.0+ | SHA256, MD5_SHA256, MD5 | ✅ Full Support | |
| 113 | +| OpenGauss | 3.0+ | SHA256, MD5_SHA256, MD5 | ✅ Full Support | |
| 114 | +| PostgreSQL | 10+ | SCRAM-SHA-256, MD5 | ✅ Full Support | |
| 115 | + |
| 116 | +### Feature Compatibility |
| 117 | + |
| 118 | +| Feature | GaussDB | OpenGauss | PostgreSQL | |
| 119 | +|---------|---------|-----------|------------| |
| 120 | +| Basic SQL Operations | ✅ | ✅ | ✅ | |
| 121 | +| Transactions | ✅ | ✅ | ✅ | |
| 122 | +| Prepared Statements | ✅ | ✅ | ✅ | |
| 123 | +| COPY Operations | ✅ | ✅ | ✅ | |
| 124 | +| LISTEN/NOTIFY | ⚠️ Limited | ⚠️ Limited | ✅ | |
| 125 | +| Binary COPY | ⚠️ Issues | ⚠️ Issues | ✅ | |
| 126 | + |
| 127 | +## Running Tests |
| 128 | + |
| 129 | +### Prerequisites |
| 130 | + |
| 131 | +The test suite requires GaussDB or OpenGauss to be running. The easiest way is with Docker: |
| 132 | + |
| 133 | +1. Install `docker` and `docker-compose` |
| 134 | + - On Ubuntu: `sudo apt install docker.io docker-compose` |
| 135 | + - On Windows: Install Docker Desktop |
| 136 | + - On macOS: Install Docker Desktop |
| 137 | + |
| 138 | +2. Make sure your user has Docker permissions |
| 139 | + - On Ubuntu: `sudo usermod -aG docker $USER` |
| 140 | + |
| 141 | +### Running Tests |
| 142 | + |
| 143 | +1. Change to the top-level directory of `gaussdb-rust` repo |
| 144 | +2. Start the test database: |
| 145 | + ```bash |
| 146 | + docker-compose up -d |
| 147 | + ``` |
| 148 | +3. Run the test suite: |
| 149 | + ```bash |
| 150 | + cargo test |
| 151 | + ``` |
| 152 | +4. Stop the test database: |
| 153 | + ```bash |
| 154 | + docker-compose stop |
| 155 | + ``` |
| 156 | + |
| 157 | +### Test Configuration |
| 158 | + |
| 159 | +The test suite supports both GaussDB and OpenGauss environments. Connection strings are automatically configured for: |
| 160 | + |
| 161 | +- **Host**: localhost |
| 162 | +- **Port**: 5433 (GaussDB/OpenGauss default) |
| 163 | +- **User**: gaussdb |
| 164 | +- **Password**: Gaussdb@123 |
| 165 | +- **Database**: postgres |
| 166 | + |
| 167 | +## Documentation |
| 168 | + |
| 169 | +### API Documentation |
| 170 | + |
| 171 | +- [gaussdb](https://docs.rs/gaussdb) - Synchronous client API |
| 172 | +- [tokio-gaussdb](https://docs.rs/tokio-gaussdb) - Asynchronous client API |
| 173 | +- [gaussdb-types](https://docs.rs/gaussdb-types) - Type conversion utilities |
| 174 | +- [gaussdb-protocol](https://docs.rs/gaussdb-protocol) - Low-level protocol implementation |
| 175 | + |
| 176 | +### Guides and Examples |
| 177 | + |
| 178 | +- [GaussDB Connection Guide](docs/connection-guide.md) |
| 179 | +- [Authentication Methods](docs/authentication.md) |
| 180 | +- [Migration from rust-postgres](docs/migration.md) |
| 181 | +- [GaussDB vs PostgreSQL Differences](docs/GaussDB-PostgreSQL-差异分析报告.md) |
| 182 | + |
| 183 | +## Contributing |
| 184 | + |
| 185 | +We welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines. |
| 186 | + |
| 187 | +### Development Setup |
| 188 | + |
| 189 | +1. Clone the repository: |
| 190 | + ```bash |
| 191 | + git clone https://github.com/HuaweiCloudDeveloper/gaussdb-rust.git |
| 192 | + cd gaussdb-rust |
| 193 | + ``` |
| 194 | + |
| 195 | +2. Install Rust (if not already installed): |
| 196 | + ```bash |
| 197 | + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh |
| 198 | + ``` |
| 199 | + |
| 200 | +3. Run tests: |
| 201 | + ```bash |
| 202 | + cargo test |
| 203 | + ``` |
| 204 | + |
| 205 | +## License |
| 206 | + |
| 207 | +This project is licensed under either of |
| 208 | + |
| 209 | +- Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) |
| 210 | +- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) |
| 211 | + |
| 212 | +at your option. |
| 213 | + |
| 214 | +## Acknowledgments |
| 215 | + |
| 216 | +This project is based on the excellent [rust-postgres](https://github.com/sfackler/rust-postgres) library by Steven Fackler. We extend our gratitude to the original authors and contributors. |
| 217 | + |
| 218 | +## Support |
| 219 | + |
| 220 | +- [GitHub Issues](https://github.com/HuaweiCloudDeveloper/gaussdb-rust/issues) - Bug reports and feature requests |
| 221 | +- [Documentation](https://docs.rs/gaussdb) - API documentation and guides |
| 222 | +- [Examples](examples/) - Code examples and tutorials |
0 commit comments