Commit Graph

143 Commits

Author SHA1 Message Date
wangliuyang 812bb20c34
fix(nested transaction): SavePoint SQL Statement not support in Prepared Statements (#6220)
* test: add nested transaction and prepareStmt coexist test case

note: please test in the MySQL environment

Change-Id: I0db32adc5f74b0d443e98943d3b182236583b959
Signed-off-by: 王柳洋 <wangliuyang.520@bytedance.com>

* fix(nested transaction): SavePoint SQL Statement not support in Prepared Statements

1. SavetPoint SQL Statement not support in Prepared Statements
 e.g. see mysql8.0 doc: https://dev.mysql.com/doc/refman/8.0/en/sql-prepared-statements.html

Change-Id: I082012db9b140e8ec69764c633724665cc802692
Signed-off-by: 王柳洋 <wangliuyang.520@bytedance.com>

* revert(transaction_api): remove savepoint name pool,meaningless

Change-Id: I84aa9924fc54612005a81c83d66fdf8968ee56ad
Signed-off-by: 王柳洋 <wangliuyang.520@bytedance.com>

---------

Signed-off-by: 王柳洋 <wangliuyang.520@bytedance.com>
Co-authored-by: 王柳洋 <wangliuyang.520@bytedance.com>
2023-05-26 10:24:28 +08:00
201430098137 f5837deef3
fix:clickhouse error not capture(#6277) (#6321)
Co-authored-by: zhuangg <zhuangg@mingyuanyun.com>
2023-05-17 10:15:41 +08:00
cyhone 5d1cdfef2e
avoid starting a transaction when performing only one insert operation in CreateInBatches function (#6174) 2023-03-23 14:02:35 +08:00
black-06 1a7ea98ac5
fix: count with group (#6157) (#6160)
* fix: count with group (#6157)

* add an easy-to-understand ut
2023-03-23 11:19:53 +08:00
black-06 0c7e575f19
save should be idempotent #6139 (#6149) 2023-03-23 11:18:57 +08:00
Jinzhu cc2d46e5be reuse name for savepoints from nested transaction, close #6060 2023-03-10 17:42:38 +08:00
Jinzhu f3874339ef Fix Save with stress tests 2023-03-02 17:22:51 +08:00
Nate Armstrong f3c6fc2533
Update func comments in chainable_api and FirstOr_ (#5935)
Add comments to functions in chainable_api. Depending on the method,
these comments add some additional context or details that are relevant
when reading the function, link to the actual docs at gorm.io/docs, or
provide examples of use. These comments should make GORM much more
pleasant to use with an IDE that provides hoverable comments, and are
minimal examples.

Also add in-code documentation to FirstOrInit and FirstOrCreate.

Almost all examples are directly pulled from the docs, with short
comments explaining the code. Most examples omit the `db.Model(&User{})`
for brevity, and would not actually work.

Co-authored-by: Nate Armstrong <nate.armstrong@eluv.io>
2022-12-23 16:51:01 +08:00
wjw1758548031 f931def33d
clear code syntax (#5889)
* clear code syntax

* clear code syntax
2022-12-01 20:25:53 +08:00
Jinzhu f91313436a Fix group by with count logic 2022-11-21 11:10:56 +08:00
Cr 342310fba4
fix(FindInBatches): throw err if pk not exists (#5868) 2022-11-21 10:49:27 +08:00
robhafner e8f48b5c15
fix: limit=0 results (#5735) (#5736) 2022-10-07 20:14:14 +08:00
Bruce MacKenzie f29afdd329
Rewrite of finisher_api Godocs (#5618) 2022-09-09 11:16:41 +08:00
Bruce MacKenzie a35883590b
update Delete Godoc to describe soft delete behaviour (#5554) 2022-08-11 11:38:04 +08:00
Jinzhu 75720099b5 Create a new db in FindInBatches 2022-07-18 18:07:05 +08:00
Jinzhu 9fd73ae4f1 Revert "use callback to handle transaction"
This reverts commit 93f28bc116.
2022-07-07 15:06:48 +08:00
Joe 93f28bc116 use callback to handle transaction
- make transaction have before and after hooks, so plugin can have hack before
or after transaction
2022-06-24 10:33:39 +08:00
t-inagaki@hum_op dc1ae394f3
fixed FirstOrCreate not handled error when table is not exists (#5367)
* fixed FirstOrCreate not handled error when table is not exists

* delete useless part
2022-05-28 22:18:43 +08:00
Cr 7496c3a56e
fix: trx in hooks clone stmt (#5338)
* fix: trx in hooks

* chore: format by gofumpt
2022-05-17 14:13:41 +08:00
Jinzhu 6a6dfdae72 Refactor FirstOrCreate, FirstOrInit 2022-04-26 17:16:48 +08:00
Cr b49ae84780
fix: FindInBatches with offset limit (#5255)
* fix: FindInBatches with offset limit

* fix: break first

* fix: FindInBatches Limit zero
2022-04-17 09:58:33 +08:00
Jinzhu d421c67ef5 Remove ErrRecordNotFound error from log when using Save 2022-04-14 10:51:39 +08:00
Cr a65912c588
fix: FirstOrCreate RowsAffected (#5250) 2022-04-13 15:52:07 +08:00
Jinzhu 0729261b62 Support double ptr for Save 2022-04-08 14:23:25 +08:00
ZhangShenao f7b52bb649
unify db receiver name (#5215)
Co-authored-by: Shenao Zhang <shenao.zhang@shopee.com>
2022-04-01 08:35:16 +08:00
Jinzhu 6befa0c947 Refactor preload error check 2022-03-17 11:22:25 +08:00
Jinzhu 4e523499d1 Refactor Tx interface 2022-03-01 16:59:50 +08:00
lianghuan 996b96e812 Add TxConnPoolBeginner and Tx interface 2022-03-01 16:59:50 +08:00
Gilad Weiss f3547e00cc
Inherit clone flag (NewDB) on transaction creation (#5012)
* Inherit clone flag (NewDB) on transaction creation

I find it very reassuring to know that after a finisher API, I get a clean db object for my next queries.
If you look at the example in https://gorm.io/docs i’d see many queries running one after the other.. but in reality they wouldn’t work as the they are portrayed and that’s because in default mode NewDB is false and will make all the clauses stay even after a finisher API.

My solution is just to have the value of the clone flag in the “parent” db object, be injected to its children transactions.

* Fix typo
2022-02-20 08:33:12 +08:00
Jinzhu 39d84cba5f Add serializer support (#5078)
* Update context

* Update GormFieldValuer

* Add Serializer

* Add Serializer Interface

* Refactor gorm field

* Refactor setter, valuer

* Add sync.Pool

* Fix test

* Add pool manager

* Fix pool manager

* Add poolInitializer

* Add Serializer Scan support

* Add Serializer Value method

* Add serializer test

* Finish Serializer

* Fix JSONSerializer for postgres

* Fix JSONSerializer for sqlserver

* Test serializer tag

* Add unixtime serializer

* Update go.mod
2022-02-19 17:02:53 +08:00
Saurabh Thakre 581a879bf1
Added comments to existing methods
Added two comments to describe FirstOrInit and FirstOrCreate methods.
2022-01-31 17:26:28 +05:30
Ning 8c3673286d
preoload not allowd before count (#5023)
Co-authored-by: ningfei <accelerator314@outlook.com>
2022-01-30 18:17:06 +08:00
Jinzhu eae73624ad Fix return failed to begin transaction error when failed to start a transaction 2022-01-07 10:04:35 +08:00
kinggo 0df42e9afc
feat: add `Connection` to execute multiple commands in a single connection; (#4982) 2022-01-07 09:49:56 +08:00
Jinzhu 300a23fc31 Check rows.Close error, close #4891 2021-12-02 10:39:24 +08:00
kinggo d8a710cba2
fix: count() when use group by and only find one record (#4885)
Co-authored-by: 李龙 <lilong.21@bytedance.com>
2021-11-29 20:14:23 +08:00
Jinzhu 270e38c518 Fix duplicated error when Scan, close #4525 2021-11-29 14:23:10 +08:00
Jinzhu b23c3b290e Don't query with primary key when using Save 2021-11-08 18:49:59 +08:00
kinggo c170af11e9
fix connections leak (#4826)
* fix connections leak

* fix connections leak

* fix connections leak

* fix connections leak

Co-authored-by: 李龙 <lilong.21@bytedance.com>
2021-11-03 13:39:52 +08:00
Jinzhu af3fbdc2fc Improve returning support 2021-10-26 22:40:14 +08:00
kinggo 6864a24150
fix:remove the tableName judgment in pluck (#4731) 2021-09-27 22:11:29 +08:00
Jinzhu 12bbde89e6 Fix Scan with interface 2021-09-17 14:04:19 +08:00
Jinzhu 61b018cb94 Fix count with selected * 2021-09-16 11:17:54 +08:00
River 1bb0d8732d
feat: count accpet `db`.`table` (#4626)
* feat: count accpet `db`.`table`

* fix: logic fix
2021-08-20 17:37:21 +08:00
Jinzhu 83530ec659 Fix delete order by clause when counting, close #4478 2021-07-13 21:17:43 +08:00
wuwenchi 8bd8d38fe9 Fix Pluck's usage #4473 2021-06-26 21:23:16 +08:00
Jinzhu 8e67a08774 Fix Scopes with Row, close #4465 2021-06-18 15:38:20 +08:00
Tony a0bddccfe1
Use count(*) instead of count(1) include NULL and non-NULL rows(SQL-92). (#4453) 2021-06-11 21:51:18 +08:00
heige 50e85e14d4
Code optimize (#4415)
* optimize gormSourceDir replace

* fmt.Errorf adjust and Optimize for-break

* strings trim

* feat: avoid using the same name field and if..else optimization adjustment

* optimization callbacks/create.go Create func if...else logic

* fix: callbacks/create.go Create func

* fix FileWithLineNum func and add gormSourceDir unit test

* remove debug print and utils_filenum_test.go
2021-06-10 10:21:28 +08:00
liamrfell 00b252559f
Fix: FirstOrCreate slice out of bounds error when using 'Assigns' (#4436)
Co-authored-by: Liam Fell <liam@lot.to>
2021-06-07 10:39:24 +08:00