Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch to latest #31

Merged
merged 87 commits into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
d41fb3a
Refactor dummy driver QuoteTo method
jinzhu Sep 11, 2021
61b018c
Fix count with selected *
jinzhu Sep 16, 2021
12bbde8
Fix Scan with interface
jinzhu Sep 17, 2021
da16a8a
Update updated_at when upserting with Create OnConflict
jinzhu Sep 17, 2021
ab35533
Fix scan with interface
jinzhu Sep 17, 2021
d67120a
Bump gorm.io/driver/sqlite from 1.1.4 to 1.1.5 in /tests (#4701)
dependabot[bot] Sep 20, 2021
199c852
Bump gorm.io/driver/postgres from 1.1.0 to 1.1.1 in /tests (#4699)
dependabot[bot] Sep 20, 2021
5202529
fix (clause/expression): Allow sql stmt terminator (#4693)
jimlambrt Sep 20, 2021
6864a24
fix:remove the tableName judgment in pluck (#4731)
Sep 27, 2021
002bf78
Fix Join condition with DB, close #4719
jinzhu Sep 28, 2021
c4a2e89
Fix Join condition with DB
jinzhu Sep 28, 2021
851fea0
fix: QuoteTo not fully support raw mode (#4735)
tr1v3r Sep 29, 2021
0b6bd33
Update `tests.yml` (#4741)
s-takehana Oct 8, 2021
57d927d
Bump gorm.io/driver/postgres from 1.1.1 to 1.1.2 in /tests (#4740)
dependabot[bot] Oct 8, 2021
5d91dda
fixed belongs_to & has_one reversed if field same (proper fix) (#4694)
paraswaykole Oct 8, 2021
c13f301
feat: adjust SetupJoinTable func if..else code (#4680)
daheige Oct 8, 2021
e3fc49a
feat: ajust PreparedStmtDB unlock location and BuildCondition if logi…
daheige Oct 8, 2021
b46e2af
fix : update miss where's condition when primary key use "<-:create" …
Oct 8, 2021
d4c838c
Upgrade sqlite driver
jinzhu Oct 8, 2021
6312d86
Support specify select/omit columns with table
jinzhu Oct 8, 2021
bfda75d
Support specify select/omit columns with table
jinzhu Oct 9, 2021
418c60c
fixed: clauseSelect.Columns missed when use Join And execute multiple…
Oct 9, 2021
ec58e33
fixed:panic when create value from nil struct pointer. (#4771)
Oct 12, 2021
696092e
update tests' go.mod and tests_all.sh (#4774)
Oct 13, 2021
19cf645
feat: Convert SQL nulls to zero values (ConvertNullToZeroValues)
jimlambrt Sep 12, 2021
b27095e
Refactor Convert SQL null values to zero values for model fields whic…
jinzhu Oct 13, 2021
9a5ba37
Merge branch 'hashicorp-jimlambrt-null-without-ptrs'
jinzhu Oct 13, 2021
a3bd9c3
fix: automigrate error caused by indexes while using dynamic table name
xwjdsh Oct 12, 2021
38e55f1
Merge pull request #4773 from xwjdsh/master
huacnlee Oct 19, 2021
d321190
Refactor ParseWithSchemaTable method and improve test. (#4789)
huacnlee Oct 25, 2021
af3fbdc
Improve returning support
jinzhu Oct 26, 2021
835d7bd
Add returning support to delete
jinzhu Oct 27, 2021
e953880
Add returning tests
jinzhu Oct 28, 2021
9f53395
Add dest value if current size equal zero
jinzhu Oct 28, 2021
9635d25
Fix query with uninitialized map
jinzhu Nov 1, 2021
8de266b
Add ToSQL support to generate SQL string. (#4787)
huacnlee Nov 1, 2021
7b92790
Bump gorm.io/driver/sqlserver from 1.1.2 to 1.2.0 in /tests (#4820)
dependabot[bot] Nov 1, 2021
c170af1
fix connections leak (#4826)
Nov 3, 2021
4c8810a
Refactor if logic (#4683)
daheige Nov 4, 2021
d9d5c4d
Fix self-referential belongs to constraint (#4801)
mgovilla Nov 8, 2021
b23c3b2
Don't query with primary key when using Save
jinzhu Nov 8, 2021
ca7accd
Fix preload all associations with inline conditions, close #4836
jinzhu Nov 8, 2021
5daa413
Stabilize schema.FieldsWithDefaultDBValue's order, close #4643
jinzhu Nov 8, 2021
33bc56c
feat(update): update when has SET clause
tr1v3r Nov 9, 2021
5e64ac7
feat(migrator,migrator/migrator.go,tests/migrate_test.go) : Get multi…
dino-ma Nov 13, 2021
11d5c34
Bump github.com/jinzhu/now from 1.1.2 to 1.1.3 (#4865)
dependabot[bot] Nov 23, 2021
0f8e861
Bump github.com/jinzhu/now from 1.1.2 to 1.1.3 in /tests (#4866)
dependabot[bot] Nov 23, 2021
cff7845
Bump gorm.io/driver/mysql from 1.1.3 to 1.2.0 in /tests (#4856)
dependabot[bot] Nov 23, 2021
b8f33a4
Add unused argument (#4871)
jinzhu Nov 23, 2021
9d5f315
feat: go code style adjust and optimize code for callbacks package (#…
daheige Nov 29, 2021
e1b4c06
Fix FullSaveAssociations, close #4874
jinzhu Nov 29, 2021
270e38c
Fix duplicated error when Scan, close #4525
jinzhu Nov 29, 2021
92d5a95
Fix tests
jinzhu Nov 29, 2021
45e804d
Fix call valuer interface when using nil value
jinzhu Nov 29, 2021
27e2753
Fix create duplicated value when updating nested has many relationshi…
jinzhu Nov 29, 2021
d8a710c
fix: count() when use group by and only find one record (#4885)
Nov 29, 2021
3a3b822
Fix auto migration always alert table, close #4198
jinzhu Nov 29, 2021
8627634
Fix create associations with zero primary key, close #4890
jinzhu Dec 2, 2021
300a23f
Check rows.Close error, close #4891
jinzhu Dec 2, 2021
e5bdd61
fix: save not use soft_delete (#4897)
Dec 8, 2021
2a578d7
Use Golangci configuration file (#4896)
mmorel-35 Dec 10, 2021
380cc64
fix type alias AutoMigrate bug(Add Test Case) (#4888)
piyongcai-liucai Dec 10, 2021
adf8f70
Upgrade go.mod
jinzhu Dec 10, 2021
24026bf
modify unscoped judge (#4929)
liweitingwt Dec 16, 2021
2c3fc2d
Fix: Where clauses with named arguments may cause generation of unint…
emregullu Dec 21, 2021
b9667cb
fix: fix the error handle in tests_test
liweitingwt Dec 28, 2021
8dde09e
fix: generate sql incorrect when use soft_delete and only one OR (#4969)
Dec 30, 2021
4dd2647
Merge pull request #4964 from liweitingwt/f_test_error
Dec 31, 2021
b47cf57
ci: add gofumpt check in reviewdog (#4973)
Jan 6, 2022
f757b8f
fix: auto migration column order unpredictable (#4980)
halfcrazy Jan 6, 2022
0df42e9
feat: add `Connection` to execute multiple commands in a single conne…
Jan 7, 2022
eae7362
Fix return failed to begin transaction error when failed to start a t…
jinzhu Jan 7, 2022
a0d6ff1
time.Time, []byte type add alias support. (rebase master) (#4992)
piyongcai-liucai Jan 12, 2022
e5894ca
chore(deps): bump gorm.io/driver/mysql from 1.2.1 to 1.2.3 in /tests …
dependabot[bot] Jan 12, 2022
cec0d32
Support use clause.Expression as argument
jinzhu Jan 28, 2022
98c4b78
Add Session Initialized option
jinzhu Jan 28, 2022
c0bea44
fix: omit not work when use join (#5034)
li-jin-gou Jan 28, 2022
8c36732
preoload not allowd before count (#5023)
0fv Jan 30, 2022
8d293d4
Fix docker-compose test env for Mac M1
jinzhu Jan 30, 2022
f19b84d
Fix github action
jinzhu Jan 30, 2022
581a879
Added comments to existing methods
Saurabh-Thakre Jan 31, 2022
93b1a6f
Merge pull request #5043 from Saurabh-Thakre/patch-2
huacnlee Feb 4, 2022
416c4d0
Test query with Or and soft delete
jinzhu Feb 8, 2022
d222151
fix: replace empty table name result in panic (#5048)
li-jin-gou Feb 8, 2022
4eeb839
Better support Stringer when explain SQL
jinzhu Feb 9, 2022
df23650
Remove uncessary switch case
jinzhu Feb 9, 2022
a0aceeb
Migrator AlterColumn with full data type
jinzhu Feb 9, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v1
uses: actions/checkout@v2
- name: golangci-lint
uses: reviewdog/action-golangci-lint@v2

- name: Setup reviewdog
uses: reviewdog/action-setup@v1

- name: gofumpt -s with reviewdog
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
go install mvdan.cc/[email protected]
gofumpt -e -d . | \
reviewdog -name="gofumpt" -f=diff -f.diff.strip=0 -reporter=github-pr-review
18 changes: 9 additions & 9 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
sqlite:
strategy:
matrix:
go: ['1.17', '1.16', '1.15']
go: ['1.17', '1.16']
platform: [ubuntu-latest] # can not run in windows OS
runs-on: ${{ matrix.platform }}

Expand All @@ -33,13 +33,13 @@ jobs:
key: ${{ runner.os }}-go-${{ matrix.go }}-${{ hashFiles('tests/go.mod') }}

- name: Tests
run: GORM_DIALECT=sqlite ./tests/tests_all.sh
run: GITHUB_ACTION=true GORM_DIALECT=sqlite ./tests/tests_all.sh

mysql:
strategy:
matrix:
dbversion: ['mysql:latest', 'mysql:5.7', 'mariadb:latest']
go: ['1.17', '1.16', '1.15']
go: ['1.17', '1.16']
platform: [ubuntu-latest]
runs-on: ${{ matrix.platform }}

Expand Down Expand Up @@ -77,13 +77,13 @@ jobs:
key: ${{ runner.os }}-go-${{ matrix.go }}-${{ hashFiles('tests/go.mod') }}

- name: Tests
run: GORM_DIALECT=mysql GORM_DSN="gorm:gorm@tcp(localhost:9910)/gorm?charset=utf8&parseTime=True" ./tests/tests_all.sh
run: GITHUB_ACTION=true GORM_DIALECT=mysql GORM_DSN="gorm:gorm@tcp(localhost:9910)/gorm?charset=utf8&parseTime=True" ./tests/tests_all.sh

postgres:
strategy:
matrix:
dbversion: ['postgres:latest', 'postgres:12', 'postgres:11', 'postgres:10']
go: ['1.17', '1.16', '1.15']
dbversion: ['postgres:latest', 'postgres:13', 'postgres:12', 'postgres:11', 'postgres:10']
go: ['1.17', '1.16']
platform: [ubuntu-latest] # can not run in macOS and Windows
runs-on: ${{ matrix.platform }}

Expand Down Expand Up @@ -120,12 +120,12 @@ jobs:
key: ${{ runner.os }}-go-${{ matrix.go }}-${{ hashFiles('tests/go.mod') }}

- name: Tests
run: GORM_DIALECT=postgres GORM_DSN="user=gorm password=gorm dbname=gorm host=localhost port=9920 sslmode=disable TimeZone=Asia/Shanghai" ./tests/tests_all.sh
run: GITHUB_ACTION=true GORM_DIALECT=postgres GORM_DSN="user=gorm password=gorm dbname=gorm host=localhost port=9920 sslmode=disable TimeZone=Asia/Shanghai" ./tests/tests_all.sh

sqlserver:
strategy:
matrix:
go: ['1.17', '1.16', '1.15']
go: ['1.17', '1.16']
platform: [ubuntu-latest] # can not run test in macOS and windows
runs-on: ${{ matrix.platform }}

Expand Down Expand Up @@ -163,4 +163,4 @@ jobs:
key: ${{ runner.os }}-go-${{ matrix.go }}-${{ hashFiles('tests/go.mod') }}

- name: Tests
run: GORM_DIALECT=sqlserver GORM_DSN="sqlserver://gorm:LoremIpsum86@localhost:9930?database=gorm" ./tests/tests_all.sh
run: GITHUB_ACTION=true GORM_DIALECT=sqlserver GORM_DSN="sqlserver://gorm:LoremIpsum86@localhost:9930?database=gorm" ./tests/tests_all.sh
11 changes: 11 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
linters:
enable:
- cyclop
- exportloopref
- gocritic
- gosec
- ineffassign
- misspell
- prealloc
- unconvert
- unparam
8 changes: 5 additions & 3 deletions callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,11 @@ func (p *processor) Execute(db *DB) *DB {
f(db)
}

db.Logger.Trace(stmt.Context, curTime, func() (string, int64) {
return db.Dialector.Explain(stmt.SQL.String(), stmt.Vars...), db.RowsAffected
}, db.Error)
if stmt.SQL.Len() > 0 {
db.Logger.Trace(stmt.Context, curTime, func() (string, int64) {
return db.Dialector.Explain(stmt.SQL.String(), stmt.Vars...), db.RowsAffected
}, db.Error)
}

if !stmt.DB.DryRun {
stmt.SQL.Reset()
Expand Down
47 changes: 30 additions & 17 deletions callbacks/associations.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"gorm.io/gorm/utils"
)

func SaveBeforeAssociations(create bool) func(db *gorm.DB) {
Expand Down Expand Up @@ -39,7 +40,8 @@ func SaveBeforeAssociations(create bool) func(db *gorm.DB) {
switch db.Statement.ReflectValue.Kind() {
case reflect.Slice, reflect.Array:
var (
objs = make([]reflect.Value, 0, db.Statement.ReflectValue.Len())
rValLen = db.Statement.ReflectValue.Len()
objs = make([]reflect.Value, 0, rValLen)
fieldType = rel.Field.FieldType
isPtr = fieldType.Kind() == reflect.Ptr
)
Expand All @@ -49,21 +51,20 @@ func SaveBeforeAssociations(create bool) func(db *gorm.DB) {
}

elems := reflect.MakeSlice(reflect.SliceOf(fieldType), 0, 10)
for i := 0; i < db.Statement.ReflectValue.Len(); i++ {
for i := 0; i < rValLen; i++ {
obj := db.Statement.ReflectValue.Index(i)
if reflect.Indirect(obj).Kind() != reflect.Struct {
break
}

if reflect.Indirect(obj).Kind() == reflect.Struct {
if _, zero := rel.Field.ValueOf(obj); !zero { // check belongs to relation value
rv := rel.Field.ReflectValueOf(obj) // relation reflect value
objs = append(objs, obj)
if isPtr {
elems = reflect.Append(elems, rv)
} else {
elems = reflect.Append(elems, rv.Addr())
}
if _, zero := rel.Field.ValueOf(obj); !zero { // check belongs to relation value
rv := rel.Field.ReflectValueOf(obj) // relation reflect value
objs = append(objs, obj)
if isPtr {
elems = reflect.Append(elems, rv)
} else {
elems = reflect.Append(elems, rv.Addr())
}
} else {
break
}
}

Expand Down Expand Up @@ -182,6 +183,7 @@ func SaveAfterAssociations(create bool) func(db *gorm.DB) {
fieldType = reflect.PtrTo(fieldType)
}
elems := reflect.MakeSlice(reflect.SliceOf(fieldType), 0, 10)
identityMap := map[string]bool{}
appendToElems := func(v reflect.Value) {
if _, zero := rel.Field.ValueOf(v); !zero {
f := reflect.Indirect(rel.Field.ReflectValueOf(v))
Expand All @@ -197,10 +199,21 @@ func SaveAfterAssociations(create bool) func(db *gorm.DB) {
}
}

if isPtr {
elems = reflect.Append(elems, elem)
} else {
elems = reflect.Append(elems, elem.Addr())
relPrimaryValues := make([]interface{}, 0, len(rel.FieldSchema.PrimaryFields))
for _, pf := range rel.FieldSchema.PrimaryFields {
if pfv, ok := pf.ValueOf(elem); !ok {
relPrimaryValues = append(relPrimaryValues, pfv)
}
}

cacheKey := utils.ToStringKey(relPrimaryValues)
if len(relPrimaryValues) != len(rel.FieldSchema.PrimaryFields) || !identityMap[cacheKey] {
identityMap[cacheKey] = true
if isPtr {
elems = reflect.Append(elems, elem)
} else {
elems = reflect.Append(elems, elem.Addr())
}
}
}
}
Expand Down
30 changes: 15 additions & 15 deletions callbacks/callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ var (

type Config struct {
LastInsertIDReversed bool
WithReturning bool
CreateClauses []string
QueryClauses []string
UpdateClauses []string
Expand All @@ -25,6 +24,19 @@ func RegisterDefaultCallbacks(db *gorm.DB, config *Config) {
return !db.SkipDefaultTransaction
}

if len(config.CreateClauses) == 0 {
config.CreateClauses = createClauses
}
if len(config.QueryClauses) == 0 {
config.QueryClauses = queryClauses
}
if len(config.DeleteClauses) == 0 {
config.DeleteClauses = deleteClauses
}
if len(config.UpdateClauses) == 0 {
config.UpdateClauses = updateClauses
}

createCallback := db.Callback().Create()
createCallback.Match(enableTransaction).Register("gorm:begin_transaction", BeginTransaction)
createCallback.Register("gorm:before_create", BeforeCreate)
Expand All @@ -33,44 +45,32 @@ func RegisterDefaultCallbacks(db *gorm.DB, config *Config) {
createCallback.Register("gorm:save_after_associations", SaveAfterAssociations(true))
createCallback.Register("gorm:after_create", AfterCreate)
createCallback.Match(enableTransaction).Register("gorm:commit_or_rollback_transaction", CommitOrRollbackTransaction)
if len(config.CreateClauses) == 0 {
config.CreateClauses = createClauses
}
createCallback.Clauses = config.CreateClauses

queryCallback := db.Callback().Query()
queryCallback.Register("gorm:query", Query)
queryCallback.Register("gorm:preload", Preload)
queryCallback.Register("gorm:after_query", AfterQuery)
if len(config.QueryClauses) == 0 {
config.QueryClauses = queryClauses
}
queryCallback.Clauses = config.QueryClauses

deleteCallback := db.Callback().Delete()
deleteCallback.Match(enableTransaction).Register("gorm:begin_transaction", BeginTransaction)
deleteCallback.Register("gorm:before_delete", BeforeDelete)
deleteCallback.Register("gorm:delete_before_associations", DeleteBeforeAssociations)
deleteCallback.Register("gorm:delete", Delete)
deleteCallback.Register("gorm:delete", Delete(config))
deleteCallback.Register("gorm:after_delete", AfterDelete)
deleteCallback.Match(enableTransaction).Register("gorm:commit_or_rollback_transaction", CommitOrRollbackTransaction)
if len(config.DeleteClauses) == 0 {
config.DeleteClauses = deleteClauses
}
deleteCallback.Clauses = config.DeleteClauses

updateCallback := db.Callback().Update()
updateCallback.Match(enableTransaction).Register("gorm:begin_transaction", BeginTransaction)
updateCallback.Register("gorm:setup_reflect_value", SetupUpdateReflectValue)
updateCallback.Register("gorm:before_update", BeforeUpdate)
updateCallback.Register("gorm:save_before_associations", SaveBeforeAssociations(false))
updateCallback.Register("gorm:update", Update)
updateCallback.Register("gorm:update", Update(config))
updateCallback.Register("gorm:save_after_associations", SaveAfterAssociations(false))
updateCallback.Register("gorm:after_update", AfterUpdate)
updateCallback.Match(enableTransaction).Register("gorm:commit_or_rollback_transaction", CommitOrRollbackTransaction)
if len(config.UpdateClauses) == 0 {
config.UpdateClauses = updateClauses
}
updateCallback.Clauses = config.UpdateClauses

rowCallback := db.Callback().Row()
Expand Down
Loading