Documentation
¶
Overview ¶
package sqlbuilder provides a simple sql query builder
Index ¶
- Constants
- type BuildFunc
- func And(fns ...BuildFunc) BuildFunc
- func Eq(column string, value interface{}) BuildFunc
- func Expr(expr string, args ...interface{}) BuildFunc
- func Gt(column string, value interface{}) BuildFunc
- func Gte(column string, value interface{}) BuildFunc
- func In(col string, values ...interface{}) BuildFunc
- func IsNull(col string) BuildFunc
- func Like(col, pattern string) BuildFunc
- func Lt(column string, value interface{}) BuildFunc
- func Lte(column string, value interface{}) BuildFunc
- func Neq(column string, value interface{}) BuildFunc
- func Not(fn BuildFunc) BuildFunc
- func NotIn(col string, values ...interface{}) BuildFunc
- func NotNull(col string) BuildFunc
- func Or(fns ...BuildFunc) BuildFunc
- type Builder
- type DeleteBuilder
- type DialectBuilder
- type InsertBuilder
- type Op
- type SelectBuilder
- func (sb *SelectBuilder) From(table string) *SelectBuilder
- func (sb *SelectBuilder) GroupBy(columns ...string) *SelectBuilder
- func (sb *SelectBuilder) Having(cond BuildFunc) *SelectBuilder
- func (sb *SelectBuilder) Join(table string, on BuildFunc) *SelectBuilder
- func (sb *SelectBuilder) LeftJoin(table string, on BuildFunc) *SelectBuilder
- func (sb *SelectBuilder) Limit(limit int) *SelectBuilder
- func (sb *SelectBuilder) Offset(offset int) *SelectBuilder
- func (sb *SelectBuilder) OrderBy(columns ...string) *SelectBuilder
- func (sb *SelectBuilder) Query() (string, []interface{})
- func (sb *SelectBuilder) RightJoin(table string, on BuildFunc) *SelectBuilder
- func (sb *SelectBuilder) Where(cond BuildFunc) *SelectBuilder
- type UpdateBuilder
Constants ¶
const ( Postgres = "postgres" Sqlite = "sqlite" Mysql = "mysql" )
Dialect names
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BuildFunc ¶
type BuildFunc func(*Builder)
the BuildFunc type is used to add sql expressions to the provided builder
type DeleteBuilder ¶
type DeleteBuilder struct { *Builder // contains filtered or unexported fields }
DeleteBuilder is a builder for delete queries
func DeleteFrom ¶
func DeleteFrom(table string) *DeleteBuilder
DeleteFrom create a builder for delete queries
func (*DeleteBuilder) Query ¶
func (db *DeleteBuilder) Query() (string, []interface{})
Query builds the sql query and returns it along with its arguments
func (*DeleteBuilder) Where ¶
func (db *DeleteBuilder) Where(cond BuildFunc) *DeleteBuilder
Where adds a where condition to the delete query
type DialectBuilder ¶ added in v0.2.0
type DialectBuilder struct {
// contains filtered or unexported fields
}
DialectBuilder is for building queries for a custom sql dialect
func Dialect ¶ added in v0.2.0
func Dialect(dialect string) DialectBuilder
Dialect creates a custom builder for the given sql dialect
func (DialectBuilder) DeleteFrom ¶ added in v0.2.0
func (db DialectBuilder) DeleteFrom(table string) *DeleteBuilder
DeleteFrom creates a DeleteBuilder for the configured dialect
func (DialectBuilder) Insert ¶ added in v0.2.0
func (db DialectBuilder) Insert(table string) *InsertBuilder
Insert creates an InsertBuilder for the configured dialect
func (DialectBuilder) Select ¶ added in v0.2.0
func (db DialectBuilder) Select(columns ...string) *SelectBuilder
Select creates a SelectBuilder for the configured dialect
func (DialectBuilder) Update ¶ added in v0.2.0
func (db DialectBuilder) Update(table string) *UpdateBuilder
Update creates an UpdateBuilder for the configured dialect
type InsertBuilder ¶
type InsertBuilder struct { *Builder // contains filtered or unexported fields }
InsertBuilder is a builder for insert queries
func (*InsertBuilder) Columns ¶
func (b *InsertBuilder) Columns(columns ...string) *InsertBuilder
Columns adds a list of columns to the insert query
func (*InsertBuilder) Query ¶
func (b *InsertBuilder) Query() (string, []interface{})
Query builds the sql query and returns it along with its arguments
func (*InsertBuilder) Returning ¶ added in v0.2.0
func (b *InsertBuilder) Returning(columns ...string) *InsertBuilder
func (*InsertBuilder) Values ¶
func (b *InsertBuilder) Values(values ...interface{}) *InsertBuilder
Values adds column values to the insert query
type SelectBuilder ¶
type SelectBuilder struct { *Builder // contains filtered or unexported fields }
SelectBuilder is a builder for select queries
func Select ¶
func Select(columns ...string) *SelectBuilder
Select creates a builder for select queries
func (*SelectBuilder) From ¶
func (sb *SelectBuilder) From(table string) *SelectBuilder
From sets the table that we are selecting from
func (*SelectBuilder) GroupBy ¶
func (sb *SelectBuilder) GroupBy(columns ...string) *SelectBuilder
GroupBy adds a `GROUP BY` clause to the query
func (*SelectBuilder) Having ¶
func (sb *SelectBuilder) Having(cond BuildFunc) *SelectBuilder
Having adds a `HAVING` condition to the query
func (*SelectBuilder) Join ¶
func (sb *SelectBuilder) Join(table string, on BuildFunc) *SelectBuilder
Join adds an `INNER JOIN` clause to the query
func (*SelectBuilder) LeftJoin ¶
func (sb *SelectBuilder) LeftJoin(table string, on BuildFunc) *SelectBuilder
Join adds a `LEFT JOIN` clause to the query
func (*SelectBuilder) Limit ¶
func (sb *SelectBuilder) Limit(limit int) *SelectBuilder
Limit adds a `LIMIT` clause to the query
func (*SelectBuilder) Offset ¶
func (sb *SelectBuilder) Offset(offset int) *SelectBuilder
Offset adds an `OFFSET` clause to the query
func (*SelectBuilder) OrderBy ¶
func (sb *SelectBuilder) OrderBy(columns ...string) *SelectBuilder
OrderBy adds an `ORDER BY` clause to the query
func (*SelectBuilder) Query ¶
func (sb *SelectBuilder) Query() (string, []interface{})
Query builds the sql query and returns it along with its arguments
func (*SelectBuilder) RightJoin ¶
func (sb *SelectBuilder) RightJoin(table string, on BuildFunc) *SelectBuilder
Join adds a `RIGHT JOIN` clause to the query
func (*SelectBuilder) Where ¶
func (sb *SelectBuilder) Where(cond BuildFunc) *SelectBuilder
Where adds a where condition to the select query
type UpdateBuilder ¶
type UpdateBuilder struct { *Builder // contains filtered or unexported fields }
UpdateBuilder is a builder for update queries
func (*UpdateBuilder) Query ¶
func (b *UpdateBuilder) Query() (string, []interface{})
Query builds the sql query and returns it along with its arguments
func (*UpdateBuilder) Set ¶
func (b *UpdateBuilder) Set(column string, value interface{}) *UpdateBuilder
Set sets the column to the provided value
func (*UpdateBuilder) Where ¶
func (b *UpdateBuilder) Where(cond BuildFunc) *UpdateBuilder
Where adds a where condition to the update query