Commit Graph

2640 Commits

Author SHA1 Message Date
Jinzhu c1e911f6ed Update tests/go.mod 2023-11-09 18:46:39 +08:00
Kijima Daigo 40f4afe8c2
docs: fix broken link (#6673) 2023-11-07 10:20:06 +08:00
Flc゛ d2fb7a942b
chore(logger): optimize (#6675)
* chore(logger): optimize

* chore(logger): optimize
2023-11-07 10:19:41 +08:00
black-06 9fea15ae75
feat: add MigrateColumnUnique (#6640)
* feat: add MigrateColumnUnique

* feat: define new methods

* delete debug in test
2023-10-30 17:15:49 +08:00
Cr 5adc0ce5f6
test: fix TestEmbeddedRelations (#6639) 2023-10-26 11:58:13 +08:00
gleb 78e905919f
tests/sqilte: enable FOREIGN_KEYS inside OpenTestConnection (#6641) 2023-10-26 11:54:15 +08:00
Franco Liberali 6bef318891
add support for returning in sqlserver (#6585) 2023-10-10 15:03:34 +08:00
dependabot[bot] 1b24081010
chore(deps): bump actions/checkout from 3 to 4 (#6586)
Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-10-10 14:50:45 +08:00
Jeremy Quirke 8c18714462
Don't call MethodByName with a variable arg (#6602)
Go 1.22 goes somewhat toward addressing the issue using reflect
MethodByName disabling linker deadcode elimination (DCE) and the
resultant large increase in binary size because the linker cannot
prune unused code because it might be reached via reflection.

Go Issue golang/go#62257 reduces the number of incidences of this
problem by leveraging a compiler assist to avoid marking functions
containing calls to MethodByName as ReflectMethods as long as the
arguments are constants.

An analysis of Uber Technologies code base however shows that a number
of transitive imports still contain calls to MethodByName with a
variable argument, including GORM.

In the case of GORM, the solution we are proposing is because the
number of possible methods is finite, we will "unroll" this. This
demonstrably shows that GORM is not longer a problem for DCE.

Before
```
% go version
go version devel go1.22-2f3458a8ce Sat Sep 16 16:26:48 2023 -0700 darwin/arm64
% go  test ./... -ldflags=-dumpdep   2>  >(grep -i -e  '->.*<reflectmethod>')
gorm.io/gorm.(*Statement).BuildCondition -> gorm.io/gorm/schema.ParseWithSpecialTableName <ReflectMethod>
type:reflect.Value <UsedInIface> -> reflect.(*Value).Method <ReflectMethod>
type:reflect.Value <UsedInIface> -> reflect.(*Value).MethodByName <ReflectMethod>
ok  	gorm.io/gorm	(cached)
ok  	gorm.io/gorm/callbacks	(cached)
gorm.io/gorm/clause_test.BenchmarkComplexSelect -> gorm.io/gorm/schema.ParseWithSpecialTableName <ReflectMethod>
type:reflect.Value <UsedInIface> -> reflect.(*Value).Method <ReflectMethod>
type:reflect.Value <UsedInIface> -> reflect.(*Value).MethodByName <ReflectMethod>
?   	gorm.io/gorm/migrator	[no test files]
ok  	gorm.io/gorm/clause	(cached)
ok  	gorm.io/gorm/logger	(cached)
gorm.io/gorm/schema_test.TestAdvancedDataTypeValuerAndSetter -> gorm.io/gorm/schema.ParseWithSpecialTableName <ReflectMethod>
type:reflect.Value <UsedInIface> -> reflect.(*Value).Method <ReflectMethod>
type:reflect.Value <UsedInIface> -> reflect.(*Value).MethodByName <ReflectMethod>
?   	gorm.io/gorm/utils/tests	[no test files]
ok  	gorm.io/gorm/schema	(cached)
ok  	gorm.io/gorm/utils	(cached)
```

After

```
%go version
go version devel go1.22-2f3458a8ce Sat Sep 16 16:26:48 2023 -0700 darwin/arm64
%go  test ./... -ldflags=-dumpdep   2>  >(grep -i -e  '->.*<reflectmethod>')
ok  	gorm.io/gorm	(cached)
ok  	gorm.io/gorm/callbacks	(cached)
?   	gorm.io/gorm/migrator	[no test files]
?   	gorm.io/gorm/utils/tests	[no test files]
ok  	gorm.io/gorm/clause	(cached)
ok  	gorm.io/gorm/logger	(cached)
ok  	gorm.io/gorm/schema	(cached)
ok  	gorm.io/gorm/utils	(cached)
```
2023-10-10 14:50:29 +08:00
Mathias Zeller 12ba285a52
*datatypes.JSON in model causes panic on tx.Statement.Changed (#6611)
* do not panic on nil

* more explanation in comments

* get things compact
2023-10-10 14:46:32 +08:00
hjwblog.com 9d8a5bb208
feat: reuse name (#6626) 2023-10-10 14:45:48 +08:00
Samuel N Cui 2095d42b4c
fix: sqlite dialector cannot apply `PRIMARY KEY AUTOINCREMENT` type (#6624)
* fix: sqlite dialector cannot apply `PRIMARY KEY AUTOINCREMENT` type

fix #4760

* feat: add auto increment test

* feat: update sqlite

* feat: update tests deps sqlite to v1.5.4
2023-10-09 17:26:27 +08:00
Jinzhu e57e5d8884 Update go.mod 2023-08-27 15:40:54 +08:00
Jinzhu 653732e1c3 Update go testing versions 2023-08-24 20:19:38 +08:00
Rataj ac07543962
Fixed error message when dialector fails to initialize (#6509)
Let's say we have a problem with DSN which leads to dialector initialize error. However DB connection is not created and for some reason line 184 error provides <nil> even though "db" doesn't exist.

Previously, this code leads to:
panic: runtime error: invalid memory address or nil pointer dereference

This fix now doesn't attempt to close non-existant database connection and instead continues, so the proper error is shown. In my case:
[error] failed to initialize database, got error default addr for network 'localhost' unknown
2023-08-20 19:46:56 +08:00
龚一涛 7e44f73ad3
fix schema GetIdentityFieldValuesMap interface or ptr (#6417)
Co-authored-by: uptutu <yitao.gong@vzenith.com>
2023-08-19 21:35:14 +08:00
Heliner 2c2089760c
add float32 test case (#6530) 2023-08-19 21:33:57 +08:00
qqxhb fef42941ba
feat: rm GetDBConnWithContext method (#6535)
* feat: rm contextconnpool method

* feat: nil
2023-08-19 21:33:31 +08:00
weih bae684b363
fix(clause): when the value of clause.Eq is an empty array, the SQL should be IN (NULL) (#6503) 2023-08-10 13:34:33 +08:00
Jinzhu 15162afaf2 Support GetDBConnWithContext PreparedStmtDB 2023-08-10 13:30:57 +08:00
fayvori 3c34bc2f59
refactor: Regex description (#6507)
* Mirror cleanup

* Regex description

---------

Co-authored-by: Ignat Belousov <ignatbelousov@Ignats-MacBook-Pro.local>
2023-08-07 16:35:19 +08:00
Aayush Acharya f473761813
fix: added `SkipHooks` in db `getInstance()` (#6484) 2023-08-04 10:35:59 +08:00
San Ye 193c454cf4
keep float precision in ExplainSQL (#6495) 2023-08-04 10:31:18 +08:00
Saeid 1fb26ac90e
test: coverage for tabletype added (#6496)
* test: coverage for tabletype added

* test: tidb exclueded

---------

Co-authored-by: Saeid Saeidee <s.saeidee@sensysgatso.com>
2023-08-04 10:30:07 +08:00
Jinzhu a7f01bd1b2 Test Pluck with customized type 2023-07-25 10:47:19 +08:00
Saeid c10f807d3c
test: coverage for foreign key violation err (#6403)
* test: coverage for foreign key violation err

* test: enabled foreign keys constraint for sqlite

* test: enabled mysql& mssql for ErrForeignKeyViolate

* test: disabled mysql & updated sqlserver driver version

* test: skipped tidb

---------

Co-authored-by: Saeid Saeidee <s.saeidee@sensysgatso.com>
2023-07-12 21:21:22 +08:00
Saeid 2066138684
ci: fix mariadb mysqladmin (#6401)
Co-authored-by: Saeid Saeidee <s.saeidee@sensysgatso.com>
2023-06-11 07:42:18 +08:00
Saeid c2d571cbc8
test: coverage for duplicated key err (#6389)
* test: ErrDuplicatedKey coverage added

* test: updated sqlserver version

* test: removed sqlserver

* test: support added for sqlserver

---------

Co-authored-by: Saeid Saeidee <s.saeidee@sensysgatso.com>
2023-06-10 21:05:19 +08:00
Johannes Riecken 7dd702d379
Fix incorrect documentation comment (has many -> has one) (#6382) 2023-06-07 15:02:30 +08:00
Nuno Cruces 7157b7e375
fix: database/sql.Scanner should not retain references (#6380) 2023-06-07 15:02:07 +08:00
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
东方上人 740f2be453
fix: begin transaction fail, rollback panic (#6365) 2023-05-31 19:21:51 +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
black-06 11fdf46a9f
fix: save with hook (#6285) (#6294) 2023-05-26 10:28:02 +08:00
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
Saeid 8197c00def
refactor: error translator test (#6350)
Co-authored-by: Saeid Saeidee <s.saeidee@sensysgatso.com>
2023-05-25 11:10:00 +08:00
Muhammad Amir Ejaz 001738be49
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
2023-05-21 21:27:22 +08:00
Avinaba Bhattacharjee 6698ba709e
renamed License to LICENSE (#6336) 2023-05-21 21:24:00 +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
Jinzhu c3d7d08b9a Clear SET clause after build SQL 2023-05-15 15:43:44 +08:00
aclich 63534145fd
fix: 🐛 embedded struct test failed with custom datatypes (#6311)
* fix: 🐛 embedded struct test failed with custom datatypes

Fix the pointer embedded struct within custom datatypes and *time.time
should be nil issue.

* fix: 🐛 change test case to avoid mssql driver issue

change test cases from bytes to string to avoid mssql driver issue
2023-05-15 09:59:26 +08:00
John Mai e61b98d696
feat: migrator support table comment (#6225)
* feat: migrator support table comment

* feat: migrator support tableType.It like ColumnTypes

* Avoid updating the go.mod file.

* Update tests_all.sh

* Update migrator.go

* remove Catalog() & Engine() methods.

* remove CatalogValue & EngineValue.

---------

Co-authored-by: Jinzhu <wosmvp@gmail.com>
2023-05-05 15:58:27 +08:00
black-06 32045fdd7d
feat: unscoped association (#5899) (#6246)
* feat: unscoped association (#5899)

* modify name because mysql character is latin1

* work only on has association

* format

* Unscoped on belongs_to association
2023-05-04 19:30:45 +08:00
hykuan 67642abfff
fix: 🐛 numeric types in pointer embedded struct test failed (#6293) 2023-05-04 19:29:31 +08:00
hanwn aeb298635b
debug: use slice Stale sort (#6263)
Co-authored-by: hanwang <hanwang.7721@bytedance.com>
2023-04-26 22:19:46 +08:00
Cr 407bedae0a
fix: nested joins alias (#6265) 2023-04-26 22:19:32 +08:00
yikakia 1f763c81cb
fix typo chainable_api.go (#6266) 2023-04-26 22:19:06 +08:00