mirror of
https://github.com/tangpanqing/aorm.git
synced 2025-09-26 20:11:29 +08:00
update WhereISNULL WhereISNOTNULL
This commit is contained in:
@@ -510,7 +510,7 @@ func (b *Builder) whereAndHaving(where []WhereItem, args []any, isFromHaving boo
|
||||
}
|
||||
|
||||
if where[i].Opt == Raw {
|
||||
whereList = append(whereList, allFieldName+fmt.Sprintf("%v", where[i].Val))
|
||||
whereList = append(whereList, allFieldName+" "+fmt.Sprintf("%v", where[i].Val))
|
||||
}
|
||||
|
||||
if where[i].Opt == RawEq {
|
||||
|
@@ -89,6 +89,14 @@ func (b *Builder) WhereFindInSet(val interface{}, field interface{}, prefix ...s
|
||||
return b.whereItemAppend(field, FindInSet, val, prefix...)
|
||||
}
|
||||
|
||||
func (b *Builder) WhereIsNull(field interface{}, prefix ...string) *Builder {
|
||||
return b.whereItemAppend(field, Raw, "IS NULL", prefix...)
|
||||
}
|
||||
|
||||
func (b *Builder) WhereIsNOTNull(field interface{}, prefix ...string) *Builder {
|
||||
return b.whereItemAppend(field, Raw, "IS NOT NULL", prefix...)
|
||||
}
|
||||
|
||||
func (b *Builder) WhereRawEq(field interface{}, val interface{}, prefix ...string) *Builder {
|
||||
return b.whereItemAppend(field, RawEq, val, prefix...)
|
||||
}
|
||||
|
10
go.mod
10
go.mod
@@ -2,13 +2,15 @@ module github.com/tangpanqing/aorm
|
||||
|
||||
go 1.18
|
||||
|
||||
require github.com/go-sql-driver/mysql v1.7.0
|
||||
require (
|
||||
github.com/denisenkom/go-mssqldb v0.12.3
|
||||
github.com/go-sql-driver/mysql v1.7.0
|
||||
github.com/lib/pq v1.10.7
|
||||
github.com/mattn/go-sqlite3 v1.14.16
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/denisenkom/go-mssqldb v0.12.3 // indirect
|
||||
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
|
||||
github.com/golang-sql/sqlexp v0.1.0 // indirect
|
||||
github.com/lib/pq v1.10.7 // indirect
|
||||
github.com/mattn/go-sqlite3 v1.14.16 // indirect
|
||||
golang.org/x/crypto v0.4.0 // indirect
|
||||
)
|
||||
|
@@ -116,6 +116,8 @@ func TestAll(t *testing.T) {
|
||||
testGetMany(dbItem)
|
||||
testUpdate(dbItem, id)
|
||||
|
||||
testNull(dbItem, id)
|
||||
|
||||
isExists := testExists(dbItem, id)
|
||||
if isExists != true {
|
||||
panic("应该存在,但是数据库不存在")
|
||||
@@ -361,6 +363,19 @@ func testExists(db *base.Db, id int64) bool {
|
||||
return exists
|
||||
}
|
||||
|
||||
func testNull(db *base.Db, id int64) {
|
||||
var p Person
|
||||
err := aorm.Db(db).Table(&person).WhereIsNOTNull(&person.Id).WhereEq(&person.Id, id).OrderBy(&person.Id, builder.Desc).Debug(false).GetOne(&p)
|
||||
if err != nil {
|
||||
panic(db.DriverName() + " test WhereIsNOTNull " + "found err:" + err.Error())
|
||||
}
|
||||
|
||||
_, err = aorm.Db(db).Table(&person).WhereIsNull(&person.Id).Debug(false).Count("*")
|
||||
if err != nil {
|
||||
panic(db.DriverName() + " test WhereIsNull " + "found err:" + err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func testTable(db *base.Db) {
|
||||
_, err := aorm.Db(db).Table("person_1").Insert(&Person{Name: null.StringFrom("Cherry")})
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user