修改condetion 拼写错误,改成condition

This commit is contained in:
windha
2021-08-04 12:08:33 +08:00
parent e0856cb712
commit 83fd5c0f91
5 changed files with 26 additions and 26 deletions

View File

@@ -112,13 +112,13 @@ func CloseRelated() {
// 自定义sql查询
type Condetion struct {
list []*condetionInfo
type Condition struct {
list []*conditionInfo
}
// And a condition by and .and 一个条件
func (c *Condetion) And(column string, cases string, value ...interface{}) {
c.list = append(c.list, &condetionInfo{
func (c *Condition) And(column string, cases string, value ...interface{}) {
c.list = append(c.list, &conditionInfo{
andor: "and",
column: column, // 列名
case_: cases, // 条件(and,or,in,>=,<=)
@@ -127,8 +127,8 @@ func (c *Condetion) And(column string, cases string, value ...interface{}) {
}
// Or a condition by or .or 一个条件
func (c *Condetion) Or(column string, cases string, value ...interface{}) {
c.list = append(c.list, &condetionInfo{
func (c *Condition) Or(column string, cases string, value ...interface{}) {
c.list = append(c.list, &conditionInfo{
andor: "or",
column: column, // 列名
case_: cases, // 条件(and,or,in,>=,<=)
@@ -136,7 +136,7 @@ func (c *Condetion) Or(column string, cases string, value ...interface{}) {
})
}
func (c *Condetion) Get() (where string, out []interface{}) {
func (c *Condition) Get() (where string, out []interface{}) {
firstAnd := -1
for i := 0; i < len(c.list); i++ { // 查找第一个and
if c.list[i].andor == "and" {
@@ -163,7 +163,7 @@ func (c *Condetion) Get() (where string, out []interface{}) {
return
}
type condetionInfo struct {
type conditionInfo struct {
andor string
column string // 列名
case_ string // 条件(in,>=,<=)

View File

@@ -138,14 +138,14 @@ func TestFuncFetchBy(t *testing.T) {
fmt.Println(accounts)
}
// TestCondetion 测试sql构建
func TestCondetion(t *testing.T) {
condetion := model.Condetion{}
condetion.And(model.AccountColumns.AccountID, ">=", "1")
condetion.And(model.AccountColumns.UserID, "in", "1", "2", "3")
condetion.Or(model.AccountColumns.Type, "in", "1", "2", "3")
// TestCondition 测试sql构建
func TestCondition(t *testing.T) {
condition := model.Condition{}
condition.And(model.AccountColumns.AccountID, ">=", "1")
condition.And(model.AccountColumns.UserID, "in", "1", "2", "3")
condition.Or(model.AccountColumns.Type, "in", "1", "2", "3")
where, obj := condetion.Get()
where, obj := condition.Get()
fmt.Println(where)
fmt.Println(obj...)
@@ -155,6 +155,6 @@ func TestCondetion(t *testing.T) {
sqldb.Close()
}()
accountMgr := model.AccountMgr(db.Where(condetion.Get()))
accountMgr := model.AccountMgr(db.Where(condition.Get()))
accountMgr.Gets()
}

View File

@@ -93,13 +93,13 @@ func CloseRelated() {
}
// 自定义sql查询
type Condetion struct {
list []*condetionInfo
type Condition struct {
list []*conditionInfo
}
// And a condition by and .and 一个条件
func (c *Condetion) And(column string, cases string, value ...interface{}) {
c.list = append(c.list, &condetionInfo{
func (c *Condition) And(column string, cases string, value ...interface{}) {
c.list = append(c.list, &conditionInfo{
andor: "and",
column: column, // 列名
case_: cases, // 条件(and,or,in,>=,<=)
@@ -108,8 +108,8 @@ func (c *Condetion) And(column string, cases string, value ...interface{}) {
}
// Or a condition by or .or 一个条件
func (c *Condetion) Or(column string, cases string, value ...interface{}) {
c.list = append(c.list, &condetionInfo{
func (c *Condition) Or(column string, cases string, value ...interface{}) {
c.list = append(c.list, &conditionInfo{
andor: "or",
column: column, // 列名
case_: cases, // 条件(and,or,in,>=,<=)
@@ -117,7 +117,7 @@ func (c *Condetion) Or(column string, cases string, value ...interface{}) {
})
}
func (c *Condetion) Get() (where string, out []interface{}) {
func (c *Condition) Get() (where string, out []interface{}) {
firstAnd := -1
for i := 0; i < len(c.list); i++ { // 查找第一个and
if c.list[i].andor == "and" {
@@ -144,7 +144,7 @@ func (c *Condetion) Get() (where string, out []interface{}) {
return
}
type condetionInfo struct {
type conditionInfo struct {
andor string
column string // 列名
case_ string // 条件(in,>=,<=)