1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
//! # Bottle ORM
//!
//! **Bottle ORM** is a lightweight, async ORM for Rust built on top of [sqlx](https://github.com/launchbadge/sqlx).
//! It is designed to be simple, efficient, and easy to use, providing a fluent Query Builder
//! and automatic schema migrations.
//!
//! ## Features
//!
//! - **Async & Non-blocking**: Built on `tokio` and `sqlx`
//! - **Multi-Driver Support**: Compatible with PostgreSQL, MySQL, and SQLite (via `sqlx::Any`)
//! - **Macro-based Models**: Define your schema using standard Rust structs with `#[derive(Model)]`
//! - **Fluent Query Builder**: Chainable methods for filtering, selecting, pagination, and sorting
//! - **Auto-Migration**: Automatically creates tables and foreign key constraints based on your structs
//! - **UUID Support**: Full support for UUID versions 1 through 7
//!
//! ## Quick Start Example
//!
//! ```rust,ignore
//! use bottle_orm::{Database, Model};
//! use serde::{Deserialize, Serialize};
//! use sqlx::FromRow;
//!
//! #[derive(Model, Debug, Clone, Serialize, Deserialize, FromRow)]
//! struct User {
//! #[orm(primary_key)]
//! id: i32,
//! #[orm(size = 50, unique)]
//! username: String,
//! age: i32,
//! }
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let db = Database::connect("sqlite::memory:").await?;
//!
//! db.migrator()
//! .register::<User>()
//! .run()
//! .await?;
//!
//! let users: Vec<User> = db.model::<User>()
//! .filter("age", ">=", 18)
//! .scan()
//! .await?;
//!
//! Ok(())
//! }
//! ```
// ============================================================================
// Macro Re-exports
// ============================================================================
/// Re-export of the procedural macro for deriving the `Model` trait.
///
/// This macro is defined in the `bottle-orm-macro` crate and allows automatic
/// implementation of the `Model` trait for structs representing database tables.
pub use Model;
/// Re-export of the procedural macro for deriving `Display` and `FromStr` for enums.
pub use BottleEnum;
/// Re-export of the procedural macro for deriving `FromRow` for `AnyRow` and `AnyImpl`.
///
/// This macro facilitates scanning arbitrary query results (via `AnyRow`) into
/// Rust structs, handling necessary type conversions (especially for temporal types).
pub use FromAnyRow;
// ============================================================================
// Module Declarations
// ============================================================================
/// 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.
/// Core Model trait and column metadata structures.
///
/// Defines the `Model` trait that must be implemented by all ORM entities,
/// and the `ColumnInfo` struct containing metadata about table columns.
/// Support for mapping arbitrary `AnyRow` results to structs.
///
/// Defines traits and structures (`AnyImpl`, `AnyInfo`) that support the `FromAnyRow`
/// derive macro, enabling flexible result mapping.
/// Fluent query builder for constructing SQL queries.
///
/// Provides the `QueryBuilder` struct with chainable methods for building
/// SELECT, INSERT, and filtered queries with type-safe parameter binding.
/// Schema migration management.
///
/// Contains the `Migrator` struct for registering models and executing
/// automatic table creation and foreign key assignment.
/// Error types and handling.
///
/// Defines the `Error` enum with variants for different error scenarios
/// that can occur during ORM operations.
/// Temporal type conversion and handling.
///
/// Provides specialized conversion functions for chrono types (DateTime, NaiveDateTime, etc.)
/// across different database drivers, optimizing for native database type support.
/// Value binding utilities for SQL queries.
///
/// Provides type-safe value binding with automatic type detection and conversion,
/// supporting all SQL types across different database drivers.
/// Pagination utilities for web framework integration.
///
/// Provides the `Pagination` struct which implements `Serialize`/`Deserialize`
/// for easy extraction from query parameters in frameworks like Axum or Actix-web.
// ============================================================================
// Public API Re-exports
// ============================================================================
/// Re-export of the `Database` struct for connection management.
///
/// This is the main entry point for establishing database connections
/// and creating query builders or migrators.
pub use ;
/// Re-export of the `Model` trait and `ColumnInfo` struct.
///
/// The `Model` trait defines the interface for ORM entities, while
/// `ColumnInfo` contains metadata about individual table columns.
pub use ;
/// Re-export of `AnyImpl` and `AnyInfo` for dynamic row mapping.
///
/// `AnyImpl` is the trait implemented by structs that can be scanned from `AnyRow`,
/// providing necessary column metadata via `AnyInfo`.
pub use ;
pub use Transaction;
/// Re-export of the `QueryBuilder` for constructing and executing queries.
///
/// `QueryBuilder` provides a fluent interface for building SELECT and INSERT
/// queries with filtering, ordering, and pagination capabilities.
pub use ;
/// Re-export of the `Migrator` for schema migration management.
///
/// `Migrator` handles the registration of models and execution of
/// migration tasks to create tables and establish relationships.
pub use Migrator;
/// Re-export of the `Error` type for error handling.
///
/// This is the main error type used throughout Bottle ORM, wrapping
/// various error scenarios including database errors and validation errors.
pub use Error;
/// Re-export of `Pagination` struct.
pub use Pagination;