849 Commits

Author SHA1 Message Date
Billy Chan
5291c7f551
clippy 2022-12-20 15:56:37 +08:00
Billy Chan
2f00a8757d
Merge branch 'master' into select-into-tuple 2022-12-20 15:51:06 +08:00
Billy Chan
3cd834d40c
docs 2022-12-20 15:43:03 +08:00
mohs8421
1f27837f49
refactoring Schema to expose functions for database updates (#1256)
* extracting get_column_def from create_table_from_entity to make it available for database upgrade processes.

* Align code example formatting

* Converting the foreign key related code from create_table_from_entity into From<RelationDef> implementations to make its usage easier in different context, like updating a database.

* Refactor

* Fixup

Co-authored-by: Billy Chan <ccw.billy.123@gmail.com>
2022-12-19 17:24:11 +08:00
Billy Chan
17ed7156c4
Fix: update many cast enum values (#1178) 2022-12-19 17:09:18 +08:00
Billy Chan
7757a46c46
clippy 2022-12-16 21:36:00 +08:00
Antonio Scandurra
df2dcdabac
Prevent returning connections to pool with a positive transaction depth (#1283)
Mark transaction as closed *only* after commit/rollback succeeds.

Previously, `open` on the transaction would be set to `false` prior to attempting
to commit or rollback the transaction. When the operation failed, for example, due
to a serialization failure with a serializable isolation level, this would leave
the transaction in an inconsistent state, where it thought it was closed but really
it was still open. The connection would then be returned to the connection pool with
a transaction depth of 1, causing a savepoint to be erroneously created the next time
a transaction was created for the connection.

By waiting to set `open` to `false` until the commit/rollback succeeds, a failure
to do either will result in us correctly rolling back the transaction when dropping
it, ensuring that the connection is returned to the pool with a transaction depth
of 0. Note that this is consistent with how `sqlx` handles transactions.

We attempted to write a test, but had a very difficult time forcing postgres to fail
to commit a transaction. We found that it would block our requests instead when creating
conflicting updates, and we couldn't find any information about when it blocks vs when
transaction commits fail.

Co-Authored-By: Nathan Sobo <nathan@zed.dev>

Co-authored-by: Nathan Sobo <nathan@zed.dev>
2022-12-16 21:11:51 +08:00
Billy Chan
ccca35ab1a
clippy 2022-12-16 16:48:16 +08:00
Billy Chan
70c4a3a23e
Select into tuple 2022-12-15 21:24:10 +08:00
Marco Napetti
824158457b
Transactions Isolation level and Access mode (#1230)
* Transactions Isolation level and Access mode

* Fix typo

* Fix clippy lints
2022-12-02 13:09:23 +08:00
Billy Chan
ccb8818365
Add QuerySelect::columns method (#1264) 2022-12-01 14:01:11 +08:00
Billy Chan
3de0078a31
Optimize TryGetableFromJson (#1249) 2022-12-01 13:23:24 +08:00
Billy Chan
08cb44028e
Support bigdecimal::BigDecimal (#1258)
* Fix: fields with type `Option<T>` are always nullable

* Support BigDecimal
2022-12-01 12:53:19 +08:00
Chris Tsang
1b4e1670f7 clippy 2022-11-28 13:04:25 +08:00
Panagiotis Karatakis
f3910c329b Fix shared related item 2022-11-25 12:01:58 +02:00
Chris Tsang
085091c7df
Apply suggestions from code review 2022-11-24 16:24:49 +08:00
Chris Tsang
ca403da0d9
Mock DbErr (#1241)
* Mock Err

* Test mock errors
2022-11-24 13:42:47 +08:00
Chris Tsang
19b1da175d Move file 2022-11-24 00:03:29 +08:00
Chris Tsang
319f64fe64 cargo fmt 2022-11-23 23:55:24 +08:00
Chris Tsang
dcfba6f685 Remove Debug trait bounds 2022-11-23 23:31:28 +08:00
Chris Tsang
0abe9c9657 Use ValueTuple to replace Vec<Value> 2022-11-23 23:12:18 +08:00
Chris Tsang
6c7a162f05 cargo fmt 2022-11-23 22:47:41 +08:00
Panagiotis Karatakis
2bba146e9b Add load_one tests 2022-11-22 12:24:18 +02:00
Panagiotis Karatakis
f7f90cd7c5 Add load_many unit test 2022-11-22 10:38:54 +02:00
Billy Chan
115e19a95e
Close connection explicitly (#1236)
* Close connection and transaction

* Close connection only
2022-11-22 13:55:03 +08:00
Panagiotis Karatakis
94650bf5c6 Fix example 2022-11-21 14:23:36 +02:00
Panagiotis Karatakis
9dfef65a48 Add loader load_many
* modify signature to accept statement outside
* add simple test
2022-11-21 13:54:39 +02:00
Panagiotis Karatakis
f87f6a8e71 WIP add loader skeleton 2022-11-18 16:08:53 +02:00
Chris Tsang
19f0ecd0bc Readme 2022-11-16 14:09:48 +08:00
Chris Tsang
0ac8ff8db7 Update Spyglass 2022-11-16 13:53:09 +08:00
Billy Chan
4d8645ae8b
Support Vector of enum for Postgres (#1210)
* Support Vector of enum for Postgres

* Fix clippy

* Add tests for integer array

* Fix dependency

* Bump sea-query to 0.27.2

Co-authored-by: Chris Tsang <chris.2y3@outlook.com>
2022-11-15 13:50:05 +08:00
Billy Chan
73e56e5531
Filter rows with IS IN enum values expression (#1183)
* [demo] filter rows with enum value is in list

* Fix clippy
2022-11-15 13:20:47 +08:00
Billy Chan
a0b3c58c5f
README 2022-11-14 14:43:14 +08:00
Chris Tsang
d082340848
Composite key cursor pagination (#1216)
* Composite key cursor pagination

* Fix Composite key of 3
2022-11-14 14:26:56 +08:00
Jacob Trueb
cf4657e127
Add Insert query execution without RETURNING clause (#1208) 2022-11-11 11:16:05 +08:00
e-rhodes
69612fa507
Fix typo in error name (#1180)
* fix typo in error name

* fixed typo in docs

Co-authored-by: erhodes <erik@space-nav.com>
2022-11-06 14:18:07 +08:00
Marco Napetti
9d25ee9ac1
use GAT to elide StreamTrait lifetime (#1161) 2022-11-06 12:55:21 +08:00
Marco Napetti
9f2a6dc40b
Fix transaction metrics (#1165) 2022-10-28 01:00:04 +08:00
Billy Chan
fdb3cff29f
SQLite support time crate (#995)
* SQLite support `time` crate

* Serialize time types for SQLite query results
2022-10-27 14:35:39 +08:00
Billy Chan
a766500ebf
Cont. "Enable convert from ActiveModel to Model" (#990)
* Changelog

* Enable convert from ActiveModel to Model (#725)

* feat: enable convert from ActiveModel to Model

* feat: add tests for converting from ActiveModel to Model

* cargo fmt

* Refactoring

Co-authored-by: Billy Chan <ccw.billy.123@gmail.com>

* Fix clippy warnings

* Use error type

Co-authored-by: Chris Tsang <chris.2y3@outlook.com>
Co-authored-by: greenhandatsjtu <40566803+greenhandatsjtu@users.noreply.github.com>
2022-10-23 23:12:22 +08:00
Billy Chan
b91ca2b778
Implements fmt::Display for ActiveEnum (#986)
Co-authored-by: Chris Tsang <chris.2y3@outlook.com>
2022-10-23 22:29:31 +08:00
Billy Chan
b5b9790252
Support array datatype in PostgreSQL (#1132)
* PostgreSQL array (draft)

* Fixup

* Fixup

* Fixup

* Fixup

* Fixup

* Refactoring

* generate entity for Postgres array fields

* Add tests

* Update Cargo.toml

Co-authored-by: Chris Tsang <chris.2y3@outlook.com>
2022-10-23 18:26:57 +08:00
Billy Chan
4df9a2672a
Fixup 2022-10-18 19:06:38 +08:00
Ivan Krivosheev
3219e6ff42
Merge branch 'master' into sea-query-v0.27 2022-10-17 21:50:48 +03:00
Billy Chan
a0fd72e635
Serialize time types as serde_json::Value (#1042)
* Implement `IntoActiveValue` for `time` types.

I tried to implement a [custom active
model](https://www.sea-ql.org/SeaORM/docs/advanced-query/custom-active-model/),
and one of the columns was `Option<TimeDateTimeWithTimeZone>`. I got a
compiler error:

```
error[E0277]: the trait bound `std::option::Option<sea_orm::prelude::TimeDateTimeWithTimeZone>: IntoActiveValue<_>` is not satisfied
```

Looking into the source code, it seemed a simple oversight that this
trait was implemented for the `chrono` types but not the `time` types,
and it was easy enough to fix since there's already a macro to implement
it for new types.

I also noticed that the `time` types are not accounted for in
`src/query/json.rs` while the `chrono` types are, which I assume is also
an oversight. However, I don't have a need for that at this point and
the fix for that seemed less trivial, so I'm just bringing it to your
attention.

Thanks for SeaORM!

* Implement `IntoActiveValue` for `Vec<u8>` types

* Add tests to double check and prevent it from happening again

* Add docs

* Fixup

* Serialize `time` types as `serde_json::Value`

Co-authored-by: Jimmy Cuadra <jimmy@jimmycuadra.com>
2022-10-18 00:04:03 +08:00
Billy Chan
468cbb9baf
Fixup 2022-10-17 22:00:42 +08:00
Chris Tsang
bfab8720b4 Improve error messages #1125 2022-10-17 21:11:16 +08:00
Billy Chan
29da37b4f2
Merge branch 'master' into sea-query-v0.27 2022-10-17 17:53:41 +08:00
Billy Chan
671d79469a
Fixup 2022-10-17 17:25:35 +08:00
Billy Chan
b22db842e4
Run migrations on PostgreSQL schema (#1056)
* Run migrations on PostgreSQL schema

* fmt

* fmt & clippy

* clippy

* [cli] update helper text
2022-10-17 17:16:00 +08:00