1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 14:50:55 +00:00
Beego/orm/qb.go

63 lines
2.0 KiB
Go
Raw Normal View History

2014-09-08 09:37:01 +00:00
// Copyright 2014 beego Author. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package orm
2014-09-08 09:56:55 +00:00
import "errors"
2015-09-12 13:46:43 +00:00
// QueryBuilder is the Query builder interface
2014-09-08 09:37:01 +00:00
type QueryBuilder interface {
Select(fields ...string) QueryBuilder
ForUpdate() QueryBuilder
From(tables ...string) QueryBuilder
InnerJoin(table string) QueryBuilder
LeftJoin(table string) QueryBuilder
2014-09-09 06:17:12 +00:00
RightJoin(table string) QueryBuilder
On(cond string) QueryBuilder
2014-09-09 06:17:12 +00:00
Where(cond string) QueryBuilder
And(cond string) QueryBuilder
Or(cond string) QueryBuilder
In(vals ...string) QueryBuilder
2014-09-09 06:17:12 +00:00
OrderBy(fields ...string) QueryBuilder
Asc() QueryBuilder
Desc() QueryBuilder
Limit(limit int) QueryBuilder
Offset(offset int) QueryBuilder
GroupBy(fields ...string) QueryBuilder
Having(cond string) QueryBuilder
2014-09-11 05:48:39 +00:00
Update(tables ...string) QueryBuilder
Set(kv ...string) QueryBuilder
Delete(tables ...string) QueryBuilder
InsertInto(table string, fields ...string) QueryBuilder
Values(vals ...string) QueryBuilder
2014-09-09 06:17:12 +00:00
Subquery(sub string, alias string) string
2014-09-08 09:37:01 +00:00
String() string
}
2014-09-08 09:47:15 +00:00
2015-09-12 13:46:43 +00:00
// NewQueryBuilder return the QueryBuilder
2014-09-08 09:56:55 +00:00
func NewQueryBuilder(driver string) (qb QueryBuilder, err error) {
if driver == "mysql" {
qb = new(MySQLQueryBuilder)
2015-09-11 03:24:58 +00:00
} else if driver == "tidb" {
qb = new(TiDBQueryBuilder)
2014-09-08 09:56:55 +00:00
} else if driver == "postgres" {
2015-09-12 13:46:43 +00:00
err = errors.New("postgres query builder is not supported yet")
2014-09-08 09:56:55 +00:00
} else if driver == "sqlite" {
2015-09-12 13:46:43 +00:00
err = errors.New("sqlite query builder is not supported yet")
2014-09-08 09:56:55 +00:00
} else {
2015-09-12 13:46:43 +00:00
err = errors.New("unknown driver for query builder")
2014-09-08 09:56:55 +00:00
}
2014-09-08 09:47:15 +00:00
return
}