|
|
@@ -1,13 +1,10 @@
|
|
|
# SQL builder
|
|
|
|
|
|
-[](https://gitci.cn/go-xorm/builder) [](https://codecov.io/gh/go-xorm/builder)
|
|
|
-[](https://goreportcard.com/report/github.com/go-xorm/builder)
|
|
|
-
|
|
|
Package builder is a lightweight and fast SQL builder for Go and XORM.
|
|
|
|
|
|
Make sure you have installed Go 1.8+ and then:
|
|
|
|
|
|
- go get github.com/go-xorm/builder
|
|
|
+ go get github.com/xormplus/builder
|
|
|
|
|
|
# Insert
|
|
|
|
|
|
@@ -71,7 +68,7 @@ sql, args, err := Select("*").From("a").Where(Eq{"status": "1"}).
|
|
|
* `Eq` is a redefine of a map, you can give one or more conditions to `Eq`
|
|
|
|
|
|
```Go
|
|
|
-import . "github.com/go-xorm/builder"
|
|
|
+import . "github.com/xormplus/builder"
|
|
|
|
|
|
sql, args, _ := ToSQL(Eq{"a":1})
|
|
|
// a=? [1]
|
|
|
@@ -90,7 +87,7 @@ sql, args, _ := ToSQL(Eq{"b": 1, "c":[]int{2, 3}})
|
|
|
* `Neq` is the same to `Eq`
|
|
|
|
|
|
```Go
|
|
|
-import . "github.com/go-xorm/builder"
|
|
|
+import . "github.com/xormplus/builder"
|
|
|
|
|
|
sql, args, _ := ToSQL(Neq{"a":1})
|
|
|
// a<>? [1]
|
|
|
@@ -109,7 +106,7 @@ sql, args, _ := ToSQL(Neq{"b": 1, "c":[]int{2, 3}})
|
|
|
* `Gt`, `Gte`, `Lt`, `Lte`
|
|
|
|
|
|
```Go
|
|
|
-import . "github.com/go-xorm/builder"
|
|
|
+import . "github.com/xormplus/builder"
|
|
|
|
|
|
sql, args, _ := ToSQL(Gt{"a", 1}.And(Gte{"b", 2}))
|
|
|
// a>? AND b>=? [1, 2]
|
|
|
@@ -120,7 +117,7 @@ sql, args, _ := ToSQL(Lt{"a", 1}.Or(Lte{"b", 2}))
|
|
|
* `Like`
|
|
|
|
|
|
```Go
|
|
|
-import . "github.com/go-xorm/builder"
|
|
|
+import . "github.com/xormplus/builder"
|
|
|
|
|
|
sql, args, _ := ToSQL(Like{"a", "c"})
|
|
|
// a LIKE ? [%c%]
|
|
|
@@ -129,7 +126,7 @@ sql, args, _ := ToSQL(Like{"a", "c"})
|
|
|
* `Expr` you can customerize your sql with `Expr`
|
|
|
|
|
|
```Go
|
|
|
-import . "github.com/go-xorm/builder"
|
|
|
+import . "github.com/xormplus/builder"
|
|
|
|
|
|
sql, args, _ := ToSQL(Expr("a = ? ", 1))
|
|
|
// a = ? [1]
|
|
|
@@ -140,7 +137,7 @@ sql, args, _ := ToSQL(Eq{"a": Expr("select id from table where c = ?", 1)})
|
|
|
* `In` and `NotIn`
|
|
|
|
|
|
```Go
|
|
|
-import . "github.com/go-xorm/builder"
|
|
|
+import . "github.com/xormplus/builder"
|
|
|
|
|
|
sql, args, _ := ToSQL(In("a", 1, 2, 3))
|
|
|
// a IN (?,?,?) [1,2,3]
|
|
|
@@ -153,7 +150,7 @@ sql, args, _ := ToSQL(In("a", Expr("select id from b where c = ?", 1))))
|
|
|
* `IsNull` and `NotNull`
|
|
|
|
|
|
```Go
|
|
|
-import . "github.com/go-xorm/builder"
|
|
|
+import . "github.com/xormplus/builder"
|
|
|
|
|
|
sql, args, _ := ToSQL(IsNull{"a"})
|
|
|
// a IS NULL []
|
|
|
@@ -164,7 +161,7 @@ sql, args, _ := ToSQL(NotNull{"b"})
|
|
|
* `And(conds ...Cond)`, And can connect one or more condtions via And
|
|
|
|
|
|
```Go
|
|
|
-import . "github.com/go-xorm/builder"
|
|
|
+import . "github.com/xormplus/builder"
|
|
|
|
|
|
sql, args, _ := ToSQL(And(Eq{"a":1}, Like{"b", "c"}, Neq{"d", 2}))
|
|
|
// a=? AND b LIKE ? AND d<>? [1, %c%, 2]
|
|
|
@@ -173,7 +170,7 @@ sql, args, _ := ToSQL(And(Eq{"a":1}, Like{"b", "c"}, Neq{"d", 2}))
|
|
|
* `Or(conds ...Cond)`, Or can connect one or more conditions via Or
|
|
|
|
|
|
```Go
|
|
|
-import . "github.com/go-xorm/builder"
|
|
|
+import . "github.com/xormplus/builder"
|
|
|
|
|
|
sql, args, _ := ToSQL(Or(Eq{"a":1}, Like{"b", "c"}, Neq{"d", 2}))
|
|
|
// a=? OR b LIKE ? OR d<>? [1, %c%, 2]
|
|
|
@@ -184,7 +181,7 @@ sql, args, _ := ToSQL(Or(Eq{"a":1}, And(Like{"b", "c"}, Neq{"d", 2})))
|
|
|
* `Between`
|
|
|
|
|
|
```Go
|
|
|
-import . "github.com/go-xorm/builder"
|
|
|
+import . "github.com/xormplus/builder"
|
|
|
|
|
|
sql, args, _ := ToSQL(Between{"a", 1, 2})
|
|
|
// a BETWEEN 1 AND 2
|
|
|
@@ -203,4 +200,4 @@ type Cond interface {
|
|
|
}
|
|
|
```
|
|
|
|
|
|
-You can define yourself conditions and compose with other `Cond`.
|
|
|
+You can define yourself conditions and compose with other `Cond`.
|