184 Commits

Author SHA1 Message Date
Beau Gieskens
1c9cbe939a
feat: add ipnet support (#3710)
* feat: add ipnet support

* fix: ipnet not decoding IP address strings

* fix: prefer ipnetwork to ipnet for compatibility

* fix: unnecessary cfg
2025-03-23 17:19:05 -07:00
Austin Bonander
393b731d5e
Merge of #3427 (by @mpyw) and #3614 (by @bonsairobo) (#3765)
* feat: Implement `get_transaction_depth` for drivers

* test: Verify `get_transaction_depth()` on postgres

* Refactor: `TransactionManager` delegation without BC

SQLite implementation is currently WIP

* Fix: Avoid breaking changes on `AnyConnectionBackend`

* Refactor: Remove verbose `SqliteConnection` typing

* Feat: Implementation for SQLite

I have included `AtomicUsize` in `WorkerSharedState`. Ideally, it is not desirable to execute `load` and `fetch_add` in two separate steps, but we decided to allow it here since there is only one thread writing. To prevent writing from other threads, the field itself was made private, and a getter method was provided with `pub(crate)`.

* Refactor: Same approach for `cached_statements_size`

ref: a66787d36d62876b55475ef2326d17bade817aed

* Fix: Add missing `is_in_transaction` for backend

* Doc: Remove verbose "synchronously" word

* Fix: Remove useless `mut` qualifier

* feat: add Connection::begin_with

This patch completes the plumbing of an optional statement from these methods to
`TransactionManager::begin` without any validation of the provided statement.

There is a new `Error::InvalidSavePoint` which is triggered by any attempt to
call `Connection::begin_with` when we are already inside of a transaction.

* feat: add Pool::begin_with and Pool::try_begin_with

* feat: add Error::BeginFailed and validate that custom "begin" statements are successful

* chore: add tests of Error::BeginFailed

* chore: add tests of Error::InvalidSavePointStatement

* chore: test begin_with works for all SQLite "BEGIN" statements

* chore: improve comment on Connection::begin_with

* feat: add default impl of `Connection::begin_with`

This makes the new method a non-breaking change.

* refactor: combine if statement + unwrap_or_else into one match

* feat: use in-memory SQLite DB to avoid conflicts across tests run in parallel

* feedback: remove public wrapper for sqlite3_txn_state

Move the wrapper directly into the test that uses it instead.

* fix: cache Status on MySqlConnection

* fix: compilation errors

* fix: format

* fix: postgres test

* refactor: delete `Connection::get_transaction_depth`

* fix: tests

---------

Co-authored-by: mpyw <ryosuke_i_628@yahoo.co.jp>
Co-authored-by: Duncan Fairbanks <duncanfairbanks6@gmail.com>
2025-03-10 14:29:46 -07:00
James H.
2f10c29dfd
feat(postgres): add geometry circle (#3773)
* feat: circle

* docs: comments
2025-03-09 15:01:30 -07:00
James H.
ca3a509036
feat(postgres): add geometry polygon (#3769)
* feat: add polygon

* test: paths for pgpoints in polygon test

* fix: import typo

* chore(Sqlite): remove ci.db from repo (#3768)

* fix: CI

* Fix breakage from Rustup 1.28 <https://blog.rust-lang.org/2025/03/02/Rustup-1.28.0.html>
* Let `Swatinem/rust-cache` generate cache keys

* fix(ci): upgrade Ubuntu image to 24.04

For some reason the `cargo +beta clippy` step is failing because `libsqlite3-sys` starts requiring Glibc >= 2.39 but I don't have time to figure out why and I can't reproduce it in a clean environment.

---------

Co-authored-by: joeydewaal <99046430+joeydewaal@users.noreply.github.com>
Co-authored-by: Austin Bonander <austin.bonander@gmail.com>
2025-03-07 01:25:45 -08:00
Chitoku
a92626d6cc postgres: Use current tracing span when dropping PgListener 2025-03-05 01:30:38 -08:00
James H.
5c573e15eb
feat(postgres): add geometry path (#3716)
* feat: add geometry path

* fix: paths to pg point

* test: remove array tests for path

* Fix readme: uuid feature is gating for all repos (#3720)

The readme previously stated that the uuid feature is only for postres but it actually also gates the functionality in mysql and sqlite.

* Replace some futures_util APIs with std variants (#3721)

* feat(sqlx-cli): Add flag to disable automatic loading of .env files (#3724)

* Add flag to disable automatic loading of .env files

* Update sqlx-cli/src/opt.rs

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

---------

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

* chore: expose bstr feature (#3714)

* chore: replace rustls-pemfile with rustls-pki-types (#3725)

* QueryBuilder: add `debug_assert` when `push_values` is passed an empty set of tuples (#3734)

* throw a warning in tracing so that the empty tuples would be noticed

* use debug assertion to throw a panic in debug mode

* fix: merge conflicts

* chore(cli): remove unused async-trait crate from dependencies (#3754)

* Update pull_request_template.md

* Fix example calculation (#3741)

* Avoid privilege requirements by using an advisory lock in test setup (postgres). (#3753)

* feat(sqlx-postgres): use advisory lock to avoid setup race condition

* fix(sqlx-postgres): numeric hex constants not supported before postgres 16

* Small doc correction. (#3755)

When sqlx-core/src/from_row.rs was updated to implement FromRow for tuples of up to 16 values, a comment was left stating that it was implemented up to tuples of 9 values.

* Update FAQ.md

* refactor(cli): replace promptly with dialoguer (#3669)

* docs(pool): recommend actix-web ThinData over Data to avoid two Arcs (#3762)

Both actix_web::web::Data and sqlx::PgPool internally wrap an Arc. Thus,
using Data<PgPool> as an extractor in an actix-web route handler results
in two Arcs wrapping the data of interest, which isn't ideal.

Actix-web 4.9.0 introduced a new web::ThinData extractor for cases like
this, where the data is already wrapped in an `Arc` (or is otherwise
similarly cheap and sensible to simply clone), which doesn't wrap the
inner value in a (second) Arc.

Since the new extractor is better suited to the task, suggest it in
place of web::Data when giving an example on how to share a pool.

* fix: merge conflicts

* fix: use types mod from main

* fix: merge conflicts

* fix: merge conflicts

* fix: merge conflicts

* fix: ordering of types mod

* fix: path import

* test: no array test for path

---------

Co-authored-by: Jon Thacker <thacker.jon@gmail.com>
Co-authored-by: Paolo Barbolini <paolo.barbolini@m4ss.net>
Co-authored-by: Ben Wilber <benwilber@users.noreply.github.com>
Co-authored-by: Austin Bonander <austin.bonander@gmail.com>
Co-authored-by: joeydewaal <99046430+joeydewaal@users.noreply.github.com>
Co-authored-by: tottoto <tottotodev@gmail.com>
Co-authored-by: Ethan Wang <mailme@ethanavania.org>
Co-authored-by: Stefan Schindler <dns2utf8@users.noreply.github.com>
Co-authored-by: kildrens <5198060+kildrens@users.noreply.github.com>
Co-authored-by: Marti Serra <marti.serra+github@protonmail.com>
Co-authored-by: Jonas Malaco <jonas@protocubo.io>
2025-03-02 14:29:53 -08:00
kildrens
a9dfb4f2c1
Avoid privilege requirements by using an advisory lock in test setup (postgres). (#3753)
* feat(sqlx-postgres): use advisory lock to avoid setup race condition

* fix(sqlx-postgres): numeric hex constants not supported before postgres 16
2025-02-20 18:13:56 -08:00
Sam Lyon
8cdad44366
docs: add some missing backticks (#3749)
* add ending backticks to starting backticks that were missing them

* fix table alignment
2025-02-19 15:23:45 -08:00
Paolo Barbolini
65229f7ff9
Replace some futures_util APIs with std variants (#3721) 2025-02-01 16:01:56 -08:00
James H.
97cada3e16
feat(postgres): add geometry box (#3711)
* feat: add geometry box

* test: cannot compare box arrays

* test: regular equals check for boxes

* test: try box array test
2025-01-29 14:59:50 -08:00
Nicolas Séverin
6ca52fe80c
Added missing special casing for encoding embedded arrays of custom types (#3603)
* Added missing special casing for encoding arrays of custom types

* Added the matching test

* Formatting
2025-01-27 17:30:02 -08:00
joeydewaal
6fa0458ff3
fix(Postgres) chunk pg_copy data (#3703)
* fix(postgres) chunk pg_copy data

* fix: cleanup after review
2025-01-25 14:23:50 -08:00
James H.
74da542bf3
feat: add postres geometry line segment (#3690)
* feat: add postres geometry line segment

* fix: add doc alias
2025-01-24 22:34:40 -08:00
Rémy SAISSY
ad1d7a8aa5
Derive clone and debug for postgresql arguments (#3687) 2025-01-24 14:41:06 -08:00
joeydewaal
a408c490fd
fix(postgres) use signed int for length prefix in PgCopyIn (#3701) 2025-01-24 14:30:02 -08:00
Andreas Liljeqvist
a83395a360
Fix: nextest cleanup race condition (#3334)
* remove unused trait fn `cleanup_test_dbs`

* *wip* solve test cleanup race condition

* check for exactly 63 chars in database name

* move base64 dependency

* change

* Use url_safe base64 encoding

* Assert quoting for database name

* refactor

* add mysql support?

* borrow

* fix borrows

* ensure quoting

* re-add trait cleanup_test_dbs

* fix mysql insert

* cargo lock

* use actual field

* cleanup converted path in sqlite

* replace dashes with underscore in db name

* refactor: remove redundant path conversion in cleanup_test and add db_name method

---------

Co-authored-by: Austin Bonander <austin.bonander@gmail.com>
2025-01-23 17:36:55 -08:00
tison
838a239a2c
docs: add example for postgres enums with type TEXT (#3655)
* docs: add example for postgres enums with type TEXT

Signed-off-by: tison <wander4096@gmail.com>

* revert GitHub naming

Signed-off-by: tison <wander4096@gmail.com>

* add note

Signed-off-by: tison <wander4096@gmail.com>

---------

Signed-off-by: tison <wander4096@gmail.com>
2025-01-15 08:41:57 -08:00
joeydewaal
dfd0ac5974
feat: add Transaction type aliases (#3658) 2025-01-03 00:26:09 -08:00
Rinat Shigapov
4590b9c3ee
close listener connection on TimedOut and BrokenPipe errors (#3648)
* close listener connection on TimedOut and BrokerPipe errors

* use matches macro to generate jump table instead of chain of conditions
2024-12-24 17:00:40 -08:00
Jakub Łabor
fdd4663318 Add PgConnection::is_explain_available 2024-12-24 01:53:37 -08:00
Jakub Labor
20bccf8877 Dont use EXPLAIN in nullability check for QuestDB 2024-12-24 01:53:37 -08:00
James H.
1678b19a46
feat: add geometry line (#3623)
* feat: add geometry line

* fix: point vs line

* fix: try regular comparison for line

* fix: undo point comparison change

* fix: regular comparison for array lines

* fix: remove line array test
2024-12-12 12:52:30 -08:00
joeydewaal
1f6ce33df4
chore: remove BoxFuture's (non-breaking) (#3629)
* chore: reduce BoxFuture's when using recursion.

* remove BoxFuture's in WithSocket

* chore: better document previous changes
2024-12-12 12:43:22 -08:00
Philip Cristiano
42ce24dab8
Add support for Postgres lquery arrays (#3553)
An lquery array can be used with the `?` operator for "Does ltree match
any lquery in array?"

Documentation: https://www.postgresql.org/docs/current/ltree.html#LTREE-OPS-FUNCS

Closes #2246
2024-11-27 19:00:13 -08:00
Gabriel Lopes Veiga
3e140ba384
Derive Copy where possible (#3577)
For database-specific types.
2024-11-27 14:49:08 -08:00
Chris Hanks
4f10962743
Add PgListener::next_buffered(), to support batch processing of notifications (#3560)
* Implement and test PgListener::try_recv_buffered().

* rustfmt

* Fix warnings.

* Fix test.

* Rename try_recv_buffered() -> next_buffered().
2024-11-27 13:56:01 -08:00
Sean Lynch
503a72c94f
Eagerly reconnect in PgListener::try_recv (#3585)
When PgListener's underlying connection is closed, try_recv() will
return Ok(None) and reconnect on the next call. In this case, user code
is supposed to reload its state from the database (or otherwise handle
potentially missing messages). However, if the user code uses another
database connection to do so then there is a period between when the
state is reloaded and PgListener's connection is re-established where
notifications are lost without any indication that this has happened.

This commit changes PgListener to eagerly reconnect by default. At the
suggestion of @abonander on discord, I have also included an option to
switch back to the old behaviour in the case where someone was depending
on it.

Now, if the connection is closed then, by default, user code can do
whatever it needs to do in order to recover and any notifications
emitted in the meantime will be waiting for it when it is done.
2024-11-27 13:52:23 -08:00
Benoit Ranque
e3ef8baf23
URL decode database name when parsing connection url (#3593) 2024-11-27 13:48:34 -08:00
James H.
a7f2928a1b
feat(postgres): point (#3583)
* feat: point

* test: try if eq operator works for arrays of geometries

* fix: re-introduce comparison

* fix: test other geometry comparison

* test: geometry array equality check

* test: array match for geo arrays geo match for geo only

* fix: prepare geometric array type

* fix: update array comparison

* fix: try another method of geometric array comparison

* fix: one more geometry match tests

* fix: correct query syntax

* test: geometry test further
2024-11-27 13:35:42 -08:00
Paolo Barbolini
3e8952b0d4
Bump thiserror to v2.0.0 (#3596) 2024-11-26 11:01:33 -08:00
Jakub Łabor
80314609ac
Use UNION ALL instead of UNION in nullable check (#3605) 2024-11-26 10:59:47 -08:00
Pmarquez
d4ae6ffd88
Implement AnyQueryResult for Sqlite and MySQL (#3608)
* impl AnyQueryResult for Sqlite and MySQL

* fix MySQL AnyQueryResult

* fix MySQL AnyQueryResult

* fix manifest

* rewrite `use` and address implementation concerns
2024-11-26 10:59:20 -08:00
Quentin Gliech
709226c19d
Implement Acquire for PgListener (#3550)
* Implement Acquire for PgListener

* Add a test which checks that PgListener implements Acquire

* Drop unnecessary call to `.acquire()`

* Rename test channel to avoid conflict with other tests
2024-10-28 15:00:06 -07:00
Oleksandr Babak
eac4b7aff7
Fix: Cannot query Postgres INTERVAL[] (#3566)
* fix(sqlx-postgres): macro could not understand pg interval array type

* refactor(sqlx-postgres): move pg interval array types closer to other array types
2024-10-28 14:59:41 -07:00
Dennis Schubert
028084bce3
Demote .pgpass file warning to a debug message. (#3548)
Fixes #3531
2024-10-06 15:21:56 -07:00
Andrei Nesterov
19f40d87a6
Obey no-transaction flag in down migrations (#3528) 2024-10-02 15:32:30 -07:00
joeydewaal
72512f7311
Support PgHstore by default in macros (#3514)
* Support PgHstore in macros

* Change tests

* Remove unused import
2024-10-02 11:56:13 -07:00
joeydewaal
68da5aefea
Box Pgconnection fields (#3529)
* Update PgConnection code

* rustfmt
2024-10-02 11:42:54 -07:00
vsuryamurthy
293c55ce89 Remove unused dependencies from sqlx-core, sqlx-cli and sqlx-postgres 2024-09-24 18:46:31 -07:00
Kurt Wolf
c597a225c5
feat: expose relation_id and relation_attribution_no on PgColumn (#3492)
* expose relation_id and relation_attribution_no on PgColumn

* Update sqlx-postgres/src/message/row_description.rs

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

* Update sqlx-postgres/src/column.rs

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

* Update sqlx-postgres/src/message/row_description.rs

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

* Update sqlx-postgres/src/column.rs

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

* Update sqlx-postgres/src/message/row_description.rs

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

* fix

---------

Co-authored-by: Austin Bonander <austin.bonander@gmail.com>
2024-09-07 18:43:03 -07:00
Pierre Wehbe
fd80f998ac
fix: Use rfc3339 to decode date from text (#3411) 2024-09-02 12:34:51 -07:00
Austin Bonander
e10789d9d7
fix cancellation issues with PgListener, PgStream::recv() (#3467)
* fix(postgres): make `PgStream::recv_unchecked()` cancel-safe

* fix(postgres): make `PgListener` close the connection on-error

* fix: incorrect math in `BufferedSocket::read_buffered()`
2024-08-27 10:54:31 -07:00
Austin Bonander
20ba796b0d fix(postgres): max number of binds is 65535, not 32767 (regression) 2024-08-26 16:20:45 -07:00
kdesjard
371cf4a0cc
Pgsql cube type compile fail (#3459)
* fails to compile as size_of is not found in scope

* keep scoping consistent with other type modules

* fmt fixes

---------

Co-authored-by: kdesjard <kristian.desjardins@nrcan-rncan.gc.ca>
2024-08-26 14:15:48 -07:00
Austin Bonander
9e3ece49d7 fix(postgres): use checked decrement on pending_ready_for_query_count 2024-08-23 23:39:32 -07:00
Austin Bonander
b5c218eb23 fix(postgres): fix missing inversion on PgNumeric::is_valid_digit() 2024-08-23 23:39:32 -07:00
Austin Bonander
01428ff643 fix(postgres): syntax error in EXPLAIN query 2024-08-23 23:39:32 -07:00
Austin Bonander
8919e34357 fix(postgres): syntax error in nullables query 2024-08-23 23:39:32 -07:00
Austin Bonander
56d0225378 chore(postgres): include nullables query in error 2024-08-23 23:39:32 -07:00
Austin Bonander
4fb2dcbe97 fix(postgres): decode PgDatabaseError for ErrorResponse 2024-08-23 23:39:32 -07:00