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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
//! # Reinhardt Database
//!
//! Django-style database layer for Reinhardt framework.
//!
//! This crate provides a unified database abstraction that combines:
//! - **Database Backends**: Low-level database operations
//! - **Connection Pooling**: Advanced connection pool management
//! - **ORM**: Django-style ORM for database queries
//! - **Migrations**: Database schema migration system
//! - **Hybrid Types**: Common database type abstractions
//! - **Associations**: Relationship management between models
//!
//! Equivalent to Django's `django.db` package.
//!
//! ## Features
//!
//! ### Database Backends (`backends` module)
//!
//! - **Schema Editor Abstraction**: Unified `BaseDatabaseSchemaEditor` trait
//! - **Database-Specific Implementations**: PostgreSQL, MySQL, SQLite support
//! - **DDL Operations**: CREATE TABLE, ALTER TABLE, CREATE INDEX, etc.
//! - **Query Builder**: Type-safe query construction
//!
//! ### Connection Pooling (`pool` module)
//!
//! - **Advanced Pooling**: SQLAlchemy-inspired connection pool management
//! - **Dependency Injection**: Integration with Reinhardt DI system
//! - **Event Listeners**: Connection lifecycle hooks
//! - **Pool Configuration**: Fine-grained control over pool behavior
//!
//! ### ORM (`orm` module)
//!
//! - **Django-style Models**: Define database models with structs
//! - **QuerySet API**: Chainable query builder
//! - **Field Types**: Rich set of field types with validation
//! - **Relationships**: ForeignKey, ManyToMany, OneToOne
//!
//! ### Migrations (`migrations` module)
//!
//! - **Schema Migrations**: Track and apply database schema changes
//! - **Auto-detection**: Automatically detect model changes
//! - **Migration Files**: Generate migration files from model changes
//! - **Rollback Support**: Reverse migrations when needed
//! - **MigrationStateLoader**: Django-style approach for building `ProjectState`
//! - Replays applied migrations to reconstruct schema state
//! - Enables accurate change detection without database introspection
//! - Used internally by `makemigrations` command
//! - **Composite Primary Key Detection**: Autodetector emits `CreateCompositePrimaryKey`
//! when a model adds a `primary_key` constraint covering 2+ columns
//! - **Sequence Reset Detection**: Autodetector emits `SetAutoIncrementValue`
//! when a model adds or changes the `sequence_reset` option
//!
//! ## Available Database Backends
//!
//! The backends crate provides multiple database backend implementations:
//! - **PostgreSQL**: Full support with connection pooling
//! - **MySQL**: Full support with connection pooling
//! - **SQLite**: Full support with connection pooling
//! - **CockroachDB**: Distributed transaction support
//!
//! ## Optimization Features ✅
//!
//! - **Connection Pool Optimization**: Idle timeout, dynamic sizing, health checks
//! - **Query Caching**: LRU cache with TTL for prepared statements and results
//! - **Batch Operations**: Efficient bulk insert, update, and delete operations
//!
//! ## Enhanced Migration Tools ✅
//!
//! - **Schema Diff Detection**: Automatic detection of schema changes between DB and models
//! - **Auto-Migration Generation**: Generate migration files from detected differences
//! - **Migration Validation**: Pre-execution validation with data loss warnings
//! - **Rollback Script Generation**: Automatic rollback operations for safe migrations
//!
//! ## Quick Start
//!
//! ### Using Schema Editor
//!
//! ```rust,no_run
//! # use sqlx::PgPool;
//! use reinhardt_db::backends::schema::factory::{SchemaEditorFactory, DatabaseType};
//! use reinhardt_query::prelude::{PostgresQueryBuilder, QueryStatementBuilder};
//!
//! # async fn example() -> Result<(), sqlx::Error> {
//! # let pool = PgPool::connect("postgresql://localhost/mydb").await?;
//! let factory = SchemaEditorFactory::new_postgres(pool);
//! let editor = factory.create_for_database(DatabaseType::PostgreSQL);
//!
//! let stmt = editor.create_table_statement("users", &[
//! ("id", "INTEGER PRIMARY KEY"),
//! ("name", "VARCHAR(100)"),
//! ]);
//! let sql = stmt.to_string(PostgresQueryBuilder);
//! # Ok(())
//! # }
//! ```
//!
//! ### Using Connection Pool
//!
//! ```rust,no_run
//! use reinhardt_db::pool::{ConnectionPool, PoolConfig};
//!
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! let pool = ConnectionPool::new_postgres("postgres://localhost/mydb", PoolConfig::default()).await?;
//! let conn = pool.acquire().await?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Architecture
//!
//! Key modules in this crate:
//!
//! - [`backends`]: Low-level database operations, schema editor, DDL generation
//! - [`backends_pool`]: Connection pool management with lifecycle hooks
//! - [`pool`]: High-level pool abstraction for `ConnectionPool`
//! - [`orm`]: Django-style model definitions, QuerySet, and field types
//! - [`migrations`]: Schema migration system with auto-detection and rollback
//! - [`hybrid`]: Cross-database compatible type system
//! - [`associations`]: Relationship management (ForeignKey, ManyToMany)
//! - [`contenttypes`]: Generic foreign key support
//!
//! ## Feature Flags
//!
//! | Feature | Default | Description |
//! |---------|---------|-------------|
//! | `backends` | enabled | Database backend abstractions and schema editor |
//! | `pool` | enabled | Connection pooling support |
//! | `orm` | enabled | ORM model definitions and QuerySet API |
//! | `migrations` | enabled | Database migration system |
//! | `hybrid` | enabled | Cross-database hybrid type system |
//! | `associations` | enabled | Model relationship management |
//! | `postgres` | enabled | PostgreSQL backend |
//! | `sqlite` | disabled | SQLite backend |
//! | `mysql` | disabled | MySQL backend |
//! | `all-databases` | disabled | Enable all database backends |
//! | `backends-pool` | disabled | Connection pool backend abstractions |
//! | `contenttypes` | disabled | Generic foreign key support |
//! | `nosql` | disabled | NoSQL/BSON type support |
//! | `di` | disabled | Dependency injection integration |
//! | `database-full` | disabled | Enable all database features |
/// Prelude module for convenient imports
///
/// Imports commonly used types from all modules.
// Re-export top-level commonly used types
pub use ;
// Re-export ORM's DatabaseConnection which wraps BackendsConnection
// This is the type used by Manager and other ORM components
pub use DatabaseConnection;
pub use ;