Merge branch 'xorm-v1' into cyjay-v1
This commit is contained in:
commit
805f4ebdaf
|
@ -9,13 +9,13 @@ jobs:
|
||||||
release:
|
release:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- name: setup go
|
- name: setup go
|
||||||
uses: actions/setup-go@v5
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: '>=1.20.1'
|
go-version-file: 'go.mod'
|
||||||
- name: Use Go Action
|
- name: Use Go Action
|
||||||
id: use-go-action
|
id: use-go-action
|
||||||
uses: https://gitea.com/actions/release-action@main
|
uses: https://gitea.com/actions/release-action@main
|
||||||
|
|
|
@ -5,38 +5,15 @@ on:
|
||||||
- master
|
- master
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
env:
|
|
||||||
GOPROXY: https://goproxy.io,direct
|
|
||||||
GOPATH: /go_path
|
|
||||||
GOCACHE: /go_cache
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test-cockroach:
|
test-cockroach:
|
||||||
name: test cockroach
|
name: test cockroach
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
# - name: cache go path
|
- uses: actions/checkout@v4
|
||||||
# id: cache-go-path
|
|
||||||
# uses: https://github.com/actions/cache@v3
|
|
||||||
# with:
|
|
||||||
# path: /go_path
|
|
||||||
# key: go_path-${{ github.repository }}-${{ github.ref_name }}
|
|
||||||
# restore-keys: |
|
|
||||||
# go_path-${{ github.repository }}-
|
|
||||||
# go_path-
|
|
||||||
# - name: cache go cache
|
|
||||||
# id: cache-go-cache
|
|
||||||
# uses: https://github.com/actions/cache@v3
|
|
||||||
# with:
|
|
||||||
# path: /go_cache
|
|
||||||
# key: go_cache-${{ github.repository }}-${{ github.ref_name }}
|
|
||||||
# restore-keys: |
|
|
||||||
# go_cache-${{ github.repository }}-
|
|
||||||
# go_cache-
|
|
||||||
- uses: actions/setup-go@v5
|
- uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: 1.20
|
go-version-file: 'go.mod'
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- name: test cockroach
|
- name: test cockroach
|
||||||
env:
|
env:
|
||||||
TEST_COCKROACH_HOST: "cockroach:26257"
|
TEST_COCKROACH_HOST: "cockroach:26257"
|
||||||
|
|
|
@ -5,38 +5,15 @@ on:
|
||||||
- master
|
- master
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
env:
|
|
||||||
GOPROXY: https://goproxy.io,direct
|
|
||||||
GOPATH: /go_path
|
|
||||||
GOCACHE: /go_cache
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
lint:
|
lint:
|
||||||
name: test mariadb
|
name: test mariadb
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
# - name: cache go path
|
- uses: actions/checkout@v4
|
||||||
# id: cache-go-path
|
|
||||||
# uses: https://github.com/actions/cache@v3
|
|
||||||
# with:
|
|
||||||
# path: /go_path
|
|
||||||
# key: go_path-${{ github.repository }}-${{ github.ref_name }}
|
|
||||||
# restore-keys: |
|
|
||||||
# go_path-${{ github.repository }}-
|
|
||||||
# go_path-
|
|
||||||
# - name: cache go cache
|
|
||||||
# id: cache-go-cache
|
|
||||||
# uses: https://github.com/actions/cache@v3
|
|
||||||
# with:
|
|
||||||
# path: /go_cache
|
|
||||||
# key: go_cache-${{ github.repository }}-${{ github.ref_name }}
|
|
||||||
# restore-keys: |
|
|
||||||
# go_cache-${{ github.repository }}-
|
|
||||||
# go_cache-
|
|
||||||
- uses: actions/setup-go@v5
|
- uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: 1.20
|
go-version-file: 'go.mod'
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- name: test mariadb
|
- name: test mariadb
|
||||||
env:
|
env:
|
||||||
TEST_MYSQL_HOST: mariadb
|
TEST_MYSQL_HOST: mariadb
|
||||||
|
|
|
@ -5,39 +5,15 @@ on:
|
||||||
- master
|
- master
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
env:
|
|
||||||
GOPROXY: https://goproxy.io,direct
|
|
||||||
GOPATH: /go_path
|
|
||||||
GOCACHE: /go_cache
|
|
||||||
RUNNER_TOOL_CACHE: /toolcache # specify with your cache path
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test-mssql-collation:
|
test-mssql-collation:
|
||||||
name: test mssql with collation
|
name: test mssql with collation
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
# - name: cache go path
|
- uses: actions/checkout@v4
|
||||||
# id: cache-go-path
|
- uses: actions/setup-go@v5
|
||||||
# uses: https://github.com/actions/cache@v3
|
|
||||||
# with:
|
|
||||||
# path: /go_path
|
|
||||||
# key: go_path-${{ github.repository }}-${{ github.ref_name }}
|
|
||||||
# restore-keys: |
|
|
||||||
# go_path-${{ github.repository }}-
|
|
||||||
# go_path-
|
|
||||||
# - name: cache go cache
|
|
||||||
# id: cache-go-cache
|
|
||||||
# uses: https://github.com/actions/cache@v3
|
|
||||||
# with:
|
|
||||||
# path: /go_cache
|
|
||||||
# key: go_cache-${{ github.repository }}-${{ github.ref_name }}
|
|
||||||
# restore-keys: |
|
|
||||||
# go_cache-${{ github.repository }}-
|
|
||||||
# go_cache-
|
|
||||||
- uses: actions/setup-go@v3
|
|
||||||
with:
|
with:
|
||||||
go-version: 1.20
|
go-version-file: 'go.mod'
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- name: test mssql with collation
|
- name: test mssql with collation
|
||||||
env:
|
env:
|
||||||
TEST_MSSQL_HOST: mssql2
|
TEST_MSSQL_HOST: mssql2
|
||||||
|
|
|
@ -5,38 +5,15 @@ on:
|
||||||
- master
|
- master
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
env:
|
|
||||||
GOPROXY: https://goproxy.io,direct
|
|
||||||
GOPATH: /go_path
|
|
||||||
GOCACHE: /go_cache
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test-mssql:
|
test-mssql:
|
||||||
name: test mssql
|
name: test mssql
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
# - name: cache go path
|
- uses: actions/checkout@v4
|
||||||
# id: cache-go-path
|
|
||||||
# uses: https://github.com/actions/cache@v3
|
|
||||||
# with:
|
|
||||||
# path: /go_path
|
|
||||||
# key: go_path-${{ github.repository }}-${{ github.ref_name }}
|
|
||||||
# restore-keys: |
|
|
||||||
# go_path-${{ github.repository }}-
|
|
||||||
# go_path-
|
|
||||||
# - name: cache go cache
|
|
||||||
# id: cache-go-cache
|
|
||||||
# uses: https://github.com/actions/cache@v3
|
|
||||||
# with:
|
|
||||||
# path: /go_cache
|
|
||||||
# key: go_cache-${{ github.repository }}-${{ github.ref_name }}
|
|
||||||
# restore-keys: |
|
|
||||||
# go_cache-${{ github.repository }}-
|
|
||||||
# go_cache-
|
|
||||||
- uses: actions/setup-go@v5
|
- uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: 1.20
|
go-version-file: 'go.mod'
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- name: test mssql
|
- name: test mssql
|
||||||
env:
|
env:
|
||||||
TEST_MSSQL_HOST: mssql
|
TEST_MSSQL_HOST: mssql
|
||||||
|
|
|
@ -5,38 +5,15 @@ on:
|
||||||
- master
|
- master
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
env:
|
|
||||||
GOPROXY: https://goproxy.io,direct
|
|
||||||
GOPATH: /go_path
|
|
||||||
GOCACHE: /go_cache
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test-mysql:
|
test-mysql:
|
||||||
name: test mysql
|
name: test mysql
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
# - name: cache go path
|
- uses: actions/checkout@v4
|
||||||
# id: cache-go-path
|
|
||||||
# uses: https://github.com/actions/cache@v3
|
|
||||||
# with:
|
|
||||||
# path: /go_path
|
|
||||||
# key: go_path-${{ github.repository }}-${{ github.ref_name }}
|
|
||||||
# restore-keys: |
|
|
||||||
# go_path-${{ github.repository }}-
|
|
||||||
# go_path-
|
|
||||||
# - name: cache go cache
|
|
||||||
# id: cache-go-cache
|
|
||||||
# uses: https://github.com/actions/cache@v3
|
|
||||||
# with:
|
|
||||||
# path: /go_cache
|
|
||||||
# key: go_cache-${{ github.repository }}-${{ github.ref_name }}
|
|
||||||
# restore-keys: |
|
|
||||||
# go_cache-${{ github.repository }}-
|
|
||||||
# go_cache-
|
|
||||||
- uses: actions/setup-go@v5
|
- uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: 1.20
|
go-version-file: 'go.mod'
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- name: test mysql utf8mb4
|
- name: test mysql utf8mb4
|
||||||
env:
|
env:
|
||||||
TEST_MYSQL_HOST: mysql
|
TEST_MYSQL_HOST: mysql
|
||||||
|
|
|
@ -5,38 +5,15 @@ on:
|
||||||
- master
|
- master
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
env:
|
|
||||||
GOPROXY: https://goproxy.io,direct
|
|
||||||
GOPATH: /go_path
|
|
||||||
GOCACHE: /go_cache
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
lint:
|
lint:
|
||||||
name: test mysql8
|
name: test mysql8
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
# - name: cache go path
|
- uses: actions/checkout@v4
|
||||||
# id: cache-go-path
|
|
||||||
# uses: https://github.com/actions/cache@v3
|
|
||||||
# with:
|
|
||||||
# path: /go_path
|
|
||||||
# key: go_path-${{ github.repository }}-${{ github.ref_name }}
|
|
||||||
# restore-keys: |
|
|
||||||
# go_path-${{ github.repository }}-
|
|
||||||
# go_path-
|
|
||||||
# - name: cache go cache
|
|
||||||
# id: cache-go-cache
|
|
||||||
# uses: https://github.com/actions/cache@v3
|
|
||||||
# with:
|
|
||||||
# path: /go_cache
|
|
||||||
# key: go_cache-${{ github.repository }}-${{ github.ref_name }}
|
|
||||||
# restore-keys: |
|
|
||||||
# go_cache-${{ github.repository }}-
|
|
||||||
# go_cache-
|
|
||||||
- uses: actions/setup-go@v5
|
- uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: 1.20
|
go-version-file: 'go.mod'
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- name: test mysql8
|
- name: test mysql8
|
||||||
env:
|
env:
|
||||||
TEST_MYSQL_HOST: mysql8
|
TEST_MYSQL_HOST: mysql8
|
||||||
|
|
|
@ -5,38 +5,15 @@ on:
|
||||||
- master
|
- master
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
env:
|
|
||||||
GOPROXY: https://goproxy.io,direct
|
|
||||||
GOPATH: /go_path
|
|
||||||
GOCACHE: /go_cache
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
lint:
|
lint:
|
||||||
name: test postgres
|
name: test postgres
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
# - name: cache go path
|
- uses: actions/checkout@v4
|
||||||
# id: cache-go-path
|
|
||||||
# uses: https://github.com/actions/cache@v3
|
|
||||||
# with:
|
|
||||||
# path: /go_path
|
|
||||||
# key: go_path-${{ github.repository }}-${{ github.ref_name }}
|
|
||||||
# restore-keys: |
|
|
||||||
# go_path-${{ github.repository }}-
|
|
||||||
# go_path-
|
|
||||||
# - name: cache go cache
|
|
||||||
# id: cache-go-cache
|
|
||||||
# uses: https://github.com/actions/cache@v3
|
|
||||||
# with:
|
|
||||||
# path: /go_cache
|
|
||||||
# key: go_cache-${{ github.repository }}-${{ github.ref_name }}
|
|
||||||
# restore-keys: |
|
|
||||||
# go_cache-${{ github.repository }}-
|
|
||||||
# go_cache-
|
|
||||||
- uses: actions/setup-go@v5
|
- uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: 1.20
|
go-version-file: 'go.mod'
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- name: test postgres
|
- name: test postgres
|
||||||
env:
|
env:
|
||||||
TEST_PGSQL_HOST: pgsql
|
TEST_PGSQL_HOST: pgsql
|
||||||
|
|
|
@ -5,38 +5,15 @@ on:
|
||||||
- master
|
- master
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
env:
|
|
||||||
GOPROXY: https://goproxy.io,direct
|
|
||||||
GOPATH: /go_path
|
|
||||||
GOCACHE: /go_cache
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test-sqlite:
|
test-sqlite:
|
||||||
name: unit test & test sqlite
|
name: unit test & test sqlite
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
# - name: cache go path
|
- uses: actions/checkout@v4
|
||||||
# id: cache-go-path
|
|
||||||
# uses: https://github.com/actions/cache@v3
|
|
||||||
# with:
|
|
||||||
# path: /go_path
|
|
||||||
# key: go_path-${{ github.repository }}-${{ github.ref_name }}
|
|
||||||
# restore-keys: |
|
|
||||||
# go_path-${{ github.repository }}-
|
|
||||||
# go_path-
|
|
||||||
# - name: cache go cache
|
|
||||||
# id: cache-go-cache
|
|
||||||
# uses: https://github.com/actions/cache@v3
|
|
||||||
# with:
|
|
||||||
# path: /go_cache
|
|
||||||
# key: go_cache-${{ github.repository }}-${{ github.ref_name }}
|
|
||||||
# restore-keys: |
|
|
||||||
# go_cache-${{ github.repository }}-
|
|
||||||
# go_cache-
|
|
||||||
- uses: actions/setup-go@v5
|
- uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: 1.20
|
go-version-file: 'go.mod'
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- name: vet
|
- name: vet
|
||||||
run: make vet
|
run: make vet
|
||||||
- name: format check
|
- name: format check
|
||||||
|
|
|
@ -5,38 +5,15 @@ on:
|
||||||
- master
|
- master
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
env:
|
|
||||||
GOPROXY: https://goproxy.io,direct
|
|
||||||
GOPATH: /go_path
|
|
||||||
GOCACHE: /go_cache
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test-tidb:
|
test-tidb:
|
||||||
name: test tidb
|
name: test tidb
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
# - name: cache go path
|
- uses: actions/checkout@v4
|
||||||
# id: cache-go-path
|
|
||||||
# uses: https://github.com/actions/cache@v3
|
|
||||||
# with:
|
|
||||||
# path: /go_path
|
|
||||||
# key: go_path-${{ github.repository }}-${{ github.ref_name }}
|
|
||||||
# restore-keys: |
|
|
||||||
# go_path-${{ github.repository }}-
|
|
||||||
# go_path-
|
|
||||||
# - name: cache go cache
|
|
||||||
# id: cache-go-cache
|
|
||||||
# uses: https://github.com/actions/cache@v3
|
|
||||||
# with:
|
|
||||||
# path: /go_cache
|
|
||||||
# key: go_cache-${{ github.repository }}-${{ github.ref_name }}
|
|
||||||
# restore-keys: |
|
|
||||||
# go_cache-${{ github.repository }}-
|
|
||||||
# go_cache-
|
|
||||||
- uses: actions/setup-go@v5
|
- uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
go-version: 1.20
|
go-version-file: 'go.mod'
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- name: test tidb
|
- name: test tidb
|
||||||
env:
|
env:
|
||||||
TEST_TIDB_HOST: "tidb:4000"
|
TEST_TIDB_HOST: "tidb:4000"
|
||||||
|
|
|
@ -126,6 +126,9 @@ func (statement *Statement) BuildUpdates(tableValue reflect.Value,
|
||||||
|
|
||||||
if fieldValue.CanAddr() {
|
if fieldValue.CanAddr() {
|
||||||
if structConvert, ok := fieldValue.Addr().Interface().(convert.Conversion); ok {
|
if structConvert, ok := fieldValue.Addr().Interface().(convert.Conversion); ok {
|
||||||
|
if !includeNil && !requiredField && utils.IsZero(fieldValue.Interface()) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
data, err := structConvert.ToDB()
|
data, err := structConvert.ToDB()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
|
|
|
@ -199,7 +199,7 @@ func (m *Migrate) createMigrationTableIfNotExists() error {
|
||||||
|
|
||||||
idCol := schemas.NewColumn(m.options.IDColumnName, "", schemas.SQLType{
|
idCol := schemas.NewColumn(m.options.IDColumnName, "", schemas.SQLType{
|
||||||
Name: "VARCHAR",
|
Name: "VARCHAR",
|
||||||
}, 255, 0, true)
|
}, 255, 0, false)
|
||||||
idCol.IsPrimaryKey = true
|
idCol.IsPrimaryKey = true
|
||||||
|
|
||||||
table := schemas.NewTable(m.options.TableName, reflect.TypeOf(new(schemas.Table)))
|
table := schemas.NewTable(m.options.TableName, reflect.TypeOf(new(schemas.Table)))
|
||||||
|
|
5
sync.go
5
sync.go
|
@ -17,6 +17,8 @@ type SyncOptions struct {
|
||||||
IgnoreConstrains bool
|
IgnoreConstrains bool
|
||||||
// IgnoreIndices will not add or delete indices
|
// IgnoreIndices will not add or delete indices
|
||||||
IgnoreIndices bool
|
IgnoreIndices bool
|
||||||
|
// IgnoreDropIndices will not delete indices
|
||||||
|
IgnoreDropIndices bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type SyncResult struct{}
|
type SyncResult struct{}
|
||||||
|
@ -55,6 +57,7 @@ func (session *Session) Sync(beans ...interface{}) error {
|
||||||
WarnIfDatabaseColumnMissed: false,
|
WarnIfDatabaseColumnMissed: false,
|
||||||
IgnoreConstrains: false,
|
IgnoreConstrains: false,
|
||||||
IgnoreIndices: false,
|
IgnoreIndices: false,
|
||||||
|
IgnoreDropIndices: false,
|
||||||
}, beans...)
|
}, beans...)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -244,7 +247,7 @@ func (session *Session) SyncWithOptions(opts SyncOptions, beans ...interface{})
|
||||||
for name2, index2 := range oriTable.Indexes {
|
for name2, index2 := range oriTable.Indexes {
|
||||||
if _, ok := foundIndexNames[name2]; !ok {
|
if _, ok := foundIndexNames[name2]; !ok {
|
||||||
// ignore based on there type
|
// ignore based on there type
|
||||||
if (index2.Type == schemas.IndexType && opts.IgnoreIndices) ||
|
if (index2.Type == schemas.IndexType && (opts.IgnoreIndices || opts.IgnoreDropIndices)) ||
|
||||||
(index2.Type == schemas.UniqueType && opts.IgnoreConstrains) {
|
(index2.Type == schemas.UniqueType && opts.IgnoreConstrains) {
|
||||||
// make sure we do not add a index with same name later
|
// make sure we do not add a index with same name later
|
||||||
delete(addedNames, name2)
|
delete(addedNames, name2)
|
||||||
|
|
|
@ -698,7 +698,7 @@ func TestSyncWithOptions(t *testing.T) {
|
||||||
assert.NotNil(t, result)
|
assert.NotNil(t, result)
|
||||||
assert.Len(t, getIndicesOfBeanFromDB(t, &SyncWithOpts1{}), 0)
|
assert.Len(t, getIndicesOfBeanFromDB(t, &SyncWithOpts1{}), 0)
|
||||||
|
|
||||||
// only ignore indices
|
// only ignore constrains
|
||||||
result, err = testEngine.SyncWithOptions(xorm.SyncOptions{IgnoreConstrains: true}, &SyncWithOpts2{})
|
result, err = testEngine.SyncWithOptions(xorm.SyncOptions{IgnoreConstrains: true}, &SyncWithOpts2{})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotNil(t, result)
|
assert.NotNil(t, result)
|
||||||
|
@ -706,7 +706,7 @@ func TestSyncWithOptions(t *testing.T) {
|
||||||
assert.Len(t, indices, 2)
|
assert.Len(t, indices, 2)
|
||||||
assert.ElementsMatch(t, []string{"ttt", "index"}, getKeysFromMap(indices))
|
assert.ElementsMatch(t, []string{"ttt", "index"}, getKeysFromMap(indices))
|
||||||
|
|
||||||
// only ignore constrains
|
// only ignore indices
|
||||||
result, err = testEngine.SyncWithOptions(xorm.SyncOptions{IgnoreIndices: true}, &SyncWithOpts3{})
|
result, err = testEngine.SyncWithOptions(xorm.SyncOptions{IgnoreIndices: true}, &SyncWithOpts3{})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotNil(t, result)
|
assert.NotNil(t, result)
|
||||||
|
@ -714,9 +714,16 @@ func TestSyncWithOptions(t *testing.T) {
|
||||||
assert.Len(t, indices, 4)
|
assert.Len(t, indices, 4)
|
||||||
assert.ElementsMatch(t, []string{"ttt", "index", "unique", "lll"}, getKeysFromMap(indices))
|
assert.ElementsMatch(t, []string{"ttt", "index", "unique", "lll"}, getKeysFromMap(indices))
|
||||||
|
|
||||||
|
// only ignore drop indices
|
||||||
|
result, err = testEngine.SyncWithOptions(xorm.SyncOptions{IgnoreDropIndices: true}, &SyncWithOpts3{})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.NotNil(t, result)
|
||||||
|
indices = getIndicesOfBeanFromDB(t, &SyncWithOpts1{})
|
||||||
|
assert.Len(t, indices, 4)
|
||||||
|
assert.ElementsMatch(t, []string{"ttt", "index", "unique", "lll"}, getKeysFromMap(indices))
|
||||||
|
|
||||||
tableInfoFromStruct, _ := testEngine.TableInfo(&SyncWithOpts1{})
|
tableInfoFromStruct, _ := testEngine.TableInfo(&SyncWithOpts1{})
|
||||||
assert.ElementsMatch(t, getKeysFromMap(tableInfoFromStruct.Indexes), getKeysFromMap(getIndicesOfBeanFromDB(t, &SyncWithOpts1{})))
|
assert.ElementsMatch(t, getKeysFromMap(tableInfoFromStruct.Indexes), getKeysFromMap(getIndicesOfBeanFromDB(t, &SyncWithOpts1{})))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getIndicesOfBeanFromDB(t *testing.T, bean interface{}) map[string]*schemas.Index {
|
func getIndicesOfBeanFromDB(t *testing.T, bean interface{}) map[string]*schemas.Index {
|
||||||
|
|
|
@ -619,3 +619,95 @@ func TestMyArray(t *testing.T) {
|
||||||
assert.True(t, has)
|
assert.True(t, has)
|
||||||
assert.EqualValues(t, v, m.Content)
|
assert.EqualValues(t, v, m.Content)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ZDecimal struct {
|
||||||
|
value *big.Int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *ZDecimal) FromDB(data []byte) error {
|
||||||
|
i, _ := strconv.ParseInt(string(data), 10, 64)
|
||||||
|
*d = ZDecimal{
|
||||||
|
value: big.NewInt(i),
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d ZDecimal) ToDB() ([]byte, error) {
|
||||||
|
if d.value == nil {
|
||||||
|
return []byte("0"), nil
|
||||||
|
}
|
||||||
|
return []byte(fmt.Sprintf("%d", (d.value).Int64())), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d ZDecimal) IsZero() bool {
|
||||||
|
if d.value == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return d.value.Sign() == 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d ZDecimal) String() string {
|
||||||
|
if d.value == nil {
|
||||||
|
return "0"
|
||||||
|
}
|
||||||
|
return d.value.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestZDecimal(t *testing.T) {
|
||||||
|
type ZMyMoney struct {
|
||||||
|
Id int64
|
||||||
|
Account string
|
||||||
|
Amount ZDecimal
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.NoError(t, PrepareEngine())
|
||||||
|
assertSync(t, new(ZMyMoney))
|
||||||
|
|
||||||
|
_, err := testEngine.Insert(&ZMyMoney{
|
||||||
|
Account: "test",
|
||||||
|
Amount: ZDecimal{
|
||||||
|
value: big.NewInt(10000000000000000),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
m := ZMyMoney{
|
||||||
|
Id: 1,
|
||||||
|
}
|
||||||
|
has, err := testEngine.Get(&m)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.True(t, has)
|
||||||
|
|
||||||
|
_, err = testEngine.Update(&ZMyMoney{
|
||||||
|
Id: 1,
|
||||||
|
Account: "test2",
|
||||||
|
})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
m2 := ZMyMoney{
|
||||||
|
Id: 1,
|
||||||
|
}
|
||||||
|
has, err = testEngine.Get(&m2)
|
||||||
|
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.True(t, has)
|
||||||
|
assert.Equal(t, "test2", "test2")
|
||||||
|
assert.False(t, m2.Amount.IsZero())
|
||||||
|
assert.Equal(t, "10000000000000000", m2.Amount.String())
|
||||||
|
|
||||||
|
_, err = testEngine.AllCols().Update(&ZMyMoney{
|
||||||
|
Id: 1,
|
||||||
|
Account: "test3",
|
||||||
|
})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
var m3 = ZMyMoney{
|
||||||
|
Id: 1,
|
||||||
|
}
|
||||||
|
has, err = testEngine.Get(&m3)
|
||||||
|
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.True(t, has)
|
||||||
|
assert.Equal(t, "test3", "test3")
|
||||||
|
assert.True(t, m3.Amount.IsZero())
|
||||||
|
assert.Equal(t, "0", m3.Amount.String())
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue