Commit Graph

2489 Commits

Author SHA1 Message Date
Jinzhu 530b0a12b4 Add fast path for ValueOf, ReflectValueOf 2022-02-27 22:16:31 +08:00
Jinzhu 4d14ac39ff Merge branch 'a631807682-i5091' 2022-02-27 09:12:35 +08:00
Jinzhu 68bb5379d9 Refactor scan into struct 2022-02-27 09:09:29 +08:00
Jinzhu f2edda50e1 Refactor check missing where condition 2022-02-27 08:40:15 +08:00
chenrui 397b583b8e fix: query scanner in single column 2022-02-25 22:38:48 +08:00
Jinzhu 6a18a15c93 Refactor check missing where condition 2022-02-25 10:48:23 +08:00
jing1 3741f258d0
feat: support gob serialize (#5108) 2022-02-24 10:21:27 +08:00
Michael Nussbaum 45ef1da7e4
Fix naming longer then 64 chars with dots in table (#5045)
Ensures that foreign key relationships and indexes are given
syntactically valid names when their name length exceeds 64 characters
and they contained dot characters within the name. This is most often
relevant when a Postgres table name is fully qualified by including its schema
as part of its name
2022-02-24 10:10:20 +08:00
Jinzhu b1201fce4e Fix update with customized time type, close #5101 2022-02-23 17:48:26 +08:00
Qt 7837fb6fa0
fix typo in TxCommitter interface comment & improve CheckTruth, chek val empty first (#5094)
* fix typo in TxCommitter interface comment

* improve CheckTruth, chek val empty first
2022-02-20 21:19:15 +08:00
codingxh 664c5fb767
strings.replace -> strings.replaceAll (#5095)
Co-authored-by: huquan<xxhh_quan_g@163.com>
2022-02-20 19:55:04 +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
sammyrnycreal 5edc78116f Fixed the use of "or" to be " OR ", to account for words that contain "or" or "and" (e.g., 'score', 'band') in a sql statement as the name of a field. 2022-02-20 08:22:21 +08:00
Jinzhu 48ced75d1d Improve support for AutoMigrate 2022-02-19 23:42:20 +08:00
Jinzhu e0b4e0ec8f Update auto stale days 2022-02-19 17:11:23 +08:00
Jinzhu 0af95f509a Enhance migrator Columntype interface (#5088)
* Update Migrator ColumnType interface

* Update MigrateColumn Test

* Upgrade test drivers

* Fix typo
2022-02-19 17:02:53 +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
li-jin-gou 19ac396a22
fix: isPrintable incorrect (#5076)
* fix: isPrintable incorrect

* fix: isPrintable incorrect

* style: use ReplaceAll instead of Replace
2022-02-15 20:32:03 +08:00
Jinzhu a0aceeb33e Migrator AlterColumn with full data type 2022-02-10 10:40:48 +08:00
Jinzhu df2365057b Remove uncessary switch case 2022-02-09 17:23:16 +08:00
Jinzhu 4eeb839cea Better support Stringer when explain SQL 2022-02-09 15:17:25 +08:00
li-jin-gou d22215129e
fix: replace empty table name result in panic (#5048)
* fix: replace empty name result in panic

* fix: replace empty table name result in panic
2022-02-08 17:06:10 +08:00
Jinzhu 416c4d0653 Test query with Or and soft delete 2022-02-08 16:31:24 +08:00
Jason Lee 93b1a6f7ea
Merge pull request #5043 from Saurabh-Thakre/patch-2 2022-02-04 22:31:21 +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
Jinzhu f19b84d104 Fix github action 2022-01-30 22:46:41 +08:00
Jinzhu 8d293d44dd Fix docker-compose test env for Mac M1 2022-01-30 22:05:38 +08:00
Ning 8c3673286d
preoload not allowd before count (#5023)
Co-authored-by: ningfei <accelerator314@outlook.com>
2022-01-30 18:17:06 +08:00
li-jin-gou c0bea447b9
fix: omit not work when use join (#5034) 2022-01-28 22:16:42 +08:00
Jinzhu 98c4b78e4d Add Session Initialized option 2022-01-28 19:26:10 +08:00
Jinzhu cec0d32aec Support use clause.Expression as argument 2022-01-28 18:48:32 +08:00
dependabot[bot] e5894ca449
chore(deps): bump gorm.io/driver/mysql from 1.2.1 to 1.2.3 in /tests (#4987)
Bumps [gorm.io/driver/mysql](https://github.com/go-gorm/mysql) from 1.2.1 to 1.2.3.
- [Release notes](https://github.com/go-gorm/mysql/releases)
- [Commits](https://github.com/go-gorm/mysql/compare/v1.2.1...v1.2.3)

---
updated-dependencies:
- dependency-name: gorm.io/driver/mysql
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-01-12 13:11:57 +08:00
piyongcai a0d6ff1fea
time.Time, []byte type add alias support. (rebase master) (#4992)
* time.Time, []byte type add alias support

* reformat
2022-01-12 13:11:40 +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
halfcrazy f757b8fdc9
fix: auto migration column order unpredictable (#4980) 2022-01-06 18:55:20 +08:00
kinggo b47cf57f5e
ci: add gofumpt check in reviewdog (#4973) 2022-01-06 15:02:53 +08:00
kinggo 4dd2647967
Merge pull request #4964 from liweitingwt/f_test_error
improve the error handle in tests_test
2021-12-31 14:25:04 +08:00
kinggo 8dde09e0be
fix: generate sql incorrect when use soft_delete and only one OR (#4969)
* fix: generate sql incorrect when use soft_delete and only one OR
2021-12-30 11:47:14 +08:00
liweiting.wt b9667cb747 fix: fix the error handle in tests_test 2021-12-28 18:22:17 +08:00
Emre Güllü 2c3fc2db28
Fix: Where clauses with named arguments may cause generation of unintended queries (#4937) 2021-12-21 19:50:00 +08:00
liweitingwt 24026bf1fe
modify unscoped judge (#4929)
* modify unscoped judge

* modify unscoped judge

Co-authored-by: liweiting <liweiting1995@gmail.com>
2021-12-16 10:41:34 +08:00
Jinzhu adf8f70f06 Upgrade go.mod 2021-12-10 17:50:19 +08:00
piyongcai 380cc64ff5
fix type alias AutoMigrate bug(Add Test Case) (#4888)
* fix type alias AutoMigrate bug. eg

```go
package main

type IDer interface{ GetID() int64 }

// ID will add some method to implement some interface eg: GetID
type ID int64
func (z ID) GetID() int64 { return int64(z) }

type Test struct {
	ID
	Code string `gorm:"size:50"`
	Name string `gorm:"size:50"`
}

func main() {
	db, err := gorm.Open(postgres.New(postgres.Config{
		DSN: `dsn`,
		PreferSimpleProtocol: false,
	}), &gorm.Config{
		Logger:                 logger.Default.LogMode(logger.Info),
		SkipDefaultTransaction: true,
	})
	if err != nil {
		log.Fatal(err)
	}

	if err = db.AutoMigrate(&Test{}); err != nil {
		// invalid embedded struct for Test's field ID, should be struct, but got main.ID
		log.Fatal(err)
	}
}
```

* fix type alias AutoMigrate bug. eg

```go
package main

type IDer interface{ GetID() int64 }

// ID will add some method to implement some interface eg: GetID
type ID int64
func (z ID) GetID() int64 { return int64(z) }

type Test struct {
	ID
	Code string `gorm:"size:50"`
	Name string `gorm:"size:50"`
}

func main() {
	db, err := gorm.Open(postgres.New(postgres.Config{
		DSN:                  `dsn`,
		PreferSimpleProtocol: false,
	}), &gorm.Config{
		Logger:                 logger.Default.LogMode(logger.Info),
		SkipDefaultTransaction: true,
	})
	if err != nil {
		log.Fatal(err)
	}

	if err = db.AutoMigrate(&Test{}); err != nil {
		// invalid embedded struct for Test's field ID, should be struct, but got main.ID
		log.Fatal(err)
	}
}
```

* Add typealis test.

* try to fix golangci-lint
2021-12-10 17:45:36 +08:00
Matthieu MOREL 2a578d767f
Use Golangci configuration file (#4896) 2021-12-10 17:44:11 +08:00
kinggo e5bdd610c3
fix: save not use soft_delete (#4897)
* fix: Save not use soft_delete

* fix: save not use soft_delete

* fix: save not use soft_delete

* fix: save not use soft_delete

Co-authored-by: kinggo <>
2021-12-08 13:58:06 +08:00
Jinzhu 300a23fc31 Check rows.Close error, close #4891 2021-12-02 10:39:24 +08:00
Jinzhu 8627634959 Fix create associations with zero primary key, close #4890 2021-12-02 10:20:16 +08:00
Jinzhu 3a3b82263a Fix auto migration always alert table, close #4198 2021-11-29 20:24:16 +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