Skip to content

Commit 62f145e

Browse files
committed
doc: mention new sqlx.toml configuration
1 parent bdf8302 commit 62f145e

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

sqlx-core/src/config/macros.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use std::collections::BTreeMap;
22

33
/// Configuration for the `query!()` family of macros.
4+
///
5+
/// See also [`common::Config`][crate::config::common::Config] for renaming `DATABASE_URL`.
46
#[derive(Debug, Default)]
57
#[cfg_attr(
68
feature = "sqlx-toml",

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ pub mod prelude {
175175
}
176176

177177
#[cfg(feature = "_unstable-doc")]
178-
pub use sqlx_core::config;
178+
#[cfg_attr(docsrs, doc(cfg(feature = "_unstable-doc")))]
179+
pub use sqlx_core::config as _config;
179180

180181
// NOTE: APIs exported in this module are SemVer-exempt.
181182
#[doc(hidden)]

src/macros/mod.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,25 @@
7474
///
7575
/// [dotenv]: https://crates.io/crates/dotenv
7676
/// [dotenvy]: https://crates.io/crates/dotenvy
77+
///
78+
/// ## Configuration with `sqlx.toml`
79+
/// Multiple crate-wide configuration options are now available, including:
80+
///
81+
/// * change the name of the `DATABASE_URL` variable for using multiple databases in the same workspace
82+
/// * In the initial implementation, a separate crate must be created for each database.
83+
/// Using multiple databases in the same crate may become possible in the future.
84+
/// * global type overrides (useful for custom types!)
85+
/// * per-column type overrides
86+
/// * force use of a specific crate (e.g. `chrono` when both it and `time` are enabled)
87+
///
88+
/// See the [configuration guide] and [reference `sqlx.toml`] for details.
89+
///
90+
/// See also `examples/postgres/multi-database` and `examples/postgres/preferred-crates`
91+
/// for example usage.
92+
///
93+
/// [configuration guide]: crate::_config::macros::Config
94+
/// [reference `sqlx.toml`]: crate::_config::_reference
95+
///
7796
/// ## Query Arguments
7897
/// Like `println!()` and the other formatting macros, you can add bind parameters to your SQL
7998
/// and this macro will typecheck passed arguments and error on missing ones:
@@ -728,6 +747,7 @@ macro_rules! query_file_scalar_unchecked (
728747
/// Embeds migrations into the binary by expanding to a static instance of [Migrator][crate::migrate::Migrator].
729748
///
730749
/// ```rust,ignore
750+
/// // Consider instead setting
731751
/// sqlx::migrate!("db/migrations")
732752
/// .run(&pool)
733753
/// .await?;
@@ -745,6 +765,38 @@ macro_rules! query_file_scalar_unchecked (
745765
///
746766
/// See [MigrationSource][crate::migrate::MigrationSource] for details on structure of the ./migrations directory.
747767
///
768+
/// ## Note: Platform-specific Line Endings
769+
/// Different platforms use different bytes for line endings by default:
770+
/// * Linux and MacOS use Line Feeds (LF:`\n`)
771+
/// * Windows uses Carriage Returns _and_ Line Feeds (CRLF:'\r\n')
772+
///
773+
/// This may result in un-reproducible hashes across platforms unless taken into account.
774+
///
775+
/// One solution is to use a [`.gitattributes` file](https://git-scm.com/docs/gitattributes)
776+
/// and force `.sql` files to be checked out with Line Feeds:
777+
///
778+
/// ```gitattributes
779+
/// *.sql text eol=lf
780+
/// ```
781+
///
782+
/// Another option is to configure migrations to ignore whitespace.
783+
/// See the next section for details.
784+
///
785+
/// ## Configuration with `sqlx.toml`
786+
/// Multiple crate-wide configuration options are now available, including:
787+
///
788+
/// * creating schemas on database setup
789+
/// * renaming the `_sqlx_migrations` table or placing it into a new schema
790+
/// * relocating the migrations directory
791+
/// * ignoring characters for hashing (such as whitespace and newlines)
792+
///
793+
/// See the [configuration guide] and [reference `sqlx.toml`] for details.
794+
///
795+
/// `sqlx-cli` can also read these options and use them when setting up or migrating databases.
796+
///
797+
/// [configuration guide]: crate::_config::migrate::Config
798+
/// [reference `sqlx.toml`]: crate::_config::_reference
799+
///
748800
/// ## Triggering Recompilation on Migration Changes
749801
/// In some cases when making changes to embedded migrations, such as adding a new migration without
750802
/// changing any Rust source files, you might find that `cargo build` doesn't actually do anything,

0 commit comments

Comments
 (0)