Module database

Module database 

Source
Expand description

Database connection and driver management.

Contains the Database struct for connection pooling and driver detection, as well as the Drivers enum for identifying the database backend.

§Database Module

This module provides the core database connection and management functionality for Bottle ORM. It handles connection pooling, driver detection, table creation, and foreign key management across multiple database backends.

§Supported Database Drivers

  • PostgreSQL: Full support with advanced features like UUID, JSONB, arrays
  • MySQL: Complete support for standard MySQL/MariaDB features
  • SQLite: In-memory and file-based SQLite databases

§Features

  • Connection Pooling: Automatic connection pool management via sqlx
  • Driver Detection: Automatic database driver detection from connection URL
  • Schema Management: Table creation with indexes, constraints, and foreign keys
  • Type Safety: Type-safe operations across different database backends

§Example Usage

use bottle_orm::Database;

// Connect to PostgreSQL
let db = Database::connect("postgres://user:pass@localhost/mydb").await?;

// Connect to SQLite
let db = Database::connect("sqlite::memory:").await?;

// Connect to MySQL
let db = Database::connect("mysql://user:pass@localhost/mydb").await?;

// Create table for a model
db.create_table::<User>().await?;

// Assign foreign keys
db.assign_foreign_keys::<Post>().await?;

// Start building queries
let users = db.model::<User>().scan().await?;

Structs§

Database
The main entry point for database connection and management.
DatabaseBuilder
A builder for creating a Database connection with custom options.

Enums§

Drivers
Supported database driver types.

Traits§

Connection
A trait representing a database connection or transaction.