1// Copyright 2014 beego Author. All Rights Reserved. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15package orm 16 17import "errors" 18 19// QueryBuilder is the Query builder interface 20type QueryBuilder interface { 21 Select(fields ...string) QueryBuilder 22 ForUpdate() QueryBuilder 23 From(tables ...string) QueryBuilder 24 InnerJoin(table string) QueryBuilder 25 LeftJoin(table string) QueryBuilder 26 RightJoin(table string) QueryBuilder 27 On(cond string) QueryBuilder 28 Where(cond string) QueryBuilder 29 And(cond string) QueryBuilder 30 Or(cond string) QueryBuilder 31 In(vals ...string) QueryBuilder 32 OrderBy(fields ...string) QueryBuilder 33 Asc() QueryBuilder 34 Desc() QueryBuilder 35 Limit(limit int) QueryBuilder 36 Offset(offset int) QueryBuilder 37 GroupBy(fields ...string) QueryBuilder 38 Having(cond string) QueryBuilder 39 Update(tables ...string) QueryBuilder 40 Set(kv ...string) QueryBuilder 41 Delete(tables ...string) QueryBuilder 42 InsertInto(table string, fields ...string) QueryBuilder 43 Values(vals ...string) QueryBuilder 44 Subquery(sub string, alias string) string 45 String() string 46} 47 48// NewQueryBuilder return the QueryBuilder 49func NewQueryBuilder(driver string) (qb QueryBuilder, err error) { 50 if driver == "mysql" { 51 qb = new(MySQLQueryBuilder) 52 } else if driver == "tidb" { 53 qb = new(TiDBQueryBuilder) 54 } else if driver == "postgres" { 55 err = errors.New("postgres query builder is not supported yet") 56 } else if driver == "sqlite" { 57 err = errors.New("sqlite query builder is not supported yet") 58 } else { 59 err = errors.New("unknown driver for query builder") 60 } 61 return 62} 63