Skip to content

Commit b049521

Browse files
authored
Merge pull request #1 from louloulin/feature-gaussdb
Feature gaussdb
2 parents e1cd6be + c1d5602 commit b049521

File tree

185 files changed

+5081
-673
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

185 files changed

+5081
-673
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ Cargo.lock
44
.idea
55
*.iml
66
.vscode
7+
plan/
8+
scripts/

Cargo.toml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
[workspace]
22
members = [
33
"codegen",
4-
"postgres",
5-
"postgres-derive",
6-
"postgres-derive-test",
7-
"postgres-native-tls",
8-
"postgres-openssl",
9-
"postgres-protocol",
10-
"postgres-types",
11-
"tokio-postgres",
4+
"gaussdb",
5+
"gaussdb-derive",
6+
"gaussdb-derive-test",
7+
"gaussdb-native-tls",
8+
"gaussdb-openssl",
9+
"gaussdb-protocol",
10+
"gaussdb-types",
11+
"tokio-gaussdb",
12+
"examples",
1213
]
1314
resolver = "2"
1415

README.md

Lines changed: 203 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,222 @@
1-
# Rust-Postgres
1+
# GaussDB-Rust
22

3-
PostgreSQL support for Rust.
3+
GaussDB and OpenGauss support for Rust.
44

5-
## postgres [![Latest Version](https://img.shields.io/crates/v/postgres.svg)](https://crates.io/crates/postgres)
5+
## gaussdb [![Latest Version](https://img.shields.io/crates/v/gaussdb.svg)](https://crates.io/crates/gaussdb)
66

7-
[Documentation](https://docs.rs/postgres)
7+
[Documentation](https://docs.rs/gaussdb)
88

9-
A native, synchronous PostgreSQL client.
9+
A native, synchronous GaussDB client with full PostgreSQL compatibility.
1010

11-
## tokio-postgres [![Latest Version](https://img.shields.io/crates/v/tokio-postgres.svg)](https://crates.io/crates/tokio-postgres)
11+
## tokio-gaussdb [![Latest Version](https://img.shields.io/crates/v/tokio-gaussdb.svg)](https://crates.io/crates/tokio-gaussdb)
1212

13-
[Documentation](https://docs.rs/tokio-postgres)
13+
[Documentation](https://docs.rs/tokio-gaussdb)
1414

15-
A native, asynchronous PostgreSQL client.
15+
A native, asynchronous GaussDB client with full PostgreSQL compatibility.
1616

17-
## postgres-types [![Latest Version](https://img.shields.io/crates/v/postgres-types.svg)](https://crates.io/crates/postgres-types)
17+
## gaussdb-types [![Latest Version](https://img.shields.io/crates/v/gaussdb-types.svg)](https://crates.io/crates/gaussdb-types)
1818

19-
[Documentation](https://docs.rs/postgres-types)
19+
[Documentation](https://docs.rs/gaussdb-types)
2020

21-
Conversions between Rust and Postgres types.
21+
Conversions between Rust and GaussDB/PostgreSQL types.
2222

23-
## postgres-native-tls [![Latest Version](https://img.shields.io/crates/v/postgres-native-tls.svg)](https://crates.io/crates/postgres-native-tls)
23+
## gaussdb-native-tls [![Latest Version](https://img.shields.io/crates/v/gaussdb-native-tls.svg)](https://crates.io/crates/gaussdb-native-tls)
2424

25-
[Documentation](https://docs.rs/postgres-native-tls)
25+
[Documentation](https://docs.rs/gaussdb-native-tls)
2626

27-
TLS support for postgres and tokio-postgres via native-tls.
27+
TLS support for gaussdb and tokio-gaussdb via native-tls.
2828

29-
## postgres-openssl [![Latest Version](https://img.shields.io/crates/v/postgres-openssl.svg)](https://crates.io/crates/postgres-openssl)
29+
## gaussdb-openssl [![Latest Version](https://img.shields.io/crates/v/gaussdb-openssl.svg)](https://crates.io/crates/gaussdb-openssl)
3030

31-
[Documentation](https://docs.rs/postgres-openssl)
31+
[Documentation](https://docs.rs/gaussdb-openssl)
3232

33-
TLS support for postgres and tokio-postgres via openssl.
33+
TLS support for gaussdb and tokio-gaussdb via openssl.
3434

35-
# Running test suite
35+
# Features
3636

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
3838

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

codegen/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
name = "codegen"
33
version = "0.1.0"
44
authors = ["Steven Fackler <[email protected]>"]
5+
edition = "2021"
56

67
[dependencies]
78
phf_codegen = "0.11"

docker-compose-opengauss.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
version: '3.8'
2+
3+
services:
4+
opengauss:
5+
image: opengauss/opengauss-server:latest
6+
container_name: opengauss-test
7+
privileged: true
8+
restart: unless-stopped
9+
ports:
10+
- "5433:5432" # 映射到5433端口,与现有PostgreSQL测试保持一致
11+
environment:
12+
- GS_PASSWORD=Gaussdb@123 # OpenGauss密码:大写字母+小写字母+数字+特殊字符,长度>=8
13+
- GS_NODENAME=opengauss
14+
- GS_USERNAME=gaussdb # 自定义用户名
15+
16+
#volumes:
17+
#- opengauss_data:/var/lib/opengauss/data
18+
#- ./docker/opengauss_setup.sh:/docker-entrypoint-initdb.d/opengauss_setup.sh
19+
networks:
20+
- gaussdb_network
21+
healthcheck:
22+
test: ["CMD-SHELL", "gsql -d postgres -U gaussdb -c 'SELECT 1;' || exit 1"]
23+
interval: 30s
24+
timeout: 10s
25+
retries: 5
26+
start_period: 60s
27+
28+
networks:
29+
gaussdb_network:
30+
driver: bridge

0 commit comments

Comments
 (0)