qb Where条件语句

初始化

package main

import (
  "fmt"
  "github.com/aacanakin/qb"
)

func main() {
  db, _ := qb.New("sqlite3", ":memory:")
  defer db.Close()

  db.Dialect().SetEscaping(true)

  actors := qb.Table(
    "actor",
    qb.Column("id", qb.Varchar().Size(36)),
    qb.Column("name", qb.Varchar().NotNull()),
    qb.Column("nomination_count", qb.Int().Default(0)),
    qb.Column("oscar_count", qb.Int().Default(0)),
    qb.PrimaryKey("id"),
  )

}

例子

sql: SELECT name FROM actor WHERE actor.nomination_count > ?;

sel := actors.
    Select(actors.C("name")).
    Where(actors.C("nomination_count").Gt(0)).
    Build(db.Dialect())

fmt.Println(sel.SQL())
fmt.Println(sel.Bindings())

条件列表

条件.jpg

也可以使用 Condition(col ColumnElem, op string, values ...interface{}) 方法自定义条件

你可能感兴趣的:(qb Where条件语句)