1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 17:30:56 +00:00

name correction: QueryBuilder instead of QueryWriter

This commit is contained in:
Zheng Yang 2014-09-08 18:31:32 +08:00
parent f9a9b5a905
commit cca0a3f76d
2 changed files with 20 additions and 20 deletions

View File

@ -17,16 +17,16 @@ package orm
import "errors"
type QueryBuilder interface {
Select(fields ...string) QueryWriter
From(tables ...string) QueryWriter
Where(cond string) QueryWriter
LimitOffset(limit int, offset int) QueryWriter
InnerJoin(table string) QueryWriter
LeftJoin(table string) QueryWriter
On(cond string) QueryWriter
And(cond string) QueryWriter
Or(cond string) QueryWriter
In(vals ...string) QueryWriter
Select(fields ...string) QueryBuilder
From(tables ...string) QueryBuilder
Where(cond string) QueryBuilder
LimitOffset(limit int, offset int) QueryBuilder
InnerJoin(table string) QueryBuilder
LeftJoin(table string) QueryBuilder
On(cond string) QueryBuilder
And(cond string) QueryBuilder
Or(cond string) QueryBuilder
In(vals ...string) QueryBuilder
Subquery(query string, rename string) string
String() string
}

View File

@ -23,54 +23,54 @@ type MySQLQueryBuilder struct {
QueryString []string
}
func (qw *MySQLQueryBuilder) Select(fields ...string) QueryWriter {
func (qw *MySQLQueryBuilder) Select(fields ...string) QueryBuilder {
segment := fmt.Sprintf("SELECT %s", strings.Join(fields, ", "))
qw.QueryString = append(qw.QueryString, segment)
return qw
}
func (qw *MySQLQueryBuilder) From(tables ...string) QueryWriter {
func (qw *MySQLQueryBuilder) From(tables ...string) QueryBuilder {
segment := fmt.Sprintf("FROM %s", strings.Join(tables, ", "))
qw.QueryString = append(qw.QueryString, segment)
return qw
}
func (qw *MySQLQueryBuilder) Where(cond string) QueryWriter {
func (qw *MySQLQueryBuilder) Where(cond string) QueryBuilder {
qw.QueryString = append(qw.QueryString, "WHERE "+cond)
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))
return qw
}
func (qw *MySQLQueryBuilder) InnerJoin(table string) QueryWriter {
func (qw *MySQLQueryBuilder) InnerJoin(table string) QueryBuilder {
qw.QueryString = append(qw.QueryString, "INNER JOIN "+table)
return qw
}
func (qw *MySQLQueryBuilder) LeftJoin(table string) QueryWriter {
func (qw *MySQLQueryBuilder) LeftJoin(table string) QueryBuilder {
qw.QueryString = append(qw.QueryString, "LEFT JOIN "+table)
return qw
}
func (qw *MySQLQueryBuilder) On(cond string) QueryWriter {
func (qw *MySQLQueryBuilder) On(cond string) QueryBuilder {
qw.QueryString = append(qw.QueryString, "ON "+cond)
return qw
}
func (qw *MySQLQueryBuilder) And(cond string) QueryWriter {
func (qw *MySQLQueryBuilder) And(cond string) QueryBuilder {
qw.QueryString = append(qw.QueryString, "AND "+cond)
return qw
}
func (qw *MySQLQueryBuilder) Or(cond string) QueryWriter {
func (qw *MySQLQueryBuilder) Or(cond string) QueryBuilder {
qw.QueryString = append(qw.QueryString, "OR "+cond)
return qw
}
func (qw *MySQLQueryBuilder) In(vals ...string) QueryWriter {
func (qw *MySQLQueryBuilder) In(vals ...string) QueryBuilder {
segment := fmt.Sprintf("IN (%s)", strings.Join(vals, ", "))
qw.QueryString = append(qw.QueryString, segment)
return qw