builder

package
v2.2.3+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 1, 2019 License: MIT Imports: 7 Imported by: 1

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsDeleteBuilder

func IsDeleteBuilder(builder Builder) bool

IsDeleteBuilder returns true if given builder is of type "Delete"

func IsInsertBuilder

func IsInsertBuilder(builder Builder) bool

IsInsertBuilder returns true if given builder is of type "Insert"

func IsSelectBuilder

func IsSelectBuilder(builder Builder) bool

IsSelectBuilder returns true if given builder is of type "Select"

func IsUpdateBuilder

func IsUpdateBuilder(builder Builder) bool

IsUpdateBuilder returns true if given builder is of type "Update"

func MergeSet

func MergeSet(set stmt.Set, args []interface{}) stmt.Set

MergeSet merges new pairs into existing ones (last write wins).

func ToColumn

func ToColumn(arg interface{}) stmt.Column

ToColumn takes an empty interfaces and returns a Column instance.

func ToColumns

func ToColumns(values []interface{}) []stmt.Column

ToColumns takes a list of empty interfaces and returns a slice of Column instance.

func ToFrom

func ToFrom(arg interface{}) stmt.From

ToFrom takes an empty interfaces and returns a From instance.

func ToInt64

func ToInt64(value interface{}) (int64, bool)

ToInt64 takes an empty interfaces and returns a int64.

func ToInto

func ToInto(arg interface{}) stmt.Into

ToInto takes an empty interfaces and returns a Into instance.

func ToPrefix

func ToPrefix(arg interface{}) stmt.Prefix

ToPrefix takes an empty interfaces and returns a Prefix instance.

func ToSelectExpressions

func ToSelectExpressions(values []interface{}) []stmt.SelectExpression

ToSelectExpressions takes a list of empty interfaces and returns a slice of SelectExpression instance.

func ToSet

func ToSet(args []interface{}) stmt.Set

ToSet takes either a types.Map or slice of types.Pair and returns a stmt.Set instance.

func ToSuffix

func ToSuffix(arg interface{}) stmt.Suffix

ToSuffix takes an empty interfaces and returns a Suffix instance.

func ToTable

func ToTable(arg interface{}) stmt.Table

ToTable takes an empty interfaces and returns a Table instance.

func ToTables

func ToTables(values []interface{}) []stmt.Table

ToTables takes a list of empty interfaces and returns a slice of Table 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 NewDelete

func NewDelete() Delete

NewDelete creates a new Delete.

func (Delete) And

func (b Delete) And(condition stmt.Expression) Delete

And adds AND WHERE conditions.

func (Delete) From

func (b Delete) From(arg interface{}) Delete

From sets the FROM clause of the query.

func (Delete) NamedQuery

func (b Delete) NamedQuery() (string, map[string]interface{})

NamedQuery returns the underlying query as a named statement.

func (Delete) Only

func (b Delete) Only() Delete

Only adds a ONLY clause to the query.

func (Delete) Or

func (b Delete) Or(condition stmt.Expression) Delete

Or adds OR WHERE conditions.

func (Delete) Query

func (b Delete) Query() (string, []interface{})

Query returns the underlying query as a regular statement.

func (Delete) Returning

func (b Delete) Returning(values ...interface{}) Delete

Returning adds a RETURNING clause.

func (Delete) Statement

func (b Delete) Statement() stmt.Statement

Statement returns underlying statement.

func (Delete) String

func (b Delete) String() 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 (Delete) Using

func (b Delete) Using(args ...interface{}) Delete

Using adds a ONLY clause to the query.

func (Delete) Where

func (b Delete) Where(condition stmt.Expression) Delete

Where adds WHERE clauses.

type Insert

type Insert struct {
	// contains filtered or unexported fields
}

Insert is a builder used for "INSERT" query.

func NewInsert

func NewInsert() Insert

NewInsert creates a new Insert.

func (Insert) Columns

func (b Insert) Columns(columns ...interface{}) Insert

Columns sets the query columns.

func (Insert) Into

func (b Insert) Into(into interface{}) Insert

Into sets the INTO clause of the query.

func (Insert) NamedQuery

func (b Insert) NamedQuery() (string, map[string]interface{})

NamedQuery returns the underlying query as a named statement.

func (Insert) OnConflict

func (b Insert) OnConflict(args ...interface{}) Insert

OnConflict builds the ON CONFLICT clause.

func (Insert) Query

func (b Insert) Query() (string, []interface{})

Query returns the underlying query as a regular statement.

func (Insert) Returning

func (b Insert) Returning(values ...interface{}) Insert

Returning builds the RETURNING clause.

func (Insert) Set

func (b Insert) Set(args ...interface{}) Insert

Set is a wrapper that defines columns and values clauses using a pair.

func (Insert) Statement

func (b Insert) Statement() stmt.Statement

Statement returns underlying statement.

func (Insert) String

func (b Insert) String() 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 (Insert) Values

func (b Insert) Values(values ...interface{}) Insert

Values sets the query values.

type Select

type Select struct {
	// contains filtered or unexported fields
}

Select is a builder used for "SELECT" query.

func NewSelect

func NewSelect() Select

NewSelect creates a new Select.

func (Select) And

func (b Select) And(condition stmt.Expression) Select

And adds AND WHERE conditions.

func (Select) Columns

func (b Select) Columns(args ...interface{}) Select

Columns adds result columns to the query.

func (Select) Distinct

func (b Select) Distinct() Select

Distinct adds a DISTINCT clause to the query.

func (Select) From

func (b Select) From(arg interface{}) Select

From sets the FROM clause of the query.

func (Select) GroupBy

func (b Select) GroupBy(args ...interface{}) Select

GroupBy adds GROUP BY clauses.

func (Select) Having

func (b Select) Having(condition stmt.Expression) Select

Having adds HAVING clauses.

func (Select) Join

func (b Select) Join(args ...interface{}) Select

Join adds a JOIN clause to the query.

func (Select) Limit

func (b Select) Limit(value interface{}) Select

Limit adds LIMIT clause.

func (Select) NamedQuery

func (b Select) NamedQuery() (string, map[string]interface{})

NamedQuery returns the underlying query as a named statement.

func (Select) Offset

func (b Select) Offset(value interface{}) Select

Offset adds OFFSET clause.

func (Select) Or

func (b Select) Or(condition stmt.Expression) Select

Or adds OR WHERE conditions.

func (Select) OrderBy

func (b Select) OrderBy(orders ...stmt.Order) Select

OrderBy adds ORDER BY clauses.

func (Select) Prefix

func (b Select) Prefix(prefix interface{}) Select

Prefix adds given clauses as prefixes.

func (Select) Query

func (b Select) Query() (string, []interface{})

Query returns the underlying query as a regular statement.

func (Select) Statement

func (b Select) Statement() stmt.Statement

Statement returns underlying statement.

func (Select) String

func (b Select) String() 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 (Select) Suffix

func (b Select) Suffix(suffix interface{}) Select

Suffix adds given clauses as suffixes.

func (Select) Where

func (b Select) Where(condition stmt.Expression) Select

Where adds WHERE clauses.

func (Select) With

func (b Select) With(args ...stmt.WithQuery) Select

With adds WITH clauses.

type Update

type Update struct {
	// contains filtered or unexported fields
}

Update is a builder used for "UPDATE" query.

func NewUpdate

func NewUpdate(arg interface{}) Update

NewUpdate creates a new Update.

func (Update) And

func (b Update) And(condition stmt.Expression) Update

And adds AND WHERE conditions.

func (Update) From

func (b Update) From(arg interface{}) Update

From sets the FROM clause of the query.

func (Update) NamedQuery

func (b Update) NamedQuery() (string, map[string]interface{})

NamedQuery returns the underlying query as a named statement.

func (Update) Only

func (b Update) Only() Update

Only sets the ONLY clause.

func (Update) Or

func (b Update) Or(condition stmt.Expression) Update

Or adds OR WHERE conditions.

func (Update) Query

func (b Update) Query() (string, []interface{})

Query returns the underlying query as a regular statement.

func (Update) Returning

func (b Update) Returning(values ...interface{}) Update

Returning adds a RETURNING clause.

func (Update) Set

func (b Update) Set(args ...interface{}) Update

Set adds a SET clause.

func (Update) Statement

func (b Update) Statement() stmt.Statement

Statement returns underlying statement.

func (Update) String

func (b Update) String() 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

func (b Update) Using(args ...interface{}) Update

Using assigns the result of the given expression to the columns defined in Set.

func (Update) Where

func (b Update) Where(condition stmt.Expression) Update

Where adds WHERE clauses.

func (Update) With

func (b Update) With(args ...stmt.WithQuery) Update

With adds WITH clauses.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL