mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 22:10:55 +00:00
name correction: QueryBuilder instead of QueryWriter
This commit is contained in:
parent
f9a9b5a905
commit
cca0a3f76d
20
orm/qb.go
20
orm/qb.go
@ -17,16 +17,16 @@ package orm
|
|||||||
import "errors"
|
import "errors"
|
||||||
|
|
||||||
type QueryBuilder interface {
|
type QueryBuilder interface {
|
||||||
Select(fields ...string) QueryWriter
|
Select(fields ...string) QueryBuilder
|
||||||
From(tables ...string) QueryWriter
|
From(tables ...string) QueryBuilder
|
||||||
Where(cond string) QueryWriter
|
Where(cond string) QueryBuilder
|
||||||
LimitOffset(limit int, offset int) QueryWriter
|
LimitOffset(limit int, offset int) QueryBuilder
|
||||||
InnerJoin(table string) QueryWriter
|
InnerJoin(table string) QueryBuilder
|
||||||
LeftJoin(table string) QueryWriter
|
LeftJoin(table string) QueryBuilder
|
||||||
On(cond string) QueryWriter
|
On(cond string) QueryBuilder
|
||||||
And(cond string) QueryWriter
|
And(cond string) QueryBuilder
|
||||||
Or(cond string) QueryWriter
|
Or(cond string) QueryBuilder
|
||||||
In(vals ...string) QueryWriter
|
In(vals ...string) QueryBuilder
|
||||||
Subquery(query string, rename string) string
|
Subquery(query string, rename string) string
|
||||||
String() string
|
String() string
|
||||||
}
|
}
|
||||||
|
@ -23,54 +23,54 @@ type MySQLQueryBuilder struct {
|
|||||||
QueryString []string
|
QueryString []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qw *MySQLQueryBuilder) Select(fields ...string) QueryWriter {
|
func (qw *MySQLQueryBuilder) Select(fields ...string) QueryBuilder {
|
||||||
segment := fmt.Sprintf("SELECT %s", strings.Join(fields, ", "))
|
segment := fmt.Sprintf("SELECT %s", strings.Join(fields, ", "))
|
||||||
qw.QueryString = append(qw.QueryString, segment)
|
qw.QueryString = append(qw.QueryString, segment)
|
||||||
return qw
|
return qw
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qw *MySQLQueryBuilder) From(tables ...string) QueryWriter {
|
func (qw *MySQLQueryBuilder) From(tables ...string) QueryBuilder {
|
||||||
segment := fmt.Sprintf("FROM %s", strings.Join(tables, ", "))
|
segment := fmt.Sprintf("FROM %s", strings.Join(tables, ", "))
|
||||||
qw.QueryString = append(qw.QueryString, segment)
|
qw.QueryString = append(qw.QueryString, segment)
|
||||||
return qw
|
return qw
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qw *MySQLQueryBuilder) Where(cond string) QueryWriter {
|
func (qw *MySQLQueryBuilder) Where(cond string) QueryBuilder {
|
||||||
qw.QueryString = append(qw.QueryString, "WHERE "+cond)
|
qw.QueryString = append(qw.QueryString, "WHERE "+cond)
|
||||||
return qw
|
return qw
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qw *MySQLQueryBuilder) LimitOffset(limit int, offset int) QueryWriter {
|
func (qw *MySQLQueryBuilder) LimitOffset(limit int, offset int) QueryBuilder {
|
||||||
qw.QueryString = append(qw.QueryString, fmt.Sprintf("LIMIT %d OFFSET %d", limit, offset))
|
qw.QueryString = append(qw.QueryString, fmt.Sprintf("LIMIT %d OFFSET %d", limit, offset))
|
||||||
return qw
|
return qw
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qw *MySQLQueryBuilder) InnerJoin(table string) QueryWriter {
|
func (qw *MySQLQueryBuilder) InnerJoin(table string) QueryBuilder {
|
||||||
qw.QueryString = append(qw.QueryString, "INNER JOIN "+table)
|
qw.QueryString = append(qw.QueryString, "INNER JOIN "+table)
|
||||||
return qw
|
return qw
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qw *MySQLQueryBuilder) LeftJoin(table string) QueryWriter {
|
func (qw *MySQLQueryBuilder) LeftJoin(table string) QueryBuilder {
|
||||||
qw.QueryString = append(qw.QueryString, "LEFT JOIN "+table)
|
qw.QueryString = append(qw.QueryString, "LEFT JOIN "+table)
|
||||||
return qw
|
return qw
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qw *MySQLQueryBuilder) On(cond string) QueryWriter {
|
func (qw *MySQLQueryBuilder) On(cond string) QueryBuilder {
|
||||||
qw.QueryString = append(qw.QueryString, "ON "+cond)
|
qw.QueryString = append(qw.QueryString, "ON "+cond)
|
||||||
return qw
|
return qw
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qw *MySQLQueryBuilder) And(cond string) QueryWriter {
|
func (qw *MySQLQueryBuilder) And(cond string) QueryBuilder {
|
||||||
qw.QueryString = append(qw.QueryString, "AND "+cond)
|
qw.QueryString = append(qw.QueryString, "AND "+cond)
|
||||||
return qw
|
return qw
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qw *MySQLQueryBuilder) Or(cond string) QueryWriter {
|
func (qw *MySQLQueryBuilder) Or(cond string) QueryBuilder {
|
||||||
qw.QueryString = append(qw.QueryString, "OR "+cond)
|
qw.QueryString = append(qw.QueryString, "OR "+cond)
|
||||||
return qw
|
return qw
|
||||||
}
|
}
|
||||||
|
|
||||||
func (qw *MySQLQueryBuilder) In(vals ...string) QueryWriter {
|
func (qw *MySQLQueryBuilder) In(vals ...string) QueryBuilder {
|
||||||
segment := fmt.Sprintf("IN (%s)", strings.Join(vals, ", "))
|
segment := fmt.Sprintf("IN (%s)", strings.Join(vals, ", "))
|
||||||
qw.QueryString = append(qw.QueryString, segment)
|
qw.QueryString = append(qw.QueryString, segment)
|
||||||
return qw
|
return qw
|
||||||
|
Loading…
Reference in New Issue
Block a user