Browse Source
upgrade xorm to v1.0.0 (#10)
upgrade xorm to v1.0.0 (#10)
upgrade xorm to v1.0.0 Reviewed-on: https://gitea.com/xorm/reverse/pulls/10main
39 changed files with 450 additions and 336 deletions
-
2go.mod
-
12go.sum
-
4vendor/modules.txt
-
71vendor/xorm.io/builder/.drone.yml
-
1vendor/xorm.io/builder/.gitignore
-
58vendor/xorm.io/builder/builder.go
-
2vendor/xorm.io/builder/builder_insert.go
-
9vendor/xorm.io/builder/builder_limit.go
-
2vendor/xorm.io/builder/builder_select.go
-
14vendor/xorm.io/builder/builder_set_operations.go
-
4vendor/xorm.io/builder/builder_update.go
-
4vendor/xorm.io/builder/cond_eq.go
-
2vendor/xorm.io/builder/go.mod
-
4vendor/xorm.io/builder/go.sum
-
9vendor/xorm.io/builder/sql.go
-
4vendor/xorm.io/xorm/.changelog.yml
-
56vendor/xorm.io/xorm/CHANGELOG.md
-
5vendor/xorm.io/xorm/Makefile
-
23vendor/xorm.io/xorm/README.md
-
22vendor/xorm.io/xorm/README_CN.md
-
8vendor/xorm.io/xorm/dialects/dialect.go
-
13vendor/xorm.io/xorm/dialects/postgres.go
-
96vendor/xorm.io/xorm/engine.go
-
8vendor/xorm.io/xorm/engine_group.go
-
2vendor/xorm.io/xorm/go.mod
-
3vendor/xorm.io/xorm/go.sum
-
2vendor/xorm.io/xorm/interface.go
-
79vendor/xorm.io/xorm/internal/statements/pk.go
-
3vendor/xorm.io/xorm/internal/statements/query.go
-
49vendor/xorm.io/xorm/internal/statements/statement.go
-
16vendor/xorm.io/xorm/internal/statements/types.go
-
66vendor/xorm.io/xorm/internal/statements/update.go
-
1vendor/xorm.io/xorm/internal/utils/strings.go
-
30vendor/xorm.io/xorm/names/table_name.go
-
2vendor/xorm.io/xorm/schemas/column.go
-
8vendor/xorm.io/xorm/schemas/table.go
-
8vendor/xorm.io/xorm/session_insert.go
-
56vendor/xorm.io/xorm/session_schema.go
-
2vendor/xorm.io/xorm/session_update.go
@ -0,0 +1 @@ |
|||
.idea |
@ -0,0 +1,79 @@ |
|||
// Copyright 2017 The Xorm Authors. All rights reserved.
|
|||
// Use of this source code is governed by a BSD-style
|
|||
// license that can be found in the LICENSE file.
|
|||
|
|||
package statements |
|||
|
|||
import ( |
|||
"fmt" |
|||
"reflect" |
|||
|
|||
"xorm.io/builder" |
|||
"xorm.io/xorm/schemas" |
|||
) |
|||
|
|||
var ( |
|||
ptrPkType = reflect.TypeOf(&schemas.PK{}) |
|||
pkType = reflect.TypeOf(schemas.PK{}) |
|||
stringType = reflect.TypeOf("") |
|||
intType = reflect.TypeOf(int64(0)) |
|||
uintType = reflect.TypeOf(uint64(0)) |
|||
) |
|||
|
|||
// ID generate "where id = ? " statement or for composite key "where key1 = ? and key2 = ?"
|
|||
func (statement *Statement) ID(id interface{}) *Statement { |
|||
switch t := id.(type) { |
|||
case *schemas.PK: |
|||
statement.idParam = *t |
|||
case schemas.PK: |
|||
statement.idParam = t |
|||
case string, int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64: |
|||
statement.idParam = schemas.PK{id} |
|||
default: |
|||
idValue := reflect.ValueOf(id) |
|||
idType := idValue.Type() |
|||
|
|||
switch idType.Kind() { |
|||
case reflect.String: |
|||
statement.idParam = schemas.PK{idValue.Convert(stringType).Interface()} |
|||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: |
|||
statement.idParam = schemas.PK{idValue.Convert(intType).Interface()} |
|||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: |
|||
statement.idParam = schemas.PK{idValue.Convert(uintType).Interface()} |
|||
case reflect.Slice: |
|||
if idType.ConvertibleTo(pkType) { |
|||
statement.idParam = idValue.Convert(pkType).Interface().(schemas.PK) |
|||
} |
|||
case reflect.Ptr: |
|||
if idType.ConvertibleTo(ptrPkType) { |
|||
statement.idParam = idValue.Convert(ptrPkType).Elem().Interface().(schemas.PK) |
|||
} |
|||
} |
|||
} |
|||
|
|||
if statement.idParam == nil { |
|||
statement.LastError = fmt.Errorf("ID param %#v is not supported", id) |
|||
} |
|||
|
|||
return statement |
|||
} |
|||
|
|||
func (statement *Statement) ProcessIDParam() error { |
|||
if statement.idParam == nil || statement.RefTable == nil { |
|||
return nil |
|||
} |
|||
|
|||
if len(statement.RefTable.PrimaryKeys) != len(statement.idParam) { |
|||
fmt.Println("=====", statement.RefTable.PrimaryKeys, statement.idParam) |
|||
return fmt.Errorf("ID condition is error, expect %d primarykeys, there are %d", |
|||
len(statement.RefTable.PrimaryKeys), |
|||
len(statement.idParam), |
|||
) |
|||
} |
|||
|
|||
for i, col := range statement.RefTable.PKColumns() { |
|||
var colName = statement.colName(col, statement.TableName()) |
|||
statement.cond = statement.cond.And(builder.Eq{colName: statement.idParam[i]}) |
|||
} |
|||
return nil |
|||
} |
@ -1,16 +0,0 @@ |
|||
// Copyright 2017 The Xorm Authors. All rights reserved.
|
|||
// Use of this source code is governed by a BSD-style
|
|||
// license that can be found in the LICENSE file.
|
|||
|
|||
package statements |
|||
|
|||
import ( |
|||
"reflect" |
|||
|
|||
"xorm.io/xorm/schemas" |
|||
) |
|||
|
|||
var ( |
|||
ptrPkType = reflect.TypeOf(&schemas.PK{}) |
|||
pkType = reflect.TypeOf(schemas.PK{}) |
|||
) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue