Commit Graph

2712 Commits

Author SHA1 Message Date
black-06 e4e23d26d2
fix: nested preload with join panic when find (#6877) 2024-03-09 21:27:19 +08:00
jessetang c4c9aa45e3
fix(scan.go): reflect.MakeSlice passes in the reflect.Array type (#6880) 2024-03-09 17:39:01 +08:00
Cr 9efae659cb
test: namer identifier lenght (#6872) 2024-03-09 17:31:28 +08:00
hishope f17a75242e Signed-off-by: hishope <csqiye@126.com>
fix some typos in tests

Signed-off-by: hishope <csqiye@126.com>
2024-03-07 16:19:17 +08:00
tsuba3 3e2c4fc446
Fix regression in db.Not introduced in v1.25.6. (#6844)
* Fix regression in db.Not introduced in 940358e.

* Fix
2024-03-05 10:23:51 +08:00
Chef f118e55db5
Add unittest test helper function ConvertSliceOfMapToValuesForCreate (#6854) 2024-03-05 10:22:57 +08:00
Chef 52404cddbb
CHORE add unittest test function ConvertMapToValueForCreate (#6846)
* CHORE add unittest test function  ConvertMapToValueForCreate

* CHORE move the test cases located in the files convert_map_test.go and visit_map_test.go into the file helper_test.go.
2024-02-27 10:48:04 +08:00
M Dmitry d81ae6f701
Fixed: panic on nullable value with multiple foreign key usage (#6839)
See: https://github.com/go-gorm/playground/pull/537
2024-02-19 11:42:25 +08:00
black-06 8fb9a31775
refactor: part 2 of distinguish between Unique and UniqueIndex (#6822) 2024-02-06 19:48:40 +08:00
jasonchuan 9514d5f9e6
let limit and offset use bind parameter (#6806)
* let limit and offset use bind parameter

* format

* format limt_test

* try again

* fix test case fro connpool

* adding driverName for postgres  ,if not to do so, the stmt vars will be added  a wrong  one called pgx.QueryExecModeSimpleProtocol  ,  causing the SQL with limit  problem  need 1 parameter ,but given two.

* delete trunk files

* restore the test_test.go

* restore test_test.go

* driver/postgres->v1.5.5

* change postgres version rollback to 1.5.4

---------

Co-authored-by: chenchuan <chenchuan@360.cn>
Co-authored-by: jason_chuan <jason_chuan@126.com>
2024-02-06 10:54:40 +08:00
black-06 46816ad31d
refactor: distinguish between Unique and UniqueIndex (#6386)
* refactor: distinguish between UniqueIndex and Index

* add test

* add ParseIndex test

* modify unique to constraint

* modify unique to constraint

* fix MigrateColumnUnique

* fix test

* fix unit test

* update test mod

* add MigrateColumnUnique to Migrator interface

* fix format lint

* add comment

* go mod tidy

* revert: revert MigrateColumn

* resolve conflicts
2024-02-04 15:49:19 +08:00
black-06 418ee3fc19
fix: preload shouldn't overwrite the value of join (#6771)
* fix: preload shouldn't overwrite the value of join

* fix lint

* fix: join may automatically add nested query
2024-01-29 11:34:57 +08:00
dependabot[bot] e043924fe7
chore(deps): bump actions/cache from 3 to 4 (#6802)
Bumps [actions/cache](https://github.com/actions/cache) from 3 to 4.
- [Release notes](https://github.com/actions/cache/releases)
- [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md)
- [Commits](https://github.com/actions/cache/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/cache
  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>
2024-01-29 10:34:20 +08:00
Jacky 0123dd4509
fix: ignore .gen.go suffix in logger to get the real caller when using gen #6697 (#6785) 2024-01-12 17:09:22 +08:00
Jinzhu 940358e0dd Fix tests doesn't follow https://gorm.io/docs/method_chaining.html convention 2024-01-12 16:42:21 +08:00
iTanken 87decced23
fix: ExplainSQL using consecutive pairs of escaper in SQL string represents an escaper (#6766)
Preventing it from being interpreted as the string terminator. This is a widely used escape mechanism in SQL standards and is applicable in most relational databases.
2023-12-28 19:53:36 +08:00
Stephano George 436cca753c
fix: join and select mytable.* not working (#6761)
* fix: select mytable.* not working

* fix: select mytable.*: will not match `mytable."*"`.
feat: increase readability of code matching table name column name
2023-12-23 21:19:41 +08:00
Alexis Viscogliosi a2cac75218
feature: bring custom type and id column name to polymorphism (#6716)
* feature: bring custom type and id column name to polymorphism

* relationship: better returns for hasPolymorphicRelation

* fix: tests
2023-12-15 16:36:08 +08:00
Maciej Laskowski b9ebdb13c7
Making locking parameters more intuitive (#6719)
* Making locking parameters more intuitive

* remove dedicated type
2023-12-15 16:32:56 +08:00
BugKillerPro 2fb4928aa8
refactor: Resolve implicit memory aliasing in for loop (#6730) 2023-12-15 16:31:23 +08:00
Franco Liberali f0af94cd16 add test to show that update from works 2023-12-04 11:50:58 +08:00
FangSqing 3207ad6033
map insert support return increment id (#6662) 2023-11-15 21:32:56 +08:00
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