Merge branch 'master' into lunny/upgrade_deps
This commit is contained in:
commit
9d9340bdd1
32
.drone.yml
32
.drone.yml
|
@ -11,7 +11,7 @@ trigger:
|
|||
- refs/pull/*/head
|
||||
steps:
|
||||
- name: test-vet
|
||||
image: golang:1.15
|
||||
image: golang:1.17
|
||||
pull: always
|
||||
volumes:
|
||||
- name: cache
|
||||
|
@ -19,7 +19,7 @@ steps:
|
|||
commands:
|
||||
- make vet
|
||||
- name: test-sqlite3
|
||||
image: golang:1.15
|
||||
image: golang:1.17
|
||||
volumes:
|
||||
- name: cache
|
||||
path: /go/pkg/mod
|
||||
|
@ -31,7 +31,7 @@ steps:
|
|||
- make test-sqlite3
|
||||
- TEST_CACHE_ENABLE=true make test-sqlite3
|
||||
- name: test-sqlite
|
||||
image: golang:1.15
|
||||
image: golang:1.17
|
||||
volumes:
|
||||
- name: cache
|
||||
path: /go/pkg/mod
|
||||
|
@ -41,7 +41,7 @@ steps:
|
|||
- make test-sqlite
|
||||
- TEST_QUOTE_POLICY=reserved make test-sqlite
|
||||
- name: test-mysql
|
||||
image: golang:1.15
|
||||
image: golang:1.17
|
||||
pull: never
|
||||
volumes:
|
||||
- name: cache
|
||||
|
@ -58,7 +58,7 @@ steps:
|
|||
- TEST_CACHE_ENABLE=true make test-mysql
|
||||
|
||||
- name: test-mysql-utf8mb4
|
||||
image: golang:1.15
|
||||
image: golang:1.17
|
||||
pull: never
|
||||
volumes:
|
||||
- name: cache
|
||||
|
@ -98,7 +98,7 @@ trigger:
|
|||
- refs/pull/*/head
|
||||
steps:
|
||||
- name: test-mysql8
|
||||
image: golang:1.15
|
||||
image: golang:1.17
|
||||
pull: never
|
||||
volumes:
|
||||
- name: cache
|
||||
|
@ -136,7 +136,7 @@ trigger:
|
|||
- refs/pull/*/head
|
||||
steps:
|
||||
- name: test-mariadb
|
||||
image: golang:1.15
|
||||
image: golang:1.17
|
||||
pull: never
|
||||
volumes:
|
||||
- name: cache
|
||||
|
@ -175,7 +175,7 @@ trigger:
|
|||
steps:
|
||||
- name: test-postgres
|
||||
pull: never
|
||||
image: golang:1.15
|
||||
image: golang:1.17
|
||||
volumes:
|
||||
- name: cache
|
||||
path: /go/pkg/mod
|
||||
|
@ -190,7 +190,7 @@ steps:
|
|||
|
||||
- name: test-postgres-schema
|
||||
pull: never
|
||||
image: golang:1.15
|
||||
image: golang:1.17
|
||||
volumes:
|
||||
- name: cache
|
||||
path: /go/pkg/mod
|
||||
|
@ -207,7 +207,7 @@ steps:
|
|||
|
||||
- name: test-pgx
|
||||
pull: never
|
||||
image: golang:1.15
|
||||
image: golang:1.17
|
||||
volumes:
|
||||
- name: cache
|
||||
path: /go/pkg/mod
|
||||
|
@ -225,7 +225,7 @@ steps:
|
|||
|
||||
- name: test-pgx-schema
|
||||
pull: never
|
||||
image: golang:1.15
|
||||
image: golang:1.17
|
||||
volumes:
|
||||
- name: cache
|
||||
path: /go/pkg/mod
|
||||
|
@ -267,7 +267,7 @@ trigger:
|
|||
steps:
|
||||
- name: test-mssql
|
||||
pull: never
|
||||
image: golang:1.15
|
||||
image: golang:1.17
|
||||
volumes:
|
||||
- name: cache
|
||||
path: /go/pkg/mod
|
||||
|
@ -306,7 +306,7 @@ trigger:
|
|||
steps:
|
||||
- name: test-tidb
|
||||
pull: never
|
||||
image: golang:1.15
|
||||
image: golang:1.17
|
||||
volumes:
|
||||
- name: cache
|
||||
path: /go/pkg/mod
|
||||
|
@ -339,7 +339,7 @@ trigger:
|
|||
steps:
|
||||
- name: test-cockroach
|
||||
pull: never
|
||||
image: golang:1.15
|
||||
image: golang:1.17
|
||||
volumes:
|
||||
- name: cache
|
||||
path: /go/pkg/mod
|
||||
|
@ -375,7 +375,7 @@ services:
|
|||
# steps:
|
||||
# - name: test-dameng
|
||||
# pull: never
|
||||
# image: golang:1.15
|
||||
# image: golang:1.17
|
||||
# volumes:
|
||||
# - name: cache
|
||||
# path: /go/pkg/mod
|
||||
|
@ -416,7 +416,7 @@ trigger:
|
|||
- refs/pull/*/head
|
||||
steps:
|
||||
- name: merge_coverage
|
||||
image: golang:1.15
|
||||
image: golang:1.17
|
||||
commands:
|
||||
- make coverage
|
||||
|
||||
|
|
|
@ -53,6 +53,7 @@ Drivers for Go's sql package which currently support database/sql includes:
|
|||
* Oracle
|
||||
- [github.com/godror/godror](https://github.com/godror/godror) (experiment)
|
||||
- [github.com/mattn/go-oci8](https://github.com/mattn/go-oci8) (experiment)
|
||||
- [github.com/sijms/go-ora](https://github.com/sijms/go-ora) (experiment)
|
||||
|
||||
## Installation
|
||||
|
||||
|
|
|
@ -290,6 +290,7 @@ func regDrvsNDialects() bool {
|
|||
"sqlite": {"sqlite3", func() Driver { return &sqlite3Driver{} }, func() Dialect { return &sqlite3{} }},
|
||||
"oci8": {"oracle", func() Driver { return &oci8Driver{} }, func() Dialect { return &oracle{} }},
|
||||
"godror": {"oracle", func() Driver { return &godrorDriver{} }, func() Dialect { return &oracle{} }},
|
||||
"oracle": {"oracle", func() Driver { return &oracleDriver{} }, func() Dialect { return &oracle{} }},
|
||||
}
|
||||
|
||||
for driverName, v := range providedDrvsNDialects {
|
||||
|
|
|
@ -939,3 +939,7 @@ func (o *oci8Driver) Parse(driverName, dataSourceName string) (*URI, error) {
|
|||
}
|
||||
return db, nil
|
||||
}
|
||||
|
||||
type oracleDriver struct {
|
||||
godrorDriver
|
||||
}
|
||||
|
|
13
doc.go
13
doc.go
|
@ -3,16 +3,15 @@
|
|||
// license that can be found in the LICENSE file.
|
||||
|
||||
/*
|
||||
|
||||
Package xorm is a simple and powerful ORM for Go.
|
||||
|
||||
Installation
|
||||
# Installation
|
||||
|
||||
Make sure you have installed Go 1.11+ and then:
|
||||
|
||||
go get xorm.io/xorm
|
||||
|
||||
Create Engine
|
||||
# Create Engine
|
||||
|
||||
Firstly, we should create an engine for a database
|
||||
|
||||
|
@ -21,7 +20,7 @@ Firstly, we should create an engine for a database
|
|||
Method NewEngine's parameters are the same as sql.Open which depend drivers' implementation.
|
||||
Generally, one engine for an application is enough. You can define it as a package variable.
|
||||
|
||||
Raw Methods
|
||||
# Raw Methods
|
||||
|
||||
XORM supports raw SQL execution:
|
||||
|
||||
|
@ -41,7 +40,7 @@ XORM supports raw SQL execution:
|
|||
|
||||
affected, err := engine.Exec("update user set .... where ...")
|
||||
|
||||
ORM Methods
|
||||
# ORM Methods
|
||||
|
||||
There are 8 major ORM methods and many helpful methods to use to operate database.
|
||||
|
||||
|
@ -142,7 +141,7 @@ or
|
|||
sumInt64s, err := engine.SumsInt(&user, "id1", "id2")
|
||||
// SELECT sum(id1), sum(id2) from user
|
||||
|
||||
Conditions
|
||||
# Conditions
|
||||
|
||||
The above 8 methods could use with condition methods chainable.
|
||||
Notice: the above 8 methods should be the last chainable method.
|
||||
|
@ -204,7 +203,7 @@ Notice: the above 8 methods should be the last chainable method.
|
|||
engine.Join("LEFT", "userdetail", "user.id=userdetail.id").Find(&users)
|
||||
//SELECT * FROM user LEFT JOIN userdetail ON user.id=userdetail.id
|
||||
|
||||
Builder
|
||||
# Builder
|
||||
|
||||
xorm could work with xorm.io/builder directly.
|
||||
|
||||
|
|
12
engine.go
12
engine.go
|
@ -815,6 +815,9 @@ func (engine *Engine) dumpTables(ctx context.Context, tables []*schemas.Table, w
|
|||
return err
|
||||
}
|
||||
}
|
||||
// !datbeohbbh! if no error, manually close
|
||||
rows.Close()
|
||||
sess.Close()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -1230,12 +1233,21 @@ func (engine *Engine) Update(bean interface{}, condiBeans ...interface{}) (int64
|
|||
}
|
||||
|
||||
// Delete records, bean's non-empty fields are conditions
|
||||
// At least one condition must be set.
|
||||
func (engine *Engine) Delete(beans ...interface{}) (int64, error) {
|
||||
session := engine.NewSession()
|
||||
defer session.Close()
|
||||
return session.Delete(beans...)
|
||||
}
|
||||
|
||||
// Truncate records, bean's non-empty fields are conditions
|
||||
// In contrast to Delete this method allows deletes without conditions.
|
||||
func (engine *Engine) Truncate(beans ...interface{}) (int64, error) {
|
||||
session := engine.NewSession()
|
||||
defer session.Close()
|
||||
return session.Truncate(beans...)
|
||||
}
|
||||
|
||||
// Get retrieve one record from table, bean's non-empty fields
|
||||
// are conditions
|
||||
func (engine *Engine) Get(beans ...interface{}) (bool, error) {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build dm
|
||||
// +build dm
|
||||
|
||||
package integrations
|
||||
|
|
|
@ -208,7 +208,7 @@ func TestUnscopeDelete(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 1, cnt)
|
||||
|
||||
var nowUnix = time.Now().Unix()
|
||||
nowUnix := time.Now().Unix()
|
||||
var s UnscopeDeleteStruct
|
||||
cnt, err = testEngine.ID(1).Delete(&s)
|
||||
assert.NoError(t, err)
|
||||
|
@ -266,3 +266,28 @@ func TestDelete2(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.False(t, has)
|
||||
}
|
||||
|
||||
func TestTruncate(t *testing.T) {
|
||||
assert.NoError(t, PrepareEngine())
|
||||
|
||||
type TruncateUser struct {
|
||||
Uid int64 `xorm:"id pk not null autoincr"`
|
||||
}
|
||||
|
||||
assert.NoError(t, testEngine.Sync(new(TruncateUser)))
|
||||
|
||||
cnt, err := testEngine.Insert(&TruncateUser{})
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 1, cnt)
|
||||
|
||||
_, err = testEngine.Delete(&TruncateUser{})
|
||||
assert.Error(t, err)
|
||||
|
||||
_, err = testEngine.Truncate(&TruncateUser{})
|
||||
assert.NoError(t, err)
|
||||
|
||||
user2 := TruncateUser{}
|
||||
has, err := testEngine.ID(1).Get(&user2)
|
||||
assert.NoError(t, err)
|
||||
assert.False(t, has)
|
||||
}
|
||||
|
|
|
@ -744,7 +744,8 @@ func TestInsertMap(t *testing.T) {
|
|||
assert.EqualValues(t, "lunny", ims[3].Name)
|
||||
}
|
||||
|
||||
/*INSERT INTO `issue` (`repo_id`, `poster_id`, ... ,`name`, `content`, ... ,`index`)
|
||||
/*
|
||||
INSERT INTO `issue` (`repo_id`, `poster_id`, ... ,`name`, `content`, ... ,`index`)
|
||||
SELECT $1, $2, ..., $14, $15, ..., MAX(`index`) + 1 FROM `issue` WHERE `repo_id` = $1;
|
||||
*/
|
||||
func TestInsertWhere(t *testing.T) {
|
||||
|
|
|
@ -31,6 +31,7 @@ type Interface interface {
|
|||
Decr(column string, arg ...interface{}) *Session
|
||||
Desc(...string) *Session
|
||||
Delete(...interface{}) (int64, error)
|
||||
Truncate(...interface{}) (int64, error)
|
||||
Distinct(columns ...string) *Session
|
||||
DropIndexes(bean interface{}) error
|
||||
Exec(sqlOrArgs ...interface{}) (sql.Result, error)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build gojson
|
||||
// +build gojson
|
||||
|
||||
package json
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build jsoniter
|
||||
// +build jsoniter
|
||||
|
||||
package json
|
||||
|
|
|
@ -163,6 +163,7 @@ func (q Quoter) quoteWordTo(buf *strings.Builder, word string) error {
|
|||
}
|
||||
|
||||
// QuoteTo quotes the table or column names. i.e. if the quotes are [ and ]
|
||||
//
|
||||
// name -> [name]
|
||||
// `name` -> [name]
|
||||
// [name] -> [name]
|
||||
|
|
|
@ -91,7 +91,18 @@ func (session *Session) cacheDelete(table *schemas.Table, tableName, sqlStr stri
|
|||
}
|
||||
|
||||
// Delete records, bean's non-empty fields are conditions
|
||||
// At least one condition must be set.
|
||||
func (session *Session) Delete(beans ...interface{}) (int64, error) {
|
||||
return session.delete(beans, true)
|
||||
}
|
||||
|
||||
// Truncate records, bean's non-empty fields are conditions
|
||||
// In contrast to Delete this method allows deletes without conditions.
|
||||
func (session *Session) Truncate(beans ...interface{}) (int64, error) {
|
||||
return session.delete(beans, false)
|
||||
}
|
||||
|
||||
func (session *Session) delete(beans []interface{}, mustHaveConditions bool) (int64, error) {
|
||||
if session.isAutoClose {
|
||||
defer session.Close()
|
||||
}
|
||||
|
@ -127,7 +138,7 @@ func (session *Session) Delete(beans ...interface{}) (int64, error) {
|
|||
}
|
||||
|
||||
pLimitN := session.statement.LimitN
|
||||
if condWriter.Len() == 0 && (pLimitN == nil || *pLimitN == 0) {
|
||||
if mustHaveConditions && condWriter.Len() == 0 && (pLimitN == nil || *pLimitN == 0) {
|
||||
return 0, ErrNeedDeletedCond
|
||||
}
|
||||
|
||||
|
|
|
@ -145,6 +145,7 @@ func (session *Session) cacheUpdate(table *schemas.Table, tableName, sqlStr stri
|
|||
// Update records, bean's non-empty fields are updated contents,
|
||||
// condiBean' non-empty filds are conditions
|
||||
// CAUTION:
|
||||
//
|
||||
// 1.bool will defaultly be updated content nor conditions
|
||||
// You should call UseBool if you have bool to use.
|
||||
// 2.float32 & float64 may be not inexact as conditions
|
||||
|
|
Loading…
Reference in New Issue