mirror of
https://github.com/launchbadge/sqlx.git
synced 2026-03-23 10:38:57 +00:00
feat(sqlx.toml): support SQLite extensions in macros and sqlx-cli (#3917)
* feat: create `sqlx.toml` format * feat: add support for ignored_chars config to sqlx_core::migrate * chore: test ignored_chars with `U+FEFF` (ZWNBSP/BOM) https://en.wikipedia.org/wiki/Byte_order_mark * refactor: make `Config` always compiled simplifies usage while still making parsing optional for less generated code * refactor: add origin information to `Column` * feat(macros): implement `type_override` and `column_override` from `sqlx.toml` * refactor(sqlx.toml): make all keys kebab-case, create `macros.preferred-crates` * feat: make macros aware of `macros.preferred-crates` * feat: make `sqlx-cli` aware of `database-url-var` * feat: teach macros about `migrate.table-name`, `migrations-dir` * feat: teach macros about `migrate.ignored-chars` * feat: teach `sqlx-cli` about `migrate.defaults` * feat: teach `sqlx-cli` about `migrate.migrations-dir` * feat: teach `sqlx-cli` about `migrate.table-name` * feat: introduce `migrate.create-schemas` * WIP feat: create multi-tenant database example * SQLite extension loading via sqlx.toml for CLI and query macros * fix: allow start_database to function when the SQLite database file does not already exist * Added example demonstrating migration and compile-time checking with SQLite extensions * remove accidentally included db file * Update sqlx-core/src/config/common.rs Doc formatting tweak Co-authored-by: Josh McKinney <joshka@users.noreply.github.com> * feat: create `sqlx.toml` format * feat: add support for ignored_chars config to sqlx_core::migrate * chore: test ignored_chars with `U+FEFF` (ZWNBSP/BOM) https://en.wikipedia.org/wiki/Byte_order_mark * refactor: make `Config` always compiled simplifies usage while still making parsing optional for less generated code * refactor: add origin information to `Column` * feat(macros): implement `type_override` and `column_override` from `sqlx.toml` * refactor(sqlx.toml): make all keys kebab-case, create `macros.preferred-crates` * feat: make macros aware of `macros.preferred-crates` * feat: make `sqlx-cli` aware of `database-url-var` * feat: teach macros about `migrate.table-name`, `migrations-dir` * feat: teach macros about `migrate.ignored-chars` * feat: teach `sqlx-cli` about `migrate.defaults` * feat: teach `sqlx-cli` about `migrate.migrations-dir` * feat: teach `sqlx-cli` about `migrate.table-name` * feat: introduce `migrate.create-schemas` * fix(postgres): don't fetch `ColumnOrigin` for transparently-prepared statements * feat: progress on axum-multi-tenant example * feat(config): better errors for mislabeled fields * WIP feat: filling out axum-multi-tenant example * feat: multi-tenant example No longer Axum-based because filling out the request routes would have distracted from the purpose of the example. * chore(ci): test multi-tenant example * fixup after merge * fix: CI, README for `multi-tenant` * fix: clippy warnings * fix: multi-tenant README * fix: sequential versioning inference for migrations * fix: migration versioning with explicit overrides * fix: only warn on ambiguous crates if the invocation relies on it * fix: remove unused imports * fix: `sqlx mig add` behavior and tests * fix: restore original type-checking order * fix: deprecation warning in `tests/postgres/macros.rs` * feat: create postgres/multi-database example * fix: examples/postgres/multi-database * fix: cargo fmt * chore: add tests for config `migrate.defaults` * fix: sqlx-cli/tests/add.rs * feat(cli): add `--config` override to all relevant commands * chore: run `sqlx mig add` test with `RUST_BACKTRACE=1` * fix: properly canonicalize config path for `sqlx mig add` test * fix: get `sqlx mig add` test passing * fix(cli): test `migrate.ignored-chars`, fix bugs * feat: create `macros.preferred-crates` example * fix(examples): use workspace `sqlx` * fix: examples * fix: run `cargo fmt` * fix: more example fixes * fix(ci): preferred-crates setup * fix: axum-multi-tenant example locked to specific sqlx version * import anyhow::Context trait in sqlx-cli/src/lib.rs since it was being used and causing a compile error * rebased on upstream/main * make cargo fmt happy * make clippy happy * make clippy happier still * fix: improved error reporting, added parsing test, removed sqlx-toml flag use * switched to kebab-case for the config key * switched to kebab-case for the config key --------- Co-authored-by: Austin Bonander <austin.bonander@gmail.com> Co-authored-by: Josh McKinney <joshka@users.noreply.github.com>
This commit is contained in:
@@ -27,6 +27,8 @@ preupdate-hook = ["libsqlite3-sys/preupdate_hook"]
|
||||
bundled = ["libsqlite3-sys/bundled"]
|
||||
unbundled = ["libsqlite3-sys/buildtime_bindgen"]
|
||||
|
||||
sqlx-toml = ["sqlx-core/sqlx-toml"]
|
||||
|
||||
# Note: currently unused, only to satisfy "unexpected `cfg` condition" lint
|
||||
bigdecimal = []
|
||||
rust_decimal = []
|
||||
|
||||
@@ -198,6 +198,23 @@ impl<'a> TryFrom<&'a AnyConnectOptions> for SqliteConnectOptions {
|
||||
fn try_from(opts: &'a AnyConnectOptions) -> Result<Self, Self::Error> {
|
||||
let mut opts_out = SqliteConnectOptions::from_url(&opts.database_url)?;
|
||||
opts_out.log_settings = opts.log_settings.clone();
|
||||
|
||||
if let Some(ref path) = opts.enable_config {
|
||||
if path.exists() {
|
||||
let config = match sqlx_core::config::Config::try_from_path(path.to_path_buf()) {
|
||||
Ok(cfg) => cfg,
|
||||
Err(sqlx_core::config::ConfigError::NotFound { path: _ }) => {
|
||||
return Ok(opts_out)
|
||||
}
|
||||
Err(err) => return Err(Self::Error::ConfigFile(err)),
|
||||
};
|
||||
|
||||
for extension in config.common.drivers.sqlite.load_extensions.iter() {
|
||||
opts_out = opts_out.extension(extension.to_owned());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(opts_out)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,7 +128,18 @@ pub static CREATE_DB_WAL: AtomicBool = AtomicBool::new(true);
|
||||
/// UNSTABLE: for use by `sqlite-macros-core` only.
|
||||
#[doc(hidden)]
|
||||
pub fn describe_blocking(query: &str, database_url: &str) -> Result<Describe<Sqlite>, Error> {
|
||||
let opts: SqliteConnectOptions = database_url.parse()?;
|
||||
let mut opts: SqliteConnectOptions = database_url.parse()?;
|
||||
|
||||
match sqlx_core::config::Config::try_from_crate_or_default() {
|
||||
Ok(config) => {
|
||||
for extension in config.common.drivers.sqlite.load_extensions.iter() {
|
||||
opts = opts.extension(extension.to_owned());
|
||||
}
|
||||
}
|
||||
Err(sqlx_core::config::ConfigError::NotFound { path: _ }) => {}
|
||||
Err(err) => return Err(Error::ConfigFile(err)),
|
||||
}
|
||||
|
||||
let params = EstablishParams::from_options(&opts)?;
|
||||
let mut conn = params.establish()?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user