Commit graph

100 commits

Author SHA1 Message Date
Austin Bonander
bae083cf79 fix: clippy warnings 2024-06-13 13:11:36 -07:00
Austin Bonander
0f6054cf81 fix: run cargo fmt 2024-06-13 13:11:36 -07:00
Dario Heinisch
c57bcb967f
Hide docs for any (#3254) 2024-06-05 18:21:10 -07:00
Max Bruckner
c57b46ceb6
Make Encode return a result (#3126)
* Make encode and encode_by_ref fallible

This only changes the trait for now and makes it compile, calling .expect() on all users. Those will be removed in a later commit.

* PgNumeric: Turn TryFrom Decimal to an infallible From

* Turn panics in Encode implementations into errors

* Add Encode error analogous to the Decode error

* Propagate decode errors through Arguments::add

This pushes the panics one level further to mostly bind calls. Those will also be removed later.

* Only check argument encoding at the end

* Use Result in Query internally

* Implement query_with functions in terms of _with_result

* Surface encode errors when executing a query.

* Remove remaining panics in AnyConnectionBackend implementations

* PostgreSQL BigDecimal: Return encode error immediately

* Arguments: Add len method to report how many arguments were added

* Query::bind: Report which argument failed to encode

* IsNull: Add is_null method

* MySqlArguments: Replace manual bitmap code with NullBitMap helper type

* Roll back buffer in MySqlArguments if encoding fails

* Roll back buffer in SqliteArguments if encoding fails

* Roll back PgArgumentBuffer if encoding fails
2024-05-31 12:42:36 -07:00
Austin Bonander
60d033eda2
fix(ci): pin Rust version, ditch unmaintained actions (#3234) 2024-05-14 23:57:31 -07:00
Grzegorz Bartoszek
a5d7fffc1b
Add Debug impl for PgRow (#2917) 2024-04-22 15:39:39 -07:00
Feike Steenbergen
17d832b3de
PostgreSQL Bugfix: Ensure connection is usable after failed COPY inside a transaction (#3138)
* Include test case for regular subtransactions

While using COPY and subtransactions I kept running into errors.
This test case documents that error, it currently fails with:

    Error: encountered unexpected or invalid data: expecting ParseComplete but received CommandComplete

* PostgreSQL Copy: Consume ReadyForQuery on error

When a COPY statement was in error inside a subtransaction,
a Protocol Error used to be raised. By consuming the ReadyForQuery
message when there is an error, we no longer have this issue.
2024-04-19 15:45:05 -07:00
Raghav
e42ee35a76
fix(postgres) : int type conversion while decoding (#3173)
* fix(postgres) : int type conversion while decoding

* Check value buffer len when decoding integer type in postgres

* decode from octal for postgres i8

---------

Co-authored-by: RaghavRox <66472843+RaghavRox@users.noreply.github.com>
2024-04-19 15:43:06 -07:00
Jaime
40aef6da2c
feat: no tx migration (#3181)
* test: add a failing test

* feat: add no_tx to migration struct

* feat: execute migration with no tx block

* fix: expected string literal compilation error

* test: update no tx to content comment

* refactor: use the sql comment instead of file name semantics

* docs: remove no_tx from file format comment

* fix: remove filename matches

* fix: messed up merge

* refactor: dedupe migration

* fix: move comment to where it makes sense

* fix: linter error
2024-04-19 15:42:44 -07:00
Gnome!
3e7aa6bedf
Bump deps that do not need code changes (#3165) 2024-04-06 00:07:36 -07:00
Maciej Flak
45b5b61d7b
Add version information for failed cli migration (#3129) (#3130) 2024-04-04 21:45:21 -07:00
Austin Bonander
02c68a46c7
refactor: lift type mappings into driver crates (#2970)
Motivated by #2917
2024-03-30 15:52:52 -07:00
Tyler Hawkes
b607251fc4
Implement PgHasArrayType for all references (#2869) 2024-03-14 12:38:19 -07:00
nitn3lav
9ba488c831
Generic Associated Types in Database, replacing HasValueRef, HasArguments, HasStatement (#2973)
* HasValueRef, HasArguments, HasStatement -> Database GATs

replace the associated types from the generic traits
`HasValueRef<'r>`, `HasArguments<'q>` and `HasStatement<'q>`
with generic associated types in `Database`

* fixup after rebase

---------

Co-authored-by: Austin Bonander <austin.bonander@gmail.com>
2024-03-14 12:35:52 -07:00
Jesse Wang
936744dfd6
Fix describe on PostgreSQL views with rules (#2736)
* fix postgres describe on multiple explains

* inline the first explain using smallvec

* fix: regenerate `Cargo.lock`

---------

Co-authored-by: Austin Bonander <austin.bonander@gmail.com>
2024-03-14 12:05:44 -07:00
Austin Bonander
635dba5b26 fix: deprecation in postgres::types::chrono 2024-03-11 22:01:04 -07:00
Joe
bbfd0d711a
fix: AnyRow not support PgType::Varchar (#2976) 2024-03-05 19:47:15 -08:00
Lílian
b29eab0439
feat: add to_url_lossy to connect options (#2902)
* feat: add get_url to connect options

Add a get_url to connect options and implement it for all needed types;
include get_filename for sqlite. These changes make it easier to test
sqlx.

* refactor: use expect with message

* refactor: change method name to `to_url_lossy`

* fix: remove unused imports
2024-03-05 19:46:49 -08:00
Austin Bonander
791a7f5417 doc(pg): document behavior of bigdecimal and rust_decimal with out-of-range values
also add a regression test
2024-03-05 18:33:56 -08:00
Léo Gaspard
dfb60141bd fix: do not panic when binding a large BigDecimal 2024-03-05 18:33:56 -08:00
Rafael Guerreiro
e8fc35a5a4 Remove sha1 because it's not being used in postgres 2024-03-05 18:10:33 -08:00
Carter
664dbdf54b docs: update example for PgConnectOptions 2024-03-04 21:36:07 -08:00
Mirek Klimos
dd900e50b6
Optimize SASL auth in sqlx-postgres (#3050)
* Optimize SASL auth in sqlx-postgres

* fix formatting
2024-02-16 16:32:31 -08:00
Paweł Urbanek
0299959ca6
Add default implementation for PgMoney (#3018) 2024-01-30 13:23:45 -08:00
Paweł Urbanek
af31d5059d
Add default implementation for PgInterval (#3013) 2024-01-25 23:29:51 -08:00
Luiz Carvalho
a7862ae416
feat: expose connect options fields (#2891)
Exposes some of the main fields for PgConnectOptions
and MySqlConnectOptions. Exposed fields include: host,
port, socket, ssl mode, application name, and charset.
2024-01-20 18:21:34 -08:00
Thomas de Zeeuw
31e541ac7a
Fix handling of deferred constraints for PostgreSQL (#2913) 2024-01-20 02:36:06 -08:00
Austin Bonander
7044a92858 fix: fix new warnings that cropped up 2024-01-05 19:05:16 -08:00
Jesse Wang
91c6e6668b
fix(postgres): avoid unnecessary flush in PgCopyIn::read_from 2023-12-12 22:53:00 +13:00
Austin Bonander
9fc9e7518e
feat: Text adapter (#2894) 2023-11-22 17:06:47 -08:00
Vraj Shah
62f82cc43a
Fixed force dropping bug (#2892) 2023-11-21 12:42:08 -08:00
Vraj Shah
fda415927a
Sqlx Cli: Added force flag to drop database for postgres (#2873)
* Updated ahash so it can compile on mac

* Updated MigrateDatabase Trait + related functions

* Postgres force drop database flag impl

* Update migrate.rs

* Reverted MigrateDatabase Trait

* Update migrate.rs

* Update migrate.rs

* Added force drop database fn impl

* Add Migrate Error

* Fixed changed function name
2023-11-21 11:11:08 -08:00
Jason Klein
ee73c847a7
Fixed (#2838)
fmt
2023-11-06 17:36:31 -08:00
Brian Heineman
92523f3629
Update extra_float_digits default to 2 instead of 3 (#2832) 2023-11-03 17:23:53 -07:00
Boris.Lok
e1ac388173
Provide fn PgConnectOptions::get_host(&self) (#2752)
Co-authored-by: boris <boris.lok@cienet.com>
2023-10-23 16:48:41 -07:00
Peter Hamilton
ab0d10d935
Make PgListener recover from UnexpectedEof (#2684)
This is often encountered when the host the db is on is restarted.
For example, a reboot of AWS Aurora causes this. If we don't handle this
properly the PgListeners are stuck in an erroring state, even when the DB
is back online. By catching it here, we will reconnect when it is
(eventually) back online.
2023-10-17 16:10:53 -07:00
Conrad Ludgate
f93bbe87be
postgres begin cancel safe (#2819) 2023-10-16 19:20:48 -07:00
Austin Bonander
58cb18a47a
fix: correct decoding of rust_decimal::Decimal for high-precision values (#2820)
also fixes handling of feature flags
2023-10-16 14:03:28 -07:00
hgranthorner
56945d7396
feat(citext): support postgres citext (#2478)
* feat(citext): implement citext for postgres

* feat(citext): add citext -> String conversion test

* feat(citext): fix ltree -> citree

* feat(citext): add citext to the setup.sql

* chore: address nits to #2478

* Rename `PgCitext` to `PgCiText`
* Document when use of `PgCiText` is warranted
* Document potentially surprising `PartialEq` behavior
* Test that the macros consider `CITEXT` to be compatible with `String` and friends

* doc: add `PgCiText` to `postgres::types` listing

* chore: restore missing trailing line break to `tests/postgres/setup.sql`

---------

Co-authored-by: Austin Bonander <austin@launchbadge.com>
2023-10-11 18:03:17 -07:00
Fernando Gonçalves
3c2471e2dc
fix: sqlx::macro db cleanup race condition by adding a margin to current timestamp (#2640)
* fix: sqlx::macro db cleanup race condition by adding a margin to current timestamp

* feat: increase margin to 2 seconds
2023-10-11 16:03:53 -07:00
Yudai Fukushima
846dcfe52a
fix: decode postgres time without subsecond (#2784)
* fix: decode postgres time without subsecond

* update: decode postgres time without subsecond by making subsecond optional
2023-10-04 16:56:14 -07:00
Ramzi Sabra
c2eda1c8ac
derived Hash trait for PgInterval (#2793) 2023-10-04 13:47:10 -07:00
wyhaya
3b9a2743ec
Support for setting client certificate and key from bytes (#2646)
* Support for setting client certificate and key from bytes

* Rename ssh_client_*_from_bytes to ssl_client_*_from_pem

* doc: clarify client_*_from_pem docs and add examples

* doc: apply missed suggestions from previous commit

* fix: run `cargo fmt`

---------

Co-authored-by: Austin Bonander <austin.bonander@gmail.com>
Co-authored-by: Austin Bonander <austin@launchbadge.com>
2023-09-25 18:29:39 -07:00
Grant G
c0d4019d17
Add impl for Type, Decode, and Encode for Box<str> and Box<[u8]> (#2712) 2023-09-11 19:28:18 -07:00
Austin Bonander
487b89a4b6
fix: ignore extra fields in Postgres describe parsing (#2670)
* fix(postgres): sqlx prepare fails if shared_preload_libraries=pg_stat_statements

closes #2622

refs:
* https://serde.rs/enum-representations.html#untagged
* https://serde.rs/field-attrs.html#skip
* https://www.postgresql.org/docs/current/pgstatstatements.html
  * https://www.postgresql.org/docs/current/runtime-config-statistics.html#GUC-COMPUTE-QUERY-ID

* fix(postgres): regression of #1449

```
error: error occurred while decoding column 0: data did not match any variant of untagged enum Explain at line 3 column 1
Error:    --> tests/postgres/macros.rs:103:15
    |
103 |     let row = sqlx::query!(r#"CALL forty_two(null)"#)
    |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: this error originates in the macro `$crate::sqlx_macros::expand_query` which comes from the expansion of the macro `sqlx::query` (in Nightly builds, run with -Z macro-backtrace for more info)

error: could not compile `sqlx` (test "postgres-macros") due to previous error
```

* refactor(postgres): don't define unused fields in QueryPlan

* refactor(postgres): simplify query plan handling, add unit test

* chore: document why we load `pg_stat_statements` in tests

---------

Co-authored-by: mrl5 <31549762+mrl5@users.noreply.github.com>
2023-07-31 14:52:55 -07:00
Yuri Astrakhan
a824e8468c
Cleanup format arguments (#2650)
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
```
2023-07-31 13:27:04 -07:00
Sebastian N. Fernandez
7e7dded8af
Adding PgHasArrayType for &[u8;N] (#2634)
* Adding PgHasArrayType for &[u8;N]

* cargo fmt

---------

Co-authored-by: asdf <asdf@ethereum>
2023-07-24 16:10:42 -07:00
Jesse Wang
94379d88b3
fix(postgres): fix buffer management in PgCopyIn.read_from (#2630) 2023-07-24 16:07:29 -07:00
Austin Bonander
1d1095e94f
feat: allow opt-out of PgHasArrayType with #[derive(sqlx::Type)] (#2619)
closes #2611
2023-07-14 16:16:18 -07:00
Luiz Carvalho
3db16751a0
feat(sqlx-core): add table function to database error (#2616) 2023-07-14 10:37:02 -07:00