Skip to content

feat(sqlx.toml): support SQLite extensions in macros and sqlx-cli #3917

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 78 commits into from
Jul 8, 2025

Conversation

djarb
Copy link
Contributor

@djarb djarb commented Jul 1, 2025

Does your PR solve an issue?

fixes #3330

Is this a breaking change?

This is not a breaking change. All new behaviors are toggled by the presence of a field in the sqlx.toml file which did not previously exist.

abonander and others added 30 commits July 1, 2025 02:58
simplifies usage while still making parsing optional for less generated code
Doc formatting tweak

Co-authored-by: Josh McKinney <joshka@users.noreply.github.com>
simplifies usage while still making parsing optional for less generated code
@djarb djarb changed the title Use sqlx.toml to load extensions while running compile-time checking macros and CLI migrations against SQLite databases Use sqlx.toml to load extensions when running compile-time checking macros and CLI migrations against SQLite databases Jul 1, 2025
Copy link
Collaborator

@abonander abonander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also concerned about the proliferation of the sqlx-toml feature.

The Config type is still defined without it, the parsing is just short-circuited to do nothing. It shouldn't be necessary to cfg a ton of stuff out on it.

@djarb
Copy link
Contributor Author

djarb commented Jul 2, 2025

Also concerned about the proliferation of the sqlx-toml feature.

The Config type is still defined without it, the parsing is just short-circuited to do nothing. It shouldn't be necessary to cfg a ton of stuff out on it.

No problem, I'll pull out most of the conditional compilation. I was just trying to respect the feature flag.

@etodanik
Copy link

etodanik commented Jul 2, 2025

This is incredibly useful! Stuck on exactly this feature missing. Thanks @djarb ❤️

@djarb djarb requested a review from abonander July 2, 2025 18:40
@djarb djarb requested a review from abonander July 5, 2025 16:56
Comment on lines +192 to +209
retry_connect_errors(opts, move |url| {
// This only handles the default case. For good support of
// the new command line options, we need to work out some
// way to make the appropriate ConfigOpt available here. I
// suspect that that infrastructure would be useful for
// other things in the future, as well, but it also seems
// like an extensive and intrusive change.
//
// On the other hand, the compile-time checking macros
// can't be configured to use a different config file at
// all, so I believe this is okay for the time being.
let config = Some(std::path::PathBuf::from("sqlx.toml")).and_then(|p| {
if p.exists() {
Some(p)
} else {
None
}
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've got a better idea of how to do this but it's a nontrivial change so I'm going to go ahead and merge. Just know that this might look a bit different in the final release.

@abonander abonander changed the title Use sqlx.toml to load extensions when running compile-time checking macros and CLI migrations against SQLite databases feat(sqlx.toml): support SQLite extensions in macros and sqlx-cli Jul 8, 2025
@abonander abonander merged commit f7ef1ed into launchbadge:main Jul 8, 2025
84 checks passed
kriswuollett pushed a commit to kriswuollett/sqlx that referenced this pull request Jul 8, 2025
…unchbadge#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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow using sqlite extensions during comptime verification
3 participants