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

Bump gorm to v1.21.15 #3

Merged
merged 162 commits into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
162 commits
Select commit Hold shift + click to select a range
db0cc4d
Fix too long foreign key/checker names, close #4026
jinzhu Feb 1, 2021
8f37cb0
Make has to be a const, close #4024
jinzhu Feb 1, 2021
3d3208e
initialize config plugins
jinzhu Feb 3, 2021
ef5ef18
recommended to use magic const strings (#4059)
daheige Feb 7, 2021
e80853e
optimization check for ParseCheckConstraints (#4063)
daheige Feb 7, 2021
bb15338
Switch driver.Valuer, fmt.Stringer order when format SQL
jinzhu Feb 7, 2021
4373aa0
Don't call AfterFind hooks if no record found, close #4048
jinzhu Feb 7, 2021
deff059
Save associations based on creatable/updatable permission, close #4056
jinzhu Feb 7, 2021
883c32e
Support Unscoped when delete with selected associations, close #4062
jinzhu Feb 7, 2021
2ba612e
Add field tag to ignore migration (#4028)
yrong Feb 9, 2021
df24821
Fix SubQuery for raw sql
jinzhu Feb 9, 2021
84ea3ec
Fix sub query argument order with multiple raw SQL
jinzhu Feb 9, 2021
a13b7a6
Fix OnConflict where order for postgres, close #4073
jinzhu Feb 10, 2021
5744e29
Replacer interface for more flexible NamingStrategy (#4042)
joelnordell Feb 14, 2021
628a0ae
Fix foreign key & reference with same name, close #4081
jinzhu Feb 15, 2021
92a2389
Fix create duplicated constraint, close #4090
jinzhu Feb 16, 2021
73d44a4
Fix create duplicated constraint, close #4090
jinzhu Feb 16, 2021
79225bf
Fix Omit/Select without Model value, close #4098
jinzhu Feb 18, 2021
940da05
Skip nested associations when create data with Select, close #4108
jinzhu Feb 23, 2021
828e6b6
Lazy call registered scopes
jinzhu Feb 25, 2021
6b7d186
Lazy call registered scopes
jinzhu Feb 25, 2021
ddeb143
Lazy call registered scopes
jinzhu Feb 25, 2021
189547f
Fix new session with Begin, close #4120
jinzhu Feb 26, 2021
eb9a704
Fix update UpdatedAt when full saving associations, close #4115
jinzhu Feb 26, 2021
3694ef4
Fix get current table
jinzhu Feb 26, 2021
0157099
Use functional options
jinzhu Mar 4, 2021
42999e9
Fix overwrite preloading associations, close #4134
jinzhu Mar 4, 2021
90476fe
Fix Join with slice IN, close #4133
jinzhu Mar 4, 2021
6647552
Don't override the from clauses, close #4129
jinzhu Mar 4, 2021
adf85d5
change the method of initializing slice (#4097)
sivchari Mar 4, 2021
1476b2f
Fix apply config
jinzhu Mar 4, 2021
2946257
Fix after initialize db callback
jinzhu Mar 5, 2021
d6c2358
Revert "Don't override the from clauses, close #4129" close #4139
jinzhu Mar 5, 2021
a948c84
Revert "Revert "Don't override the from clauses, close #4129" close #…
jinzhu Mar 5, 2021
495ec4b
invalid db error and value and invalid value length error (#4151)
daheige Mar 7, 2021
bc34775
for Config.cacheStore store PreparedStmtDB key (#4149)
daheige Mar 7, 2021
a3abb5f
support named params in Select API (#4142)
ratanphayade Mar 7, 2021
221d0a0
optimize value of reflection length (#4152)
daheige Mar 8, 2021
02cb405
Optimize parse constraint (#4153)
daheige Mar 8, 2021
0348b1d
chore: improve code quality (#4123)
withshubh Mar 8, 2021
675de6f
Clear scopes before invoke scopes methods
jinzhu Mar 8, 2021
14b9bd1
Don't panic when using nil pointer, close #4168
jinzhu Mar 10, 2021
9fccb17
Fix double pointer for where conditions, close #4159
jinzhu Mar 10, 2021
9123600
Fix Scopes with Migrator, close #4145
jinzhu Mar 11, 2021
c575a4e
support to preload all children in multiple levels associations
ruozhixian Mar 11, 2021
2055e29
Refactor nested preload all associations
jinzhu Mar 14, 2021
07f3795
optimize MigrateColumn method for regexp (#4188)
daheige Mar 17, 2021
27bb913
Refactor OnConflict.UpdateALl
jinzhu Mar 18, 2021
a3d9bbf
build *clause.Expr
jinzhu Mar 19, 2021
e85b73e
Fix nested Scopes, close #4196
jinzhu Mar 19, 2021
220349c
Fix omit associations, close #4161
jinzhu Mar 19, 2021
a9fe025
Add GetDBConnector interface
jinzhu Mar 19, 2021
8c92d96
Fix to call Scopes with using Migrator
jinzhu Mar 19, 2021
26dd4c9
Fix: FindInBatches ignores errors (#4203)
genkami Mar 22, 2021
4d5cec8
Add golang 1.16
jinzhu Mar 24, 2021
704e53a
Call scopes before parse model value, close #4209
jinzhu Mar 24, 2021
8204d0a
Update tests script
jinzhu Mar 24, 2021
88078e4
Remove sqlite_windows test case
jinzhu Mar 24, 2021
26e0c6f
skip test sqlserver due to it will raise data race for invalid sql
jinzhu Mar 24, 2021
a8b7254
Fix get database connection for prepared stmt, close #4214
jinzhu Mar 25, 2021
0eba7a9
Fix apply option
jinzhu Mar 26, 2021
73c6d3e
Add AfterInitialize error
jinzhu Mar 29, 2021
33601dc
Support Having w/o Group
jinzhu Mar 30, 2021
8cfa9d9
Update field.go (#4228)
gavwu Apr 2, 2021
673053f
Fix context cancel error, close #4259, close #4260
jinzhu Apr 9, 2021
f3bdfa8
Add IgnoreRecordNotFoundError option for logger
jinzhu Apr 9, 2021
ad53074
Pass db error to new instance
jinzhu Apr 9, 2021
d278ca4
sort GORM options before apply
jinzhu Apr 9, 2021
d791130
Respect ignore migration when add column (#4276)
yrong Apr 13, 2021
5555b01
feat: Optimal value type acquisition for v (#4278)
daheige Apr 13, 2021
74e7a9c
Optimize reflect value length and method (#4280)
daheige Apr 14, 2021
d483ffa
Fix Preload with nil pointer
jinzhu Apr 15, 2021
7701c88
Assign transaction error to db
jinzhu Apr 16, 2021
15a46bc
Fix some typos (#4294)
faulkner Apr 19, 2021
d327926
Check ReflectValue.CanAddr before set field value
jinzhu Apr 19, 2021
a855fe6
Fixed naming longer than 64 characters (#4310)
MikaMauger Apr 22, 2021
82cb4eb
Fix overwrite Statement in scopes
jinzhu Apr 22, 2021
6951be0
Allow customize clauses
jinzhu Apr 28, 2021
f0d0bbb
Added missing white space (#4330)
KarolosLykos Apr 28, 2021
70e93e7
Check data type if copyable before change reference field's type
jinzhu Apr 30, 2021
8f7f3ad
fixed belongs_to & has_one reversed if field same (#4343)
paraswaykole May 4, 2021
3f359ea
slim trace if depth (#4346)
xx1906 May 5, 2021
2aca96d
test ignore migration, close #4314, #4315
jinzhu May 5, 2021
6b7abc5
Fix tests
jinzhu May 6, 2021
a480bd8
Update Optimize schema (#4364)
chenquan May 10, 2021
92c3ba9
Fix create new db sessions in scopes
jinzhu May 17, 2021
cf93b16
Fix ErrInvalidTransaction error message (#4380)
atreya2011 May 17, 2021
79f427d
fixed has_many stopped working if field names are identical (#4387)
paraswaykole May 19, 2021
ea1bce3
Only check struct value can address or not
jinzhu May 23, 2021
ac722c1
Small grammar fix in error message (#4406)
Br3nda May 24, 2021
bcf2b38
Fix typo in associations_test.go (#4407)
eltociear May 27, 2021
363f9b7
golint standard (#4421)
heyanfu May 31, 2021
14e9608
Eq, Neq support slice of data
jinzhu May 31, 2021
9abac96
Fix Eq, Neq support slice of data
jinzhu May 31, 2021
810058c
Fix soft delete with Update
jinzhu Jun 1, 2021
cf079b8
Update version in `tests.yml` (#4432)
s-takehana Jun 2, 2021
dd8bf88
add Target where clause for on conflict (#4442)
VitalyShein Jun 7, 2021
00b2525
Fix: FirstOrCreate slice out of bounds error when using 'Assigns' (#4…
liamrfell Jun 7, 2021
50e85e1
Code optimize (#4415)
daheige Jun 10, 2021
e425ed6
Update tests go.mod
jinzhu Jun 10, 2021
5b65b02
Update tests go.mod
jinzhu Jun 11, 2021
a0bddcc
Use count(*) instead of count(1) include NULL and non-NULL rows(SQL-9…
tony95271 Jun 11, 2021
25b9f2e
Added return names to logger.Interface.Trace (#4450)
applejag Jun 11, 2021
3226937
Fix calc gormSourceDir, close #4456
jinzhu Jun 13, 2021
8e67a08
Fix Scopes with Row, close #4465
jinzhu Jun 18, 2021
8bd8d38
Fix Pluck's usage #4473
wuwenchi Jun 26, 2021
6d64e31
Merge pull request #4479 from wuwenchi/master
huacnlee Jun 27, 2021
16579e0
fix: fix race issue in prepare method (#4487)
shiyu7 Jun 30, 2021
80497f2
title foreign schema for many2many to avoid panic (#4496)
wangyuehong Jul 13, 2021
0329b80
slightly better callback warning (#4495)
bdemirpolat Jul 13, 2021
2ec7043
Respect update permission for OnConflict Create
jinzhu Jul 13, 2021
76cd73c
Fix wipes out MySQL global variables from the query, close #4515
jinzhu Jul 13, 2021
b616d81
Fix scan single value to custom type, close #4501
jinzhu Jul 13, 2021
c73fe96
Fix scan into decimal.Decimal, close #4457
jinzhu Jul 13, 2021
b13732c
Fix invalid preload SQL when no data found, close #4443
jinzhu Jul 13, 2021
52b72d7
Add error explanations when preloading assocations w/o foreign fields…
jinzhu Jul 13, 2021
83530ec
Fix delete order by clause when counting, close #4478
jinzhu Jul 13, 2021
d4f3c10
Fix OnConflict with one column, close #4370
jinzhu Jul 13, 2021
ac97aec
New Comma Expression (#4524)
tr1v3r Jul 14, 2021
7475201
Fix hang when closing a prepared statement
jinzhu Jul 14, 2021
a702546
optimize setupValuerAndSetter func
daheige Jul 14, 2021
2202e99
Fix create index with comments in MySQL (#4521)
s-takehana Jul 18, 2021
5115813
Fix preload fmt.Errorf formatter (#4531)
daheige Jul 28, 2021
3e15478
Merge pull request #4530 from daheige/optimize-setupValuerAndSetter
huacnlee Jul 28, 2021
41ac73b
update comment for ConvertSliceOfMapToValuesForCreate func
daheige Jul 14, 2021
7a49629
optimize Parse func for fieldValue.Interface
daheige Jul 14, 2021
413fe58
Optimize migrator.go MigrateColumn and ColumnTypes func. (#4532)
daheige Aug 2, 2021
9e5a4e3
Fix migrator GuessConstraintAndTable method for return value for *sch…
daheige Aug 3, 2021
a870486
Do not emit ORDER BY for empty values (#4592)
wfscheper Aug 9, 2021
cbe7275
Update Dependencies (#4582)
mmorel-35 Aug 9, 2021
82fe815
fix: table couln't be reentrant (#4556)
SmallTianTian Aug 9, 2021
21e85b8
Fix create with ignore migration (#4571)
zkqiang Aug 9, 2021
a83d25e
chore(logger): explicitly set config of Default Logger (#4605)
HurSungYun Aug 11, 2021
2b2f6e7
Add SchemaName to NamingStrategy
jinzhu Aug 11, 2021
25f561a
feat: QuoteTo accept clause.Expr (#4621)
tr1v3r Aug 19, 2021
1bb0d87
feat: count accpet `db`.`table` (#4626)
tr1v3r Aug 20, 2021
e076e9e
Bump gorm.io/gorm from 1.21.12 to 1.21.13 in /tests (#4616)
dependabot[bot] Aug 20, 2021
7a53d8e
Bump gorm.io/driver/mysql from 1.1.1 to 1.1.2 in /tests (#4615)
dependabot[bot] Aug 20, 2021
093694f
Fix extra 'AND' when len(values) == 0 ON IN.NegationBuild() (#4618)
secake Aug 20, 2021
0934b10
Bump gorm.io/driver/sqlserver from 1.0.7 to 1.0.8 in /tests (#4631)
dependabot[bot] Aug 23, 2021
f21e35f
Fix table not supported error when using unexpected table name
jinzhu Aug 26, 2021
e81833f
Fix onConflict with non-updatable in associations
zkqiang Aug 22, 2021
7474621
Test update association with non-updatable
zkqiang Aug 23, 2021
3a8c250
Refactor calc associations onConflictOption
jinzhu Aug 26, 2021
15188cf
Add Go 1.17 (#4666)
jxlwqq Sep 3, 2021
5f019f7
Bump gorm.io/gorm from 1.21.13 to 1.21.14 in /tests (#4655)
dependabot[bot] Sep 3, 2021
a89d4d8
Bump github.com/lib/pq from 1.10.2 to 1.10.3 in /tests (#4676)
dependabot[bot] Sep 6, 2021
1d9e563
style: prepose error judgement
tr1v3r Sep 3, 2021
c898622
test: add testcase in TestSave
tr1v3r Sep 5, 2021
4581e8b
test: update Save test
tr1v3r Sep 5, 2021
eaa63d1
feat: copy dest fields to model struct
tr1v3r Sep 5, 2021
895c117
Proposal, Add Specific on for Joins queries
Jul 8, 2021
52cc438
JoinsOn unit test + use all primary keys
Jul 17, 2021
c301aeb
Refactor for readability
Jul 18, 2021
d047f85
PR Comments
Aug 28, 2021
3b6a7c8
Update sqlserver driver
jinzhu Sep 7, 2021
6c94b07
try to fix fatal error: concurrent map read and map write
jinzhu Sep 7, 2021
ba16b23
Refactor update record (#4679)
jinzhu Sep 7, 2021
a16db07
Refactor Join ON
jinzhu Sep 7, 2021
04f049c
Add tests for RowsAffected
jinzhu Sep 9, 2021
fca7a9c
Add field tag to ignore migration
yrong Jan 31, 2021
e62a53b
refactor migration tag
yrong Feb 9, 2021
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
15 changes: 15 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
version: 2
updates:
- package-ecosystem: gomod
directory: /
schedule:
interval: weekly
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
- package-ecosystem: gomod
directory: /tests
schedule:
interval: weekly
2 changes: 1 addition & 1 deletion .github/workflows/invalid_question.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
ACTIONS_STEP_DEBUG: true
steps:
- name: Close Stale Issues
uses: actions/stale@v3.0.7
uses: actions/stale@v4
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: "This issue has been marked as invalid question, please give more information by following the `Question` template, if you believe there is a bug of GORM, please create a pull request that could reproduce the issue on [https://github.com/go-gorm/playground](https://github.com/go-gorm/playground), the issue will be closed in 2 days if no further activity occurs. most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ [Search Before Asking](https://stackoverflow.com/help/how-to-ask) ✨"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/missing_playground.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
ACTIONS_STEP_DEBUG: true
steps:
- name: Close Stale Issues
uses: actions/stale@v3.0.7
uses: actions/stale@v4
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: "The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout [https://github.com/go-gorm/playground](https://github.com/go-gorm/playground) for details. it will be closed in 2 days if no further activity occurs. if you are asking question, please use the `Question` template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ [Search Before Asking](https://stackoverflow.com/help/how-to-ask) ✨"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ jobs:
- name: Check out code into the Go module directory
uses: actions/checkout@v1
- name: golangci-lint
uses: reviewdog/action-golangci-lint@v1
uses: reviewdog/action-golangci-lint@v2
2 changes: 1 addition & 1 deletion .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
ACTIONS_STEP_DEBUG: true
steps:
- name: Close Stale Issues
uses: actions/stale@v3.0.7
uses: actions/stale@v4
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: "This issue has been automatically marked as stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days"
Expand Down
41 changes: 8 additions & 33 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
sqlite:
strategy:
matrix:
go: ['1.15', '1.14', '1.13']
platform: [ubuntu-latest, macos-latest] # can not run in windows OS
go: ['1.17', '1.16', '1.15']
platform: [ubuntu-latest] # can not run in windows OS
runs-on: ${{ matrix.platform }}

steps:
Expand All @@ -35,36 +35,11 @@ jobs:
- name: Tests
run: GORM_DIALECT=sqlite ./tests/tests_all.sh

sqlite_windows:
strategy:
matrix:
go: ['1.15', '1.14', '1.13']
platform: [windows-latest]
runs-on: ${{ matrix.platform }}

steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: go mod package cache
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ matrix.go }}-${{ hashFiles('tests/go.mod') }}

- name: Tests
run: cd tests && set GORM_DIALECT=sqlite && go test $race -count=1 -v ./... #run the line in widnows's CMD, default GORM_DIALECT is sqlite

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

Expand Down Expand Up @@ -107,9 +82,9 @@ jobs:
postgres:
strategy:
matrix:
dbversion: ['postgres:latest', 'postgres:11', 'postgres:10']
go: ['1.15', '1.14', '1.13']
platform: [ubuntu-latest] # can not run in macOS and widnowsOS
dbversion: ['postgres:latest', 'postgres:12', 'postgres:11', 'postgres:10']
go: ['1.17', '1.16', '1.15']
platform: [ubuntu-latest] # can not run in macOS and Windows
runs-on: ${{ matrix.platform }}

services:
Expand Down Expand Up @@ -150,7 +125,7 @@ jobs:
sqlserver:
strategy:
matrix:
go: ['1.15', '1.14', '1.13']
go: ['1.17', '1.16', '1.15']
platform: [ubuntu-latest] # can not run test in macOS and windows
runs-on: ${{ matrix.platform }}

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ TODO*
documents
coverage.txt
_book
.idea
7 changes: 3 additions & 4 deletions association.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package gorm

import (
"errors"
"fmt"
"reflect"
"strings"
Expand All @@ -27,7 +26,7 @@ func (db *DB) Association(column string) *Association {
association.Relationship = db.Statement.Schema.Relationships.Relations[column]

if association.Relationship == nil {
association.Error = fmt.Errorf("%w: %v", ErrUnsupportedRelation, column)
association.Error = fmt.Errorf("%w: %s", ErrUnsupportedRelation, column)
}

db.Statement.ReflectValue = reflect.ValueOf(db.Statement.Model)
Expand Down Expand Up @@ -356,7 +355,7 @@ func (association *Association) saveAssociation(clear bool, values ...interface{
} else if ev.Type().Elem().AssignableTo(elemType) {
fieldValue = reflect.Append(fieldValue, ev.Elem())
} else {
association.Error = fmt.Errorf("unsupported data type: %v for relation %v", ev.Type(), association.Relationship.Name)
association.Error = fmt.Errorf("unsupported data type: %v for relation %s", ev.Type(), association.Relationship.Name)
}

if elemType.Kind() == reflect.Struct {
Expand Down Expand Up @@ -441,7 +440,7 @@ func (association *Association) saveAssociation(clear bool, values ...interface{
break
}

association.Error = errors.New("invalid association values, length doesn't match")
association.Error = ErrInvalidValueOfLength
return
}

Expand Down
52 changes: 39 additions & 13 deletions callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type callbacks struct {

type processor struct {
db *DB
Clauses []string
fns []func(*DB)
callbacks []*callback
}
Expand Down Expand Up @@ -71,38 +72,57 @@ func (cs *callbacks) Raw() *processor {
return cs.processors["raw"]
}

func (p *processor) Execute(db *DB) {
curTime := time.Now()
stmt := db.Statement
func (p *processor) Execute(db *DB) *DB {
// call scopes
for len(db.Statement.scopes) > 0 {
scopes := db.Statement.scopes
db.Statement.scopes = nil
for _, scope := range scopes {
db = scope(db)
}
}

var (
curTime = time.Now()
stmt = db.Statement
resetBuildClauses bool
)

if len(stmt.BuildClauses) == 0 {
stmt.BuildClauses = p.Clauses
resetBuildClauses = true
}

// assign model values
if stmt.Model == nil {
stmt.Model = stmt.Dest
} else if stmt.Dest == nil {
stmt.Dest = stmt.Model
}

// parse model values
if stmt.Model != nil {
if err := stmt.Parse(stmt.Model); err != nil && (!errors.Is(err, schema.ErrUnsupportedDataType) || (stmt.Table == "" && stmt.SQL.Len() == 0)) {
if errors.Is(err, schema.ErrUnsupportedDataType) && stmt.Table == "" {
if err := stmt.Parse(stmt.Model); err != nil && (!errors.Is(err, schema.ErrUnsupportedDataType) || (stmt.Table == "" && stmt.TableExpr == nil && stmt.SQL.Len() == 0)) {
if errors.Is(err, schema.ErrUnsupportedDataType) && stmt.Table == "" && stmt.TableExpr == nil {
db.AddError(fmt.Errorf("%w: Table not set, please set it like: db.Model(&user) or db.Table(\"users\")", err))
} else {
db.AddError(err)
}
}
}

// assign stmt.ReflectValue
if stmt.Dest != nil {
stmt.ReflectValue = reflect.ValueOf(stmt.Dest)
for stmt.ReflectValue.Kind() == reflect.Ptr {
if stmt.ReflectValue.IsNil() {
if stmt.ReflectValue.IsNil() && stmt.ReflectValue.CanAddr() {
stmt.ReflectValue.Set(reflect.New(stmt.ReflectValue.Type().Elem()))
break
}

stmt.ReflectValue = stmt.ReflectValue.Elem()
}
if !stmt.ReflectValue.IsValid() {
db.AddError(fmt.Errorf("invalid value"))
db.AddError(ErrInvalidValue)
}
}

Expand All @@ -118,6 +138,12 @@ func (p *processor) Execute(db *DB) {
stmt.SQL.Reset()
stmt.Vars = nil
}

if resetBuildClauses {
stmt.BuildClauses = nil
}

return db
}

func (p *processor) Get(name string) func(*DB) {
Expand Down Expand Up @@ -186,15 +212,15 @@ func (c *callback) Register(name string, fn func(*DB)) error {
}

func (c *callback) Remove(name string) error {
c.processor.db.Logger.Warn(context.Background(), "removing callback `%v` from %v\n", name, utils.FileWithLineNum())
c.processor.db.Logger.Warn(context.Background(), "removing callback `%s` from %s\n", name, utils.FileWithLineNum())
c.name = name
c.remove = true
c.processor.callbacks = append(c.processor.callbacks, c)
return c.processor.compile()
}

func (c *callback) Replace(name string, fn func(*DB)) error {
c.processor.db.Logger.Info(context.Background(), "replacing callback `%v` from %v\n", name, utils.FileWithLineNum())
c.processor.db.Logger.Info(context.Background(), "replacing callback `%s` from %s\n", name, utils.FileWithLineNum())
c.name = name
c.handler = fn
c.replace = true
Expand Down Expand Up @@ -224,7 +250,7 @@ func sortCallbacks(cs []*callback) (fns []func(*DB), err error) {
for _, c := range cs {
// show warning message the callback name already exists
if idx := getRIndex(names, c.name); idx > -1 && !c.replace && !c.remove && !cs[idx].remove {
c.processor.db.Logger.Warn(context.Background(), "duplicated callback `%v` from %v\n", c.name, utils.FileWithLineNum())
c.processor.db.Logger.Warn(context.Background(), "duplicated callback `%s` from %s\n", c.name, utils.FileWithLineNum())
}
names = append(names, c.name)
}
Expand All @@ -240,7 +266,7 @@ func sortCallbacks(cs []*callback) (fns []func(*DB), err error) {
// if before callback already sorted, append current callback just after it
sorted = append(sorted[:sortedIdx], append([]string{c.name}, sorted[sortedIdx:]...)...)
} else if curIdx > sortedIdx {
return fmt.Errorf("conflicting callback %v with before %v", c.name, c.before)
return fmt.Errorf("conflicting callback %s with before %s", c.name, c.before)
}
} else if idx := getRIndex(names, c.before); idx != -1 {
// if before callback exists
Expand All @@ -258,7 +284,7 @@ func sortCallbacks(cs []*callback) (fns []func(*DB), err error) {
// if after callback sorted, append current callback to last
sorted = append(sorted, c.name)
} else if curIdx < sortedIdx {
return fmt.Errorf("conflicting callback %v with before %v", c.name, c.after)
return fmt.Errorf("conflicting callback %s with before %s", c.name, c.after)
}
} else if idx := getRIndex(names, c.after); idx != -1 {
// if after callback exists but haven't sorted
Expand Down
Loading