1 unstable release
| 0.1.0 | Sep 21, 2025 |
|---|
#2284 in Database interfaces
147 downloads per month
Used in burncloud-database-client
51KB
1K
SLoC
burncloud-database-impl
Database implementations for multiple backends (PostgreSQL, MySQL, SQLite, MongoDB) for the BurnCloud AI management system.
Overview
burncloud-database-impl provides concrete implementations of the traits defined in burncloud-database-core for multiple popular database backends. This allows you to use the same high-level API regardless of which database you choose.
Supported Databases
- PostgreSQL (default) - Full-featured with advanced JSON support
- MySQL - Popular relational database
- SQLite - Lightweight embedded database
- MongoDB - Document-oriented NoSQL database
Features
- Multi-database support: Choose the right database for your needs
- Feature flags: Only compile the database drivers you need
- Async support: All implementations are fully async
- Connection pooling: Built-in connection pool management
- Error handling: Unified error handling across all backends
- Type safety: Strong typing with compile-time guarantees
Installation
Add this to your Cargo.toml:
[dependencies]
burncloud-database-impl = "0.1"
Feature Flags
By default, only PostgreSQL support is included. Enable other databases with feature flags:
[dependencies]
burncloud-database-impl = { version = "0.1", features = ["mysql", "sqlite"] }
Available features:
postgres(default) - PostgreSQL support via sqlxmysql- MySQL support via mysql_asyncsqlite- SQLite support via rusqlitemongodb_support- MongoDB support via mongodb driverall- Enable all database backends
Usage Examples
PostgreSQL
use burncloud_database_impl::PostgresConnection;
use burncloud_database_core::{DatabaseConnection, QueryContext};
let mut conn = PostgresConnection::new("postgresql://user:pass@localhost/db".to_string());
conn.connect().await?;
let context = QueryContext::default();
conn.ping().await?;
SQLite
use burncloud_database_impl::SQLiteConnection;
let mut conn = SQLiteConnection::new("./database.db".to_string());
conn.connect().await?;
MySQL
use burncloud_database_impl::MySQLConnection;
let mut conn = MySQLConnection::new("mysql://user:pass@localhost/db".to_string());
conn.connect().await?;
MongoDB
use burncloud_database_impl::MongoDBConnection;
let mut conn = MongoDBConnection::new(
"mongodb://localhost:27017".to_string(),
"my_database".to_string()
);
conn.connect().await?;
Query Parameters
All implementations support type-safe query parameters:
use burncloud_database_impl::{StringParam, I64Param, BoolParam};
let params: Vec<&dyn QueryParam> = vec![
&StringParam("user_id".to_string()),
&I64Param(42),
&BoolParam(true),
];
Performance Considerations
- PostgreSQL: Best for complex queries and JSON operations
- MySQL: Good general-purpose choice with wide ecosystem support
- SQLite: Perfect for embedded applications and development
- MongoDB: Excellent for document-oriented data and flexible schemas
Architecture
Each database implementation provides:
- Connection management with automatic reconnection
- Query execution with parameter binding
- Transaction support (where applicable)
- Error handling with database-specific error mapping
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.
Dependencies
~4–22MB
~302K SLoC