PG Connector 🐘
A high-performance, developer-friendly PostgreSQL connector for Rust. This crate provides a streamlined API for managing database connections with built-in pooling and dedicated support for read/write cluster split architectures.
Built on top of tokio-postgres and bb8, it ensures your application scales efficiently while keeping your code clean.
✨ Features
- 🏎️ High Performance: Asynchronous I/O powered by
tokioandtokio-postgres. - 🔋 Robust Pooling: Intelligent connection management using
bb8. - ⚖️ Read/Write Splitting: Native support for clusters with separate read and write endpoints.
- 🚰 Streamlined API: One unified trait (
SqlExpose) for all your SQL operations. - 🛠️ Transaction Support: Full async implementation for PostgreSQL transactions.
- 🛡️ Errors Made Easy: Specific, actionable error types for connection and pooling issues.
🚀 Installation
Add this to your Cargo.toml:
[]
= "1.0.0"
= { = "1.40", = ["full"] }
= "0.9" # Optional: if you need custom TLS or types
💡 Quick Start
use ;
use NoTls;
use QueueStrategy;
async
🛠️ Advanced Usage
Transactions
pg_connector makes transactions simple. The SqlExpose trait is also implemented for Transaction, allowing you to use the same methods inside a transaction block.
let mut conn = connector.get_write.await?;
let transaction = conn.transaction.await?;
// Use the same trait methods!
transaction.execute.await?;
transaction.execute.await?;
transaction.commit.await?;
Pre-prepared Statements
For repeated queries, use prepare or prepare_typed for maximum performance.
let stmt = connector.prepare.await?;
let results = connector.query.await?;
📄 License
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.
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
📝 Changelog
v1.0.1 (2026-03-22)
Add feature
- Add feature to get detailed error information from Postgres.