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
//! Database connections, raw SQL, and transactions.
//!
//! Most handlers read or write a few rows. This module runs that SQL on the connections your
//! database configuration defines. [`query!`] binds the Rust values it captures as query parameters,
//! [`table`] starts a [query builder](Builder), and [`transaction`] runs writes that must succeed or
//! fail together. Each connection opens its pool on the first query, and a connection with read
//! replicas sends reads to them. To learn how to configure connections and write common queries,
//! check out the [database guide](https://github.com/laravel/rust-framework/blob/0.x/docs/database.md).
//!
//! ```no_run
//! # async fn example() -> laravel::Result<()> {
//! use laravel::db;
//!
//! let active = true;
//! let users = db::query!("SELECT id, name FROM users WHERE active = {active}")
//! .select()
//! .await?;
//!
//! for user in users {
//! let name: String = user.try_get("name")?;
//! }
//!
//! db::transaction(async |tx| {
//! db::query!(tx, "UPDATE accounts SET balance = balance - 25 WHERE id = 1").update().await?;
//! db::query!(tx, "UPDATE accounts SET balance = balance + 25 WHERE id = 2").update().await?;
//!
//! Ok(())
//! })
//! .await?;
//! # Ok(()) }
//! ```
//!
//! [`default_connection`] and [`connection`] return an [`AnyConnection`], which works with every
//! enabled driver. [`connection_for`] returns a [`Connection`] for one `SQLx` backend, for code that
//! needs the native driver.
pub use *;
pub use ;
pub use ;
/// A struct whose fields are columns of a model's table, re-exported here beside its derive.
pub use Embed;
/// Compile a directory of migrations into the binary, returning [`Migrations`].
///
/// The path is relative to the crate's `Cargo.toml`. Each `.rs` file in the directory, but not in
/// its subdirectories, is a migration named after the file, such as
/// `2026_10_27_143000_create_posts_table`. Migrations run in name order.
///
/// A migration has one public `migrate` function. Migrations only run forward, so a file that
/// defines `up` or `down` is a compile error. To change or undo a migration that has run, add a new
/// one. `migrate` takes one parameter, which decides how it runs:
///
/// - `&mut AnyTransaction<'_>` runs it in a transaction, which also records it in the
/// `migrations` table. If it fails, neither its changes nor the record are kept. On MySQL, a DDL
/// statement commits everything before it and ends the transaction, so changes up to the failure
/// can stay.
/// - `&AnyConnection` runs it without a transaction, for statements that can't run in one, such as
/// PostgreSQL's `CREATE INDEX CONCURRENTLY`. The record is written once it succeeds.
///
/// ```ignore
/// // database/migrations/2026_10_27_143000_create_posts_table.rs
/// use laravel::db::AnyTransaction;
///
/// pub async fn migrate(tx: &mut AnyTransaction<'_>) -> laravel::Result<()> {
/// tx.query("CREATE TABLE posts (id BIGSERIAL PRIMARY KEY, title TEXT NOT NULL)").statement().await?;
///
/// Ok(())
/// }
/// ```
///
/// A migration may instead define `migrate` with a macro, such as one that creates the tables a
/// framework driver uses. Its `migrate` runs in a transaction:
///
/// ```ignore
/// // database/migrations/0001_01_01_000001_create_cache_table.rs
/// laravel::cache::tables!();
/// ```
///
/// Editing a migration rebuilds the crate. Adding or removing one doesn't, because Cargo can't
/// watch a directory for a macro. Have the crate's `build.rs` print
/// `cargo::rerun-if-changed=database/migrations`, as the
/// [migrations guide](https://github.com/laravel/rust-framework/blob/0.x/docs/migrations.md#rebuilding-after-adding-a-migration)
/// shows.
pub use migrations;
/// Compile a directory's schema dumps into the binary, returning [`SchemaDumps`].
///
/// The path is relative to the crate's `Cargo.toml`. The macro embeds each
/// `<connection>-schema.sql` and `<connection>-schema.dump` file in the directory, which
/// `schema:dump` writes, under its connection's name. When a connection has both, the `.dump`
/// file wins. A missing or empty directory embeds no dumps. Register the dumps with
/// [`ApplicationBuilder::with_schema`](crate::foundation::ApplicationBuilder::with_schema):
///
/// ```ignore
/// laravel::Application::configure()
/// .with_migrations(laravel::db::migrations!("database/migrations"))
/// .with_schema(laravel::db::schema!("database/schema"));
/// ```
///
/// Changing a dump rebuilds the crate. Adding the first one doesn't, so have the crate's
/// `build.rs` print `cargo::rerun-if-changed=database/schema`, as the
/// [migrations guide](https://github.com/laravel/rust-framework/blob/0.x/docs/migrations.md#squashing-migrations)
/// shows.
pub use schema;
pub use register as register_commands;
pub use DatabaseServiceProvider;
pub use register as register_seed_command;