On `PoolOptions::connect()`, we open at least `min_connections`
connections, or 1 if unset. Therefore, the expression needs to be
`max()`. (`min(1, x)` would mean we always open only a single
connection).
Inlined format args make code more readable, and code more compact.
I ran this clippy command to fix most cases, and then cleaned up a few trailing commas and uncaught edge cases.
```
cargo clippy --bins --examples --benches --tests --lib --workspace --fix -- -A clippy::all -W clippy::uninlined_format_args
```
* cli: add --target-version CLI flags for migrate run/revert
* cli: fix broken test
* cli: test harness for `sqlx migrate` along with --target-version tests
* cli: Fail if version supplied to run/revert is too old/new
After some discussion with my coworkers, we thought about the behavior a bit more:
The behavior is now that for a run, if the provided version is too old, the CLI
will return with failure rather than being a no-op. This gives feedback to the
operator instead of being quiet.
It is still valid to up/downgrade to the latest version, this will still be a no-op
to allow for idempotency.
* Support naming migrations sequentially and inferring naming scheme
* Document new options and how naming is inferred
* Only account for up migrations when inferring ordering
* Implement Clone for PoolOptions manually (#2548)
Trying to derive `Clone` automatically for `PoolOptions` results
in errors when `clone` is actually called. This is because the
derive incorrectly determines that `Clone` is _not_ derivable
due to the lack of `Clone` implementation on the `DB: Database`
type parameter, even though no value of that type is actually
stored in a to-be-cloned position (in fact, it's only used for
the `Connection` associated type on the type parameter's
`Database` trait impl).
Manually implementing `Clone` side-steps this issue and insures
the type is always actually cloneable.
For reference: https://github.com/launchbadge/sqlx/issues/2548
* Ran 'cargo fmt'
* Simplified Arc cloning
The documentation for `PgAdvisoryLockGuard` lists a set of types
that should be able to be passed to it, but when actually trying
to do so, compilation would fail due to missing `AsMut` trait
implementations for those types. This commit adds the missing
`AsMut` impls so that `Transaction` and `PgConnection` can be used
as type parameters to `PgAdvisoryLockGuard`, as expected.
For reference: https://github.com/launchbadge/sqlx/issues/2520
* Traverse symlinks when resolving migrations
When enumerating the source directory seeking migration files, `sqlx`
ignores entries that aren't files. This was previously reported as #614
and fixed in #985 but apparently regressed somewhere along the way. This
commit reintroduces the fix from #985 to the current implementation: use
`std::fs::metadata` instead of `std::fs::DirEntry::metadata`. The former
is documented to traverse symlinks; the latter does not.
* add migrations_symlink test
* use native-tls API
* Add client cert and key to MySQL connector
* Add client ssl tests for PostgreSQL
* Add client ssl tests for MariaDB and MySQL
* Adapt GA tests
* Fix RUSTFLAGS to run all tests
* Remove containers to free the DB port before running SSL auth tests
* Fix CI bad naming
* Use docker-compose down to remove also the network
* Fix main rebase
* Stop trying to stop service using docker-compose, simply use docker cmd
* Fix RUSTFLAGS for Postgres
* Name the Docker images for MariaDB and MySQL so we can stop them using their name
* Add the exception for mysql 5.7 not supporting compatible TLS version with RusTLS
* Rebase fixes
* Set correctly tls struct (fix merge)
* Handle Elliptic Curve variant for private key
* Fix tests suite
* Fix features in CI
* Add tests for Postgres 15 + rebase
* Python tests: fix exception for MySQL 5.7 + remove unneeded for loops
* CI: run SSL tests only when building with TLS support
---------
Co-authored-by: Barry Simons <linuxuser586@gmail.com>
* CHANGELOG: mention that users should upgrade CLI
* Added regexp support in sqlite
* Added a with_regexp function to sqliteconnectoptions
* Fixed tests
* Undo CHANGELOG.md change
---------
Co-authored-by: Austin Bonander <austin.bonander@gmail.com>
Co-authored-by: Victor Koenders <victor.koenders@qrtech.se>
* Add tracing dep
* Switch over basic events
* Switch over dynamically enabled events
* Fix missing SocketAddr formatting
* More format fixing
* refactor: Apply tracing changes to new crate structure
* feat: Add set_connect_options method to Pool
This allows external updates of the ConnectionOptions used when a new
connection needs to be opened for the pool. The primary use case
is to support dynamically updated (read: rotated) credentials used
by systems like AWS RDS.
* Use Arc wrapper for ConnectOptions to reduce lock contention
* sqlite fix
* Use direct assignment instead of mem::swap
Co-authored-by: Austin Bonander <austin.bonander@gmail.com>
Co-authored-by: Austin Bonander <austin.bonander@gmail.com>
* add failing test cases for update/delete return into
* fix regression in null tracking by improving tracking of cursor empty/full state
* add failing test case for order by column types
* Add support for SorterOpen,SorterInsert,SorterData
* add failing test case for unions
* fix range copy/move implementation
* fix wrong copy/move range
* remove calls to dbg!
* fix: ensure migration progress is not lost for PG
Fixes#1966.
* fix: ensure migration progress is not lost for sqlite
This is similar to #1966.
* fix: ensure reverse migration progress is not lost for PG
See #1966.
* fix: ensure reverse migration progress is not lost for sqlite
See #1966.
* fix: ensure migration progress is not lost for mysql
This is similar to #1966.
* fix: ensure reverse migration progress is not lost for mysql
See #1966.
* test: check migration type as well
* test: extend migrations testing
* fix: work around MySQL implicit commits
* refactor: simplify migration testing
This allows to free server resources earlier and run the same logic as simple Query does:
"The simple Query message is approximately equivalent to the series Parse, Bind, portal Describe, Execute, Close, Sync,"
* Add extension support for SQLite
While SQLite supports loading extensions at run-time via either the C
API or the SQL interface, they strongly recommend [1] only enabling the C
API so that SQL injections don't allow attackers to run arbitrary
extension code.
Here we take the most conservative approach, we enable only the C
function, and then only when the user requests extensions be loaded in
their `SqliteConnectOptions`, and disable it again once we're done
loading those requested modules. We don't add any support for loading
extensions via environment variables or connection strings.
Extensions in the options are stored as an IndexMap as the load order
can have side effects, they will be loaded in the order they are
supplied by the caller.
Extensions with custom entry points are supported, but a default API
is exposed as most users will interact with extensions using the
defaults.
[1]: https://sqlite.org/c3ref/enable_load_extension.html
* Add extension testing for SQlite
Extends x.py to download an appropriate shared object file for supported
operating systems, and uses wget to fetch one into the GitHub Actions
context for use by CI.
Overriding LD_LIBRARY_PATH for only this specific DB minimises the
impact on the rest of the suite.
@danielakhterov and I were playing around with counting lines using regex and noticed that SQLx had an odd number of ` ``` ` and got a little nerd-sniped trying to find it.
* SQLite: Execute SQLCipher pragmas as very first operations on the database
SQLCipher requires, apart from 'key' pragma also other cipher-related
to be executed before read/write to the database.
* Added tests for SQLCipher functionality
* remove default-features from libsqlite3-sys when building from dev-dependencies
Co-authored-by: Szymon Zimnowoda <szimnowoda.memri@gmail.com>
* chore: add doc example for manual implemenation of FromRow trait
* fix typo
Co-authored-by: Jonas Platte <jplatte@users.noreply.github.com>
* chore: use `sqlx::Result` directly
Co-authored-by: Jonas Platte <jplatte@users.noreply.github.com>
* Add in an example of how to use separated
Dearest Maintainer,
Thank you for your work on this project. I started using query builder today and I have enjoyed it. I did have a hard time figuring out how best to use separated to generate the values for an IN statement. It is my hope that adding an example will save someone else a few minutes of code reading or compile time. I wrote the example in the github text editor but It looks correct.
Thanks again for your work on this.
Becker
* end ```
* Apply cfg and end ```
* remove dup
* Update sqlx-core/src/query_builder.rs
* fix(postgres): don't panic if `S` or `V` Notice fields are not UTF-8
* fix: run `cargo update` to rotate cache key
for some reason there's some bad compiler artifacts cached
* use direct blocking calls for SQLite in `sqlx_macros`
* this also ensures the database is closed properly, cleaning up tempfiles
* don't send `PRAGMA journal_mode` unless set
* this previously defaulted to WAL mode which is a permanent setting
on databases which doesn't necessarily apply to all use-cases
* changing into or out of WAL mode acquires an exclusive lock on the database
that can't be waited on by `sqlite3_busy_timeout()`
* for consistency, `sqlx-cli` commands that create databases will still
create SQLite databases in WAL mode; added a flag to disable this.
* in general, don't send `PRAGMA`s unless different than default
* we were sending a bunch of `PRAGMA`s with their default values just to enforce
an execution order on them, but we can also do this by inserting empty slots
for their keys into the `IndexMap`
* add error code to `SqliteError` printout
* document why `u64` is not supported
* feat(sqlite): Add 'time' crate support for date/time types
docs(sqlite): Update types module docs for JSON and Chrono
docs(mysql): Update types module docs for JSON
* More efficient time crate decoding with FormatItem::First and hand-crafting of format descriptions
* Replace temporary testing code with original intention
* Replace duplicated formatting test with intended test
* Performance improvements to decoding OffsetDateTime, PrimitiveDateTime, and Time
* Use correct iteration for OffsetDateTime
* Reduce visibility of format constants
Co-authored-by: John B Codes <johnbcodes@users.noreply.github.com>
This function can panic due to slicing out of bounds when the server
responds without the `\x` prefix. With this commit we instead error and
also ensure that the prefix is what we expect instead of blindly
removing it.
Not directly related to the panic, we replace as_str() with as_bytes()
because there is no reason to perform a utf8 validity check when
hex::decode already checks that the content is valid.
To not break the API we need to use an Arc instead of a Box for the
callback functions. Alternatively we could require all the function to
be Clone, but that would be a breaking change.
* pool: fix panic when using callbacks
add regression test
* pool: fix panic when using callbacks
add regression test
added missing typedef `MssqlPoolOptions`
* fix#1905 : replaced all uses of "uri" to "url"
* rebase commits
resolved conflicts in mod.rs
fixed conflict in options.rs
Update options.rs
Update options.rs
Update options.rs
* Fixed leak of `Arc<SharedPool>` in `DecrementSizeGuard::cancel()`
* Renamed `PoolOptions::connect_timeout` to `acquire_timeout` for clarity.
* Fixed `/* SQLx ping */` showing up in Postgres query logs
* Made `.close()` a regular function that returns a `Future`
* Deleted deprecated method `PoolConnection::release()`
* Document why connection might be dropped if `Pool::acquire()` is cancelled
* Added connection metadata to pool lifecycle callbacks
* Improved guarantees for `min_connections`
* Fixed `num_idle()` to not spin forever at high load
* Improved documentation across the `pool` module