Commit Graph

96 Commits

Author SHA1 Message Date
Lev Zakharov 661781a3d7
feat: add *sql.DB connector that uses database context (#6366)
* feat: add SQLConnector

* rename
2023-06-05 16:25:05 +08:00
KantaHasegawa 5eaccaa624
reafactor: add nil detection when sqldb return (#6373)
* reafactor: add null detection when sqldb return

* refactor: Detecting nil in dbConnector.GetDBConn()

* refactor: Revert partial code from c1ea730367

* fix: fix if statement
2023-06-05 16:24:00 +08:00
Lev Zakharov 7a76c042e6
refactor: remove unnecessary prepared statement allocation (#6374) 2023-06-05 16:23:17 +08:00
black c1ea730367 fix: avoid panic when open fails 2023-06-01 15:22:21 +08:00
mohammad ali 26663ab9bf
max identifier length changed to 63 (#6337)
* max identifier length changed to 63

* default maxIdentifierLength is 64

* renamed License to LICENSE (#6336)

* Added support of "Violates Foreign Key Constraint" (#6329)

* Added support of "Violates Foreign Key Constraint"

Updated the translator and added the support of "foreign key constraint violation". For this, this error type is needed here.

* changed the description of ErrForeignKeyViolated

* refactor: error translator test (#6350)

Co-authored-by: Saeid Saeidee <s.saeidee@sensysgatso.com>

* 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>

* fix: save with hook (#6285) (#6294)

---------

Signed-off-by: 王柳洋 <wangliuyang.520@bytedance.com>
Co-authored-by: Avinaba Bhattacharjee <avinababhattacharjee2002@gmail.com>
Co-authored-by: Muhammad Amir Ejaz <37077032+codingamir@users.noreply.github.com>
Co-authored-by: Saeid <sk.saeidee@yahoo.com>
Co-authored-by: Saeid Saeidee <s.saeidee@sensysgatso.com>
Co-authored-by: wangliuyang <54885906+wangliuyang520@users.noreply.github.com>
Co-authored-by: 王柳洋 <wangliuyang.520@bytedance.com>
Co-authored-by: black-06 <hello.bug@foxmail.com>
2023-05-30 10:00:48 +08:00
Zhiheng Lin 32fc201554
fix: avoid coroutine leaks when the dialecter initialization fails. (#6249)
Co-authored-by: Kevin Lin <kevin.lin@shopee.com>
2023-04-21 22:17:21 +08:00
Saeid Kanishka b444011d09
refactor: translatorError flag added for backward compatibility (#6178)
Co-authored-by: Saeid Saeidee <s.saeidee@sensysgatso.com>
2023-03-24 10:07:05 +08:00
Saeid Kanishka 707d70a542
refactor: translate error only when it is not nil (#6133)
* refactor: translate error only when it is not nil

* refactor: fix the error flow

* refactor: update the error if checks

* Update gorm.go

---------

Co-authored-by: Saeid Saeidee <s.saeidee@sensysgatso.com>
Co-authored-by: Jinzhu <wosmvp@gmail.com>
2023-03-10 16:51:27 +08:00
Saeid Kanishka 85eaf9eeda
feat: Unique Constraint Violation error translator for different drivers (#6004)
* feat: duplicated key error translator for different drivers

* test: removed the dependency

* test: fixed broken tests

* refactor: added ErrorTransltor interface

* style: applied styler

---------

Co-authored-by: Saeid Saeidee <s.saeidee@sensysgatso.com>
2023-03-06 14:03:31 +08:00
Haibo da2b2861de
fix(migrator): ignore relationships when migrating #5913 (#5946) 2023-01-01 19:54:28 +08:00
Jinzhu ddd3cc2502 Add ParameterizedQueries option support for logger, close #5288 2022-12-25 11:37:23 +08:00
jessetang cef3de694d
cleanup(prepare_stmt.go): unnecessary map delete (#5849) 2022-11-13 11:12:09 +08:00
Cr 0b7113b618
fix: prepare deadlock (#5568)
* fix: prepare deadlock

* chore[ci skip]: code style

* chore[ci skip]: test remove unnecessary params

* fix: prepare deadlock

* fix: double check prepare

* test: more goroutines

* chore[ci skip]: improve code comments

Co-authored-by: Jinzhu <wosmvp@gmail.com>
2022-09-30 18:13:36 +08:00
kinggo 12237454ed fix: use preparestmt in trasaction will use new conn, close #5508 2022-09-22 16:47:43 +08:00
enwawerueli 573b9fa536 fix: correct grammar 2022-08-15 10:28:36 +08:00
Jinzhu 75720099b5 Create a new db in FindInBatches 2022-07-18 18:07:05 +08:00
ZhangShenao 8333844f71
fix variable shadowing (#5212)
Co-authored-by: Shenao Zhang <shenao.zhang@shopee.com>
2022-03-31 20:57:20 +08:00
Cao Manh Dat 29a8557384 ToSQL should enable SkipDefaultTransaction by default 2022-03-03 09:18:01 +07:00
Jinzhu a0aceeb33e Migrator AlterColumn with full data type 2022-02-10 10:40:48 +08:00
Jinzhu 98c4b78e4d Add Session Initialized option 2022-01-28 19:26:10 +08:00
Jason Lee 8de266b4a7
Add ToSQL support to generate SQL string. (#4787)
* Add db.ToSQL method for generate SQL string.

* Improve sql builder test for all dialects.

Improve assertEqualSQL test helper for ignore quotes in SQL.
2021-11-01 17:08:54 +08:00
heige c13f3011f9
feat: adjust SetupJoinTable func if..else code (#4680) 2021-10-08 11:05:50 +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
Chris Faulkner 15a46bc042
Fix some typos (#4294) 2021-04-19 21:03:39 +08:00
Jinzhu d278ca49ef sort GORM options before apply 2021-04-09 11:43:24 +08:00
Jinzhu ad53074f1d Pass db error to new instance 2021-04-09 11:07:14 +08:00
Jinzhu 73c6d3e64e Add AfterInitialize error 2021-03-29 18:36:01 +08:00
Jinzhu 0eba7a9ed1 Fix apply option 2021-03-26 14:20:42 +08:00
Jinzhu a9fe025ef5 Add GetDBConnector interface 2021-03-19 15:55:38 +08:00
Jinzhu 912360097a Fix Scopes with Migrator, close #4145 2021-03-11 10:36:14 +08:00
heige bc347758e5
for Config.cacheStore store PreparedStmtDB key (#4149) 2021-03-07 10:57:22 +08:00
heige 495ec4bd87
invalid db error and value and invalid value length error (#4151) 2021-03-07 10:56:32 +08:00
Jinzhu 294625759c Fix after initialize db callback 2021-03-05 14:12:55 +08:00
Jinzhu 1476b2f7d4 Fix apply config 2021-03-04 20:37:44 +08:00
Jinzhu 0157099576 Use functional options 2021-03-04 17:40:25 +08:00
Jinzhu 3d3208ed60 initialize config plugins 2021-02-03 16:27:49 +08:00
Jinzhu 7598204dc3 Support `FullSaveAssociations` for association mode, close #4010 2021-01-29 16:55:26 +08:00
Jinzhu fe553a7c1a Fix prepared statement in transaction mode can't be shared in normal operations, close #3927 2021-01-10 16:46:06 +08:00
Qt f9131e309d
reduce DB's Use method complexity and make it easier to understand (#3930) 2021-01-10 10:15:48 +08:00
Jinzhu a5bfe2f39d Keep Error for new Session 2021-01-07 11:45:40 +08:00
Jinzhu 468152d45b Add DisableNestedTransaction support 2020-12-16 19:33:35 +08:00
Jinzhu 0c12a4c360 Add CreateBatchSize option 2020-12-02 14:59:50 +08:00
Luis Guillermo Gómez 47ffd0bef4
Select all fields in SQL queries avoiding the SELECT * FROM (#3731)
* Select all fields in SQL queries avoiding the SELECT * FROM

* Select table name with fields in SQL queries

* Use QueryFields to execute the SQL query with all fields of the table
2020-11-20 15:38:25 +08:00
Jinzhu 9df9f7688b Change UpdatingColumn to SkipHooks 2020-11-17 17:49:43 +08:00
Jinzhu 26504f5cae Use NewDB to replace WithConditions for Session 2020-11-17 16:28:37 +08:00
Jinzhu f6e1786ca2 Add skip hooks support 2020-11-17 15:19:58 +08:00
Jinzhu 1e241aa645 Reduce GC alloc 2020-11-10 21:23:20 +08:00
Jinzhu bdb30da0a7 Fix copy lock for prepared statement, close #3642, #3607 2020-10-21 15:47:46 +08:00
Jinzhu c0de3c5051 Support FullSaveAssociations Mode, close #3487, #3506 2020-09-24 19:29:15 +08:00
Jinzhu f2adb088c5 Set field size from primary fields to foreign fields 2020-09-03 16:11:15 +08:00