Commit graph

991 commits

Author SHA1 Message Date
Rob Ede
7adbb7fefc
refactor: remove direct actix-rt support (#1679)
actix- runtime feature flags are now aliases for tokio- flags
2022-08-01 21:48:40 -07:00
Austin Bonander
9a6d07f10a
feat: QueryBuilder improvements (#2005)
* get raw SQL
* method to build `QueryAs` instead of `Query`
2022-07-28 20:02:05 -07:00
Austin Bonander
a2eceec33b
chore: replace dotenv with dotenvy (#2003)
* chore: replace `dotenv` with `dotenvy`

The former appears to be unmaintained and the latter is a drop-in replacement.

* chore: fix all warnings
2022-07-28 14:33:44 -07:00
Marco Neumann
05d64fb722
fix: agree one a single default runtime for the whole workspace (#1988)
This fixes `cargo check --workspace` and rust-analyzer.

Also see <https://github.com/launchbadge/sqlx/discussions/1956>.
2022-07-28 13:15:40 -07:00
Marco Neumann
29073cbe84
fix: ensure PG connection is established before using it (#1989)
Fixes #1940.
2022-07-27 13:58:36 -07:00
Erik
78a0a5943a
Add example for manual implemenation of the FromRow trait (#1495)
* 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>
2022-07-19 14:31:10 -07:00
Vladimir
8fc4625ec7
Add push_bind_unseparated for Separated in query builder (#1985) 2022-07-19 00:10:33 -07:00
Stephen Becker IV
dbb1feebda
Add in an example of how to use separated (#1902)
* 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
2022-07-15 12:33:53 -07:00
Vladimir
28e22e1259
add push_tuples for QueryBuilder (#1954)
* add `push_tuples` for QueryBuilder

* update docs

* fix docs
2022-07-15 12:11:21 -07:00
Yota Toyama
9534de3476
Fix type info access in Any database driver (#1848)
* Fix type info access in `Any` database driver

* Implement custom receiver methods

* Revert "Fix type info access in `Any` database driver"

This reverts commit a2845c74c5e545351f3f0f2fa6851e7f23a60621.

* Refactor

* Update sqlx-core/src/any/row.rs

Co-authored-by: Yota Toyama <raviqqe@gmail.com>

Co-authored-by: Austin Bonander <austin.bonander@gmail.com>
2022-07-14 14:17:57 -07:00
Austin Bonander
6de3e09816
fix(postgres): don't panic if S or V Notice fields are not UTF-8 (#1968)
* 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
2022-07-12 17:23:13 -07:00
Théo OIRY
7cdb68be1a
support flatten attribute in FromRow macro (#1959)
* support flatten attribute in FromRow macro

* added docs for flatten FromRow attribute
2022-07-12 14:28:07 -07:00
Austin Bonander
bc3e70545b
sqlite improvements (#1965)
* 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
2022-07-12 13:59:37 -07:00
Valentin
9ca1fbf2ca
Support Rust arrays in Postgres (#1953) 2022-07-08 16:56:47 -07:00
John B Codes
cfef70a796
Add Sqlite support for the time crate (#1865)
* 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>
2022-07-08 16:51:50 -07:00
Valentin
b3bbdab705
Fix panic in Postgres Bytes decode (#1948)
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.
2022-07-06 18:23:29 -07:00
James H
79ebd3005a
docs: added docs for json (#1917)
* fix: added docs for json

* fix: doc tests
2022-06-30 17:53:46 -07:00
Thomas de Zeeuw
39eadd6d6d
Implement Clone for PoolOptions (#1919)
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.
2022-06-22 15:00:28 -07:00
Austin Bonander
3d4861fd7c
pool: fix panic when using callbacks (#1915)
* pool: fix panic when using callbacks

add regression test

* pool: fix panic when using callbacks

add regression test

added missing typedef `MssqlPoolOptions`
2022-06-21 15:17:48 -07:00
meh
59ad2ecc92
Add support for IpAddr (#1822) 2022-06-17 17:14:47 -07:00
Romain
339e0580ca
fix #1905 : replaced all uses of "uri" to "url" (#1906)
* 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
2022-06-17 15:32:30 -07:00
Austin Bonander
17cebde64a
preparing 0.6.0 release (#1911)
* preparing 0.6.0 release

* run `cargo update` (not `upgrade`)
2022-06-16 15:53:09 -07:00
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
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
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
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
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
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
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
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