Documentation ¶
Overview ¶
Package builder receives user input and generates an AST using "stmt" package.
There is four builder to manipulate an AST: Select, Insert, Update and Delete.
When the AST is ready, you can use String(), NamedQuery() or Query() to generate the underlying query. However, be vigilant with String(): it's mainly used for debugging because it's completely vulnerable to SQL injection...
Index ¶
- func IsDeleteBuilder(builder Builder) bool
- func IsInsertBuilder(builder Builder) bool
- func IsSelectBuilder(builder Builder) bool
- func IsUpdateBuilder(builder Builder) bool
- func MergeSet(set stmt.Set, args []interface{}) stmt.Set
- func ToColumn(arg interface{}) stmt.Column
- func ToColumns(values []interface{}) []stmt.Column
- func ToFrom(arg interface{}) stmt.From
- func ToInt64(value interface{}) (int64, bool)
- func ToInto(arg interface{}) stmt.Into
- func ToPrefix(arg interface{}) stmt.Prefix
- func ToSelectExpressions(values []interface{}) []stmt.SelectExpression
- func ToSet(args []interface{}) stmt.Set
- func ToSuffix(arg interface{}) stmt.Suffix
- func ToTable(arg interface{}) stmt.Table
- func ToTables(values []interface{}) []stmt.Table
- type Builder
- type Delete
- func (b Delete) And(condition stmt.Expression) Delete
- func (b Delete) From(arg interface{}) Delete
- func (b Delete) NamedQuery() (string, map[string]interface{})
- func (b Delete) Only() Delete
- func (b Delete) Or(condition stmt.Expression) Delete
- func (b Delete) Query() (string, []interface{})
- func (b Delete) Returning(values ...interface{}) Delete
- func (b Delete) Statement() stmt.Statement
- func (b Delete) String() string
- func (b Delete) Using(args ...interface{}) Delete
- func (b Delete) Where(condition stmt.Expression) Delete
- type Insert
- func (b Insert) Columns(columns ...interface{}) Insert
- func (b Insert) Into(into interface{}) Insert
- func (b Insert) NamedQuery() (string, map[string]interface{})
- func (b Insert) OnConflict(args ...interface{}) Insert
- func (b Insert) Query() (string, []interface{})
- func (b Insert) Returning(values ...interface{}) Insert
- func (b Insert) Set(args ...interface{}) Insert
- func (b Insert) Statement() stmt.Statement
- func (b Insert) String() string
- func (b Insert) Values(values ...interface{}) Insert
- type Select
- func (b Select) And(condition stmt.Expression) Select
- func (b Select) Columns(args ...interface{}) Select
- func (b Select) Distinct() Select
- func (b Select) From(arg interface{}) Select
- func (b Select) GroupBy(args ...interface{}) Select
- func (b Select) Having(condition stmt.Expression) Select
- func (b Select) Join(args ...interface{}) Select
- func (b Select) Limit(value interface{}) Select
- func (b Select) NamedQuery() (string, map[string]interface{})
- func (b Select) Offset(value interface{}) Select
- func (b Select) Or(condition stmt.Expression) Select
- func (b Select) OrderBy(orders ...stmt.Order) Select
- func (b Select) Prefix(prefix interface{}) Select
- func (b Select) Query() (string, []interface{})
- func (b Select) Statement() stmt.Statement
- func (b Select) String() string
- func (b Select) Suffix(suffix interface{}) Select
- func (b Select) Where(condition stmt.Expression) Select
- func (b Select) With(args ...stmt.WithQuery) Select
- type Update
- func (b Update) And(condition stmt.Expression) Update
- func (b Update) From(arg interface{}) Update
- func (b Update) NamedQuery() (string, map[string]interface{})
- func (b Update) Only() Update
- func (b Update) Or(condition stmt.Expression) Update
- func (b Update) Query() (string, []interface{})
- func (b Update) Returning(values ...interface{}) Update
- func (b Update) Set(args ...interface{}) Update
- func (b Update) Statement() stmt.Statement
- func (b Update) String() string
- func (b Update) Using(args ...interface{}) Update
- func (b Update) Where(condition stmt.Expression) Update
- func (b Update) With(args ...stmt.WithQuery) Update
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsDeleteBuilder ¶
IsDeleteBuilder returns true if given builder is of type "Delete"
func IsInsertBuilder ¶
IsInsertBuilder returns true if given builder is of type "Insert"
func IsSelectBuilder ¶
IsSelectBuilder returns true if given builder is of type "Select"
func IsUpdateBuilder ¶
IsUpdateBuilder returns true if given builder is of type "Update"
func ToSelectExpressions ¶
func ToSelectExpressions(values []interface{}) []stmt.SelectExpression
ToSelectExpressions takes a list of empty interfaces and returns a slice of SelectExpression instance.
Types ¶
type Builder ¶
type Builder interface { // String returns the underlying query as a raw statement. // This function should be used for debugging since it doesn't escape anything and is completely // vulnerable to SQL injection. // You should use either NamedQuery() or Query()... String() string // NamedQuery returns the underlying query as a named statement. NamedQuery() (string, map[string]interface{}) // Query returns the underlying query as a regular statement. Query() (string, []interface{}) // Statement returns underlying statement. Statement() stmt.Statement }
Builder defines a generic methods available for Select, Insert, Update and Delete builders.
type Delete ¶
type Delete struct {
// contains filtered or unexported fields
}
Delete is a builder used for "SELECT" query.
func (Delete) And ¶
func (b Delete) And(condition stmt.Expression) Delete
And adds AND WHERE conditions.
func (Delete) NamedQuery ¶
NamedQuery returns the underlying query as a named statement.
func (Delete) Or ¶
func (b Delete) Or(condition stmt.Expression) Delete
Or adds OR WHERE conditions.
func (Delete) String ¶
String returns the underlying query as a raw statement. This function should be used for debugging since it doesn't escape anything and is completely vulnerable to SQL injection. You should use either NamedQuery() or Query()...
type Insert ¶
type Insert struct {
// contains filtered or unexported fields
}
Insert is a builder used for "INSERT" query.
func (Insert) NamedQuery ¶
NamedQuery returns the underlying query as a named statement.
func (Insert) OnConflict ¶
OnConflict builds the ON CONFLICT clause.
type Select ¶
type Select struct {
// contains filtered or unexported fields
}
Select is a builder used for "SELECT" query.
func (Select) And ¶
func (b Select) And(condition stmt.Expression) Select
And adds AND WHERE conditions.
func (Select) Having ¶
func (b Select) Having(condition stmt.Expression) Select
Having adds HAVING clauses.
func (Select) NamedQuery ¶
NamedQuery returns the underlying query as a named statement.
func (Select) Or ¶
func (b Select) Or(condition stmt.Expression) Select
Or adds OR WHERE conditions.
func (Select) String ¶
String returns the underlying query as a raw statement. This function should be used for debugging since it doesn't escape anything and is completely vulnerable to SQL injection. You should use either NamedQuery() or Query()...
type Update ¶
type Update struct {
// contains filtered or unexported fields
}
Update is a builder used for "UPDATE" query.
func (Update) And ¶
func (b Update) And(condition stmt.Expression) Update
And adds AND WHERE conditions.
func (Update) NamedQuery ¶
NamedQuery returns the underlying query as a named statement.
func (Update) Or ¶
func (b Update) Or(condition stmt.Expression) Update
Or adds OR WHERE conditions.
func (Update) String ¶
String returns the underlying query as a raw statement. This function should be used for debugging since it doesn't escape anything and is completely vulnerable to SQL injection. You should use either NamedQuery() or Query()...
func (Update) Using ¶
Using assigns the result of the given expression to the columns defined in Set.