Commit graph

2211 commits

Author SHA1 Message Date
Austin Bonander
f02ff94e9c
refactor: pool fixes and breaking changes (#1901)
* 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
2022-06-16 12:56:28 -07:00
Arne Beer
21590d51f5
Expose connect_options for initialized pools and database on the PgConnectOptions (#1897)
* Expose ConnectOptions

* Expose PoolOptions
2022-06-16 12:25:13 -07:00
Miklós Tusz
664d576655
Fix migration checksum comparison during migrate info (#1888)
When running `sqlx migrate info`, the applied migrations checksums are
compared against the checksums of the local migration files. While the
checksums of applied migrations are stored correctly in the database as
sha384sum values, the `migrate info` command was incorrectly comparing
these against the checksums of down-migrations in cases where reversible
migrations are being used (e.g. when migrations end in `.up.sql` and
`.down.sql`).

This fixes the issue by skipping over any migrations with the
`MigrationType::ReversibleDown` type, using the same idiom as is used
when running migrations (with `migrate run`).

Issue introduced in #1680
Partially resolves #1158
2022-06-10 12:07:23 -07:00
Chengxing Yuan
edaf7d0673
Add i16 support for Any Type. (#1895)
* Add i16 support for Any Type.

* fix test.
2022-06-08 16:01:55 -07:00
Keiji, Yoshimi
185c57d936
added test for LoginAck (#1890) 2022-06-08 15:49:34 -07:00
Keiji, Yoshimi
4e9bfb0b2d
added test for mssql protocol Info (#1891) 2022-06-08 15:49:25 -07:00
Keiji, Yoshimi
3cfa734b50
added test for mssql ReturnValue (#1892)
* added test for mssql ReturnValue

* fixed warnings: unused import: `DataType`
2022-06-08 15:49:12 -07:00
Austin Bonander
1f91724927
feat(cli): add --connect-timeout (#1889) 2022-06-08 15:48:04 -07:00
Kian-Meng Ang
d52f301a94
Fix typos (#1894)
* Fix typos

* Update CHANGELOG.md

Co-authored-by: Austin Bonander <austin.bonander@gmail.com>

Co-authored-by: Austin Bonander <austin.bonander@gmail.com>
2022-06-08 14:56:56 -07:00
tyrelr
ed56622526
Improve Sqlite support for sub-queries and CTE's (#1816)
* reproduce incorrect nullability for materialized views

* split ephemeral/index-only table handling from real table handling

* add test for literal null, expect nullability to be identified from table information

* gather interpreter state into a struct, no change in behaviour

* prevent infinite loops that could arise once branching is supported

* track nullability alongside the datatype instead of in a separate lookup

* implement basic comprehension of branching opcodes

* fix datatype calculation of aggregates which are never 'stepped' through

* implement coroutine and return operations, including tracking of 'actual' integer value stored in the register by Integer/InitCoroutine/Yield operations.

* strip unnecessary history field out

* Modify variable test to expect bind-variable outputs to be nullable, rather than unknown

* add partially commented-out union tests, simplify code to satisfy simplest union case

* fix unit test incorrectly expecting primary keys to be implicitly not-null

* add failing test for recursive tables

* add logging of query explain plan

* track explain plan execution history

* broken RowData implementation (doesn't alias)

* Implement OpenPseudo tables as an alias of a register value

* fix comment

* clean up logging code warnings

* use cfg to omit QueryPlanLogger unless sqlite feature is used
2022-06-07 14:24:08 -07:00
Ophir LOJKINE
20d61f4271
query_as: don't stop stream after decoding error (#1887)
* query_as: don't stop stream after decoding error

Fixes https://github.com/launchbadge/sqlx/issues/1884

When a single row cannot be converted to the target type of query_as,
it should not prevent the library user from accessing the other rows

Otherwise, the user cannot access all query results in query_as.

* use union in tests to maximize db compatibility
2022-06-01 19:18:18 -07:00
Toby Murray
24baac779f
Put Usage at same level as Install (#1814)
From a formatting perspective, `Usage` is currently nested under `Install`. I think these would appropriately be siblings. This has the side benefit of making the headings under `Usage` more visually distinct from the rest of the content which I think makes it easier to read.
2022-06-01 13:53:47 -07:00
smonv
4e3ff3644f
trim [ and ] from host string before used to connect by TcpStream (#1818) 2022-05-31 18:03:26 -07:00
Erik Rhodes
c744cb7f60
Avoid panic when streaming packets are empty (#1861)
* changed [] access to .get() to return result instead of panic

* changed error type to protocol err

* fixed issue with comparing ref

* cargo fmt

Co-authored-by: Erik Rhodes <erik@space-nav.com>
2022-05-31 17:58:49 -07:00
Oskar Persson
63291d677f
Fix nullability check for inner joins in postgres (#1863) 2022-05-31 17:58:38 -07:00
Scott Wey
5d91ffc81c
add COLLATE_UTF8MB4_0900_AI_CI (#1856) 2022-05-31 17:58:16 -07:00
Toby Murray
302b415897
Reword "building in offline mode" (#1815)
Sometimes people do a bad job of reading comprehension (see #1813). This rewords a little to be even more prescriptive about how to build in offline mode.
2022-05-31 16:59:37 -07:00
Michael Freeborn
1b9c40b3c8
fix serde_json usage in macros (#1842) 2022-05-31 16:58:11 -07:00
Michael Freeborn
a110e75b95
make methods pub (#1843) 2022-05-31 16:57:46 -07:00
Charles Samborski
d5f7e4288d
Fix panics on unknown Postgres type oid when decoding (#1855)
Postgres arrays and records do not fully support custom types. When encountering an unknown OID, they currently default to using `PgTypeInfo::with_oid`. This is invalid as it breaks the invariant that decoding only uses resolved types, leading to panics.

This commit returns an error instead of panicking. This is merely a mitigation: a proper fix would actually add full support for custom Postgres types. Full support involves more work, so it may still be useful to fix this immediate issue.

Related issues:
- https://github.com/launchbadge/sqlx/issues/1672
- https://github.com/launchbadge/sqlx/issues/1797
2022-05-31 16:57:16 -07:00
Keiji, Yoshimi
fbee0655e3
fix field is never read on postgres test (#1881) 2022-05-31 16:56:12 -07:00
Keiji, Yoshimi
56d5283ef4
fix "unused Result that must be used" warnings (#1882) 2022-05-31 16:55:59 -07:00
LovecraftianHorror
a2691b9635
Reuse a cached DB connection instead of always recreating for sqlx-macros (#1782)
* refactor: Reuse a cached connection instead of always recreating for `sqlx-macros`

* fix: Fix type inference issue when no database features used

* refactor: Switch cached db conn to an `AnyConnection`

* fix: Fix invalid variant name only exposed with features

* fix: Tweak connection options for SQLite with `sqlx-macros`

* fix: Remove read only option for SQLite connection

* fix: Fix feature flags regarding usage of `sqlx_core::any`
2022-05-25 18:22:09 -07:00
Dirkjan Ochtman
fa5c436918
Update crc to 3 (#1831) 2022-05-02 12:44:16 -07:00
LovecraftianHorror
826e63fc11
refactor(sqlx-macros): Ignore deps when getting metadata for workspace root (#1823) 2022-04-21 12:36:15 -07:00
Paolo Barbolini
ec15f6b30c
Update uuid crate to v1 (#1821) 2022-04-20 12:48:29 -07:00
Paolo Barbolini
b934f82440
Bump remanining dependencies (#1807)
Co-authored-by: Austin Bonander <austin@launchbadge.com>
2022-04-15 14:34:48 -07:00
Paolo Barbolini
fc9c9be5e8
Update to edition 2021 (#1808)
* Update to edition 2021

* Fix running tests
2022-04-15 12:52:00 -07:00
Austin Bonander
fee8c60fe0
document 0.5.13 in changelog 2022-04-15 12:34:05 -07:00
Sebastian Pütz
babd353c2c
Make PgLTree::push infallible and take PgLTreeLabel directly. (#1734)
* Make PgLTree::push infallible and take PgLTreeLabel directly.

Previously the function took strings and parsed them into
PgLTreeLabel internally, now it's possible to directlry push
PgLTreeLabels onto a PgLTree.

* Push PgLTree String conversion to label.

* rebase and fix compile error

Co-authored-by: Austin Bonander <austin@launchbadge.com>
2022-04-14 16:16:00 -07:00
Valentin
c7478dcc66
Update BigDecimal dependency (#1529)
* Update BigDecimal dependency

* rebase onto master

Co-authored-by: Austin Bonander <austin@launchbadge.com>
2022-04-14 16:12:15 -07:00
Atkins
17760d0f83
Move server_version_num from trait to impl (#1384)
* refactor(core): move `fn server_version_num` from `trait PgConnectionInfo` to impl

Signed-off-by: Atkins Chang <atkinschang@gmail.com>

* fix rebase issues

Co-authored-by: Austin Bonander <austin@launchbadge.com>
2022-04-14 16:02:08 -07:00
Paolo Barbolini
17fde443be
Bump ipnetwork to 0.19 (#1426)
* Bump ipnetwork to 0.18

* Bump ipnetwork to 0.19
2022-04-14 15:11:58 -07:00
Paolo Barbolini
ba123e62fa
Update time to 0.3.2 (#1455)
Co-authored-by: Tyler Hill <tyhi@tyhi.rs>
2022-04-14 15:11:46 -07:00
Paolo Barbolini
08296a28a0
Upgrade rustls to 0.20 (#1505)
* Upgrade rustls to 0.20

* Rustls 0.20.1 is out

* Fix merge conflict mistake

* Bump rustls-pemfile to 0.3

* Resync Cargo.lock

* Bump rustls-pemfile to v1

Co-authored-by: Austin Bonander <austin@launchbadge.com>
2022-04-14 15:11:17 -07:00
Paolo Barbolini
a97208c016
postgres: use Oid type everywhere instead of u32 (#1602)
* postgres: use Oid type instead of u32

* Make serde happy

* Expose the inner u32

* docs

* Try to fix tests

* Fix unit tests

* Fix order

* Not sure what happened here
2022-04-14 15:07:45 -07:00
05storm26
a68957b21f
Make all ConnectOptions clonable (#1612) 2022-04-14 15:07:29 -07:00
05storm26
f328cc15d8
Sqlite chrono::DateTime<FixedOffset> timezone fix (#1618) 2022-04-14 15:06:55 -07:00
Josh Triplett
342d157a50
Update git2 to 0.14 (#1733)
git2-rs recently updated major versions due to libgit2 doing the same.
Bump the version used in sqlx accordingly, to allow users of the new
git2 to use git2::Oid with sqlx.
2022-04-14 15:06:37 -07:00
Pruthvikar Reddy
cc1ab90110
Fix Rust type for SQLite REAL (#1785)
REAL is stored as as 8-byte IEEE floating point number
See https://www.sqlite.org/datatype3.html#storage_classes_and_datatypes
2022-04-14 15:05:38 -07:00
Austin Bonander
2e026cae67
prepare 0.5.12 release (#1800)
* prepare release 0.5.12

* chore: remove mentions of things happening in 0.6

except one mention that should still be happening in 0.6
2022-04-14 14:21:15 -07:00
Austin Bonander
6c7006c4cc
fix(pool): don't leak connections if drop task doesn't run (#1799)
fixes #1396
2022-04-13 16:39:07 -07:00
Sebastien Guillemot
973f3d154d
Fix newline parsing in pgpass (#1791)
* Fix newline parsing in pgpass

* test loading pgpass from a file

Co-authored-by: Austin Bonander <austin@launchbadge.com>
2022-04-13 14:58:34 -07:00
Austin Bonander
a46e370c94
feat: document and expand query builder (#1790)
elaborates on the API introduced in #1780
2022-04-12 13:22:47 -07:00
Paolo Barbolini
ccbbe102b2
Update RustCrypto crates (#1625)
* Update RustCrypto crates

* rsa bump

* rsa dump

* rsa bump

* Bump rsa to 0.6.0-pre crates.io release

* Bump hkdf

* Resync Cargo.lock

* Bump rsa to 0.6.0
2022-04-11 11:24:09 -07:00
crajcan
a470682572
Add Query builder (#1780)
* Add Query builder

* Make query_builder.rs in sqlx-core

* Add QueryBuilder::new()

* Add QueryBuilder::push()

* Define questions for documentation

* Get new, push, push_bind working with types

* Handle postgres' numbered bind varaibles

* Add a test for QueryBuilder#build

* Move arguments into Option

* Refactor query builder

* Finish testing QueryBuilder#build

* Remove design doc

* Add a test for pushing strings with push_bind

* Integration test green

* Adjust some tests

* Make query builder generic about placeholder segmenent ('$N' or '?')

* Run fmt

* Redesign Arguments#format_placeholder in line with code review

* Use write! to push sql to QueryBuilder

* Add QueryBuilder::reset to allow for QueryBuilder reuse

* Run cargo fmt
2022-04-08 13:36:42 -07:00
david-mcgillicuddy-moixa
6efc39f213
Include affected rows in logging even when query is done (#1754)
* fix logging bug

* slight code cleanup

* change to split rows affected and rows returned

* review comments, and small unreachable bug
2022-04-08 12:40:11 -07:00
Jérémie Drouet
0c95fdd19a
feat(migration): add function to undo migrations (#1675)
Right now, there is only a `run` function to programatically run the
migrations, which is great, but nothing to run the migrations down.

This function adds the possibility to undo the migrations until a
specific version (could say -1 or 0 to remove them all).

With this feature, it's now possible, in the end to end or integration
tests to run the migrations and undo them between each test set and
therefore test the migrations themselves.

This is the kind of feature that some ORM have like sequelize in nodejs
that allow you to undo migrations programatically.

Reference to the doc:
https://sequelize.org/v7/manual/migrations.html#undoing-migrations

Signed-off-by: Jérémie Drouet <jeremie.drouet@gmail.com>
2022-04-07 16:03:00 -07:00
tyrelr
217dc55062
Fix #1249 Left joins in SQLite can break the query macros (#1789)
* Reproduce github issue#1249: Left joins in sqlite can break the query macros

* Fix panic caused by unknown cursor columns when executing NullRow command. Fixes #1249
2022-04-07 13:18:37 -07:00
Austin Bonander
f1c635d739
feat(pool): implement close-event notification (#1776)
fix(postgres): integrate pool close-event into `PgListener`

closes #1764
2022-04-05 16:17:35 -07:00