exql

package
v3.8.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultOrder = Order(iota)
	Ascendent
	Descendent
)

Possible values for Order

View Source
const (
	NoOp = Type(iota)

	Truncate
	DropTable
	DropDatabase
	Count
	Insert
	Select
	Update
	Delete

	SQL
)

Values for Type.

Variables

This section is empty.

Functions

This section is empty.

Types

type And

type And Where

And represents an SQL AND operator.

func JoinWithAnd

func JoinWithAnd(conditions ...Fragment) *And

JoinWithAnd creates and returns a new And.

func (*And) Compile

func (a *And) Compile(layout *Template) (compiled string, err error)

Compile transforms the And into an equivalent SQL representation.

func (*And) Hash

func (a *And) Hash() string

Hash returns a unique identifier.

type Column

type Column struct {
	Name  interface{}
	Alias string
	// contains filtered or unexported fields
}

Column represents a SQL column.

func ColumnWithName

func ColumnWithName(name string) *Column

ColumnWithName creates and returns a Column with the given name.

func (*Column) Compile

func (c *Column) Compile(layout *Template) (compiled string, err error)

Compile transforms the ColumnValue into an equivalent SQL representation.

func (*Column) Hash

func (c *Column) Hash() string

Hash returns a unique identifier for the struct.

type ColumnValue

type ColumnValue struct {
	Column   Fragment
	Operator string
	Value    Fragment
	// contains filtered or unexported fields
}

ColumnValue represents a bundle between a column and a corresponding value.

func (*ColumnValue) Compile

func (c *ColumnValue) Compile(layout *Template) (compiled string, err error)

Compile transforms the ColumnValue into an equivalent SQL representation.

func (*ColumnValue) Hash

func (c *ColumnValue) Hash() string

Hash returns a unique identifier for the struct.

type ColumnValues

type ColumnValues struct {
	ColumnValues []Fragment
	// contains filtered or unexported fields
}

ColumnValues represents an array of ColumnValue

func JoinColumnValues

func JoinColumnValues(values ...Fragment) *ColumnValues

JoinColumnValues returns an array of ColumnValue

func (*ColumnValues) Compile

func (c *ColumnValues) Compile(layout *Template) (compiled string, err error)

Compile transforms the ColumnValues into its SQL representation.

func (*ColumnValues) Hash

func (c *ColumnValues) Hash() string

Hash returns a unique identifier for the struct.

func (*ColumnValues) Insert

func (c *ColumnValues) Insert(values ...Fragment) *ColumnValues

Insert adds a column to the columns array.

type Columns

type Columns struct {
	Columns []Fragment
	// contains filtered or unexported fields
}

Columns represents an array of Column.

func JoinColumns

func JoinColumns(columns ...Fragment) *Columns

JoinColumns creates and returns an array of Column.

func (*Columns) Append

func (c *Columns) Append(a *Columns) *Columns

Append

func (*Columns) Compile

func (c *Columns) Compile(layout *Template) (compiled string, err error)

Compile transforms the Columns into an equivalent SQL representation.

func (*Columns) Hash

func (c *Columns) Hash() string

Hash returns a unique identifier.

func (*Columns) IsEmpty

func (c *Columns) IsEmpty() bool

IsEmpty

type Database

type Database struct {
	Name string
	// contains filtered or unexported fields
}

Database represents a SQL database.

func DatabaseWithName

func DatabaseWithName(name string) *Database

DatabaseWithName returns a Database with the given name.

func (*Database) Compile

func (d *Database) Compile(layout *Template) (compiled string, err error)

Compile transforms the Database into an equivalent SQL representation.

func (*Database) Hash

func (d *Database) Hash() string

Hash returns a unique identifier for the struct.

type Fragment

type Fragment interface {
	cache.Hashable
	// contains filtered or unexported methods
}

Fragment is any interface that can be both cached and compiled.

type GroupBy

type GroupBy struct {
	Columns Fragment
	// contains filtered or unexported fields
}

GroupBy represents a SQL's "group by" statement.

func GroupByColumns

func GroupByColumns(columns ...Fragment) *GroupBy

GroupByColumns creates and returns a GroupBy with the given column.

func (*GroupBy) Compile

func (g *GroupBy) Compile(layout *Template) (compiled string, err error)

Compile transforms the GroupBy into an equivalent SQL representation.

func (*GroupBy) Hash

func (g *GroupBy) Hash() string

Hash returns a unique identifier.

func (*GroupBy) IsEmpty

func (g *GroupBy) IsEmpty() bool

type Join

type Join struct {
	Type  string
	Table Fragment
	On    Fragment
	Using Fragment
	// contains filtered or unexported fields
}

Join represents a generic JOIN statement.

func (*Join) Compile

func (j *Join) Compile(layout *Template) (compiled string, err error)

Compile transforms the Join into its equivalent SQL representation.

func (*Join) Hash

func (j *Join) Hash() string

Hash returns a unique identifier for the struct.

type Joins

type Joins struct {
	Conditions []Fragment
	// contains filtered or unexported fields
}

Joins represents the union of different join conditions.

func JoinConditions

func JoinConditions(joins ...*Join) *Joins

JoinConditions creates a Joins object.

func (*Joins) Compile

func (j *Joins) Compile(layout *Template) (compiled string, err error)

Compile transforms the Where into an equivalent SQL representation.

func (*Joins) Hash

func (j *Joins) Hash() string

Hash returns a unique identifier for the struct.

type Limit

type Limit int

Limit represents the SQL limit in a query.

type Offset

type Offset int

Offset represents the SQL offset in a query.

type On

type On Where

On represents JOIN conditions.

func OnConditions

func OnConditions(conditions ...Fragment) *On

OnConditions creates and retuens a new On.

func (*On) Compile

func (o *On) Compile(layout *Template) (compiled string, err error)

Compile transforms the On into an equivalent SQL representation.

func (*On) Hash

func (o *On) Hash() string

Hash returns a unique identifier.

type Or

type Or Where

Or represents an SQL OR operator.

func JoinWithOr

func JoinWithOr(conditions ...Fragment) *Or

JoinWithOr creates and returns a new Or.

func (*Or) Compile

func (o *Or) Compile(layout *Template) (compiled string, err error)

Compile transforms the Or into an equivalent SQL representation.

func (*Or) Hash

func (o *Or) Hash() string

Hash returns a unique identifier.

type Order

type Order uint8

Order represents the order in which SQL results are sorted.

func (Order) Compile

func (s Order) Compile(layout *Template) (string, error)

Compile transforms the SortColumn into an equivalent SQL representation.

func (*Order) Hash

func (s *Order) Hash() string

Hash returns a unique identifier.

type OrderBy

type OrderBy struct {
	SortColumns Fragment
	// contains filtered or unexported fields
}

OrderBy represents an ORDER BY clause.

func JoinWithOrderBy

func JoinWithOrderBy(sc *SortColumns) *OrderBy

JoinWithOrderBy creates an returns an OrderBy using the given SortColumns.

func (*OrderBy) Compile

func (s *OrderBy) Compile(layout *Template) (compiled string, err error)

Compile transforms the SortColumn into an equivalent SQL representation.

func (*OrderBy) Hash

func (s *OrderBy) Hash() string

Hash returns a unique identifier for the struct.

type Raw

type Raw struct {
	Value string // Value should not be modified after assigned.
	// contains filtered or unexported fields
}

Raw represents a value that is meant to be used in a query without escaping.

func RawValue

func RawValue(v string) *Raw

RawValue creates and returns a new raw value.

func (*Raw) Compile

func (r *Raw) Compile(*Template) (string, error)

Compile returns the raw value.

func (*Raw) Hash

func (r *Raw) Hash() string

Hash returns a unique identifier for the struct.

func (*Raw) String

func (r *Raw) String() string

String returns the raw value.

type Returning

type Returning struct {
	*Columns
	// contains filtered or unexported fields
}

Returning represents a RETURNING clause.

func ReturningColumns

func ReturningColumns(columns ...Fragment) *Returning

ReturningColumns creates and returns an array of Column.

func (*Returning) Compile

func (r *Returning) Compile(layout *Template) (compiled string, err error)

Compile transforms the clause into its equivalent SQL representation.

func (*Returning) Hash

func (r *Returning) Hash() string

Hash returns a unique identifier for the struct.

type SortColumn

type SortColumn struct {
	Column Fragment
	Order
	// contains filtered or unexported fields
}

SortColumn represents the column-order relation in an ORDER BY clause.

func (*SortColumn) Compile

func (s *SortColumn) Compile(layout *Template) (compiled string, err error)

Compile transforms the SortColumn into an equivalent SQL representation.

func (*SortColumn) Hash

func (s *SortColumn) Hash() string

Hash returns a unique identifier for the struct.

type SortColumns

type SortColumns struct {
	Columns []Fragment
	// contains filtered or unexported fields
}

SortColumns represents the columns in an ORDER BY clause.

func JoinSortColumns

func JoinSortColumns(values ...Fragment) *SortColumns

JoinSortColumns creates and returns an array of column-order relations.

func (*SortColumns) Compile

func (s *SortColumns) Compile(layout *Template) (compiled string, err error)

Compile transforms the SortColumns into an equivalent SQL representation.

func (*SortColumns) Hash

func (s *SortColumns) Hash() string

Hash returns a unique identifier for the struct.

type Statement

type Statement struct {
	Type
	Table        Fragment
	Database     Fragment
	Columns      Fragment
	Values       Fragment
	Distinct     bool
	ColumnValues Fragment
	OrderBy      Fragment
	GroupBy      Fragment
	Joins        Fragment
	Where        Fragment
	Returning    Fragment

	Limit
	Offset

	SQL string
	// contains filtered or unexported fields
}

represents different kinds of SQL statements.

func RawSQL

func RawSQL(s string) *Statement

RawSQL represents a raw SQL statement.

func (*Statement) Amend

func (s *Statement) Amend(in string) string

func (*Statement) Compile

func (s *Statement) Compile(layout *Template) (compiled string, err error)

Compile transforms the Statement into an equivalent SQL query.

func (*Statement) Hash

func (s *Statement) Hash() string

Hash returns a unique identifier for the struct.

func (*Statement) SetAmendment

func (s *Statement) SetAmendment(amendFn func(string) string)

type Table

type Table struct {
	Name interface{}
	// contains filtered or unexported fields
}

Table struct represents a SQL table.

func TableWithName

func TableWithName(name string) *Table

TableWithName creates an returns a Table with the given name.

func (*Table) Compile

func (t *Table) Compile(layout *Template) (compiled string, err error)

Compile transforms a table struct into a SQL chunk.

func (*Table) Hash

func (t *Table) Hash() string

Hash returns a string hash of the table value.

type Template

type Template struct {
	AndKeyword          string
	AscKeyword          string
	AssignmentOperator  string
	ClauseGroup         string
	ClauseOperator      string
	ColumnAliasLayout   string
	ColumnSeparator     string
	ColumnValue         string
	CountLayout         string
	DeleteLayout        string
	DescKeyword         string
	DropDatabaseLayout  string
	DropTableLayout     string
	GroupByLayout       string
	IdentifierQuote     string
	IdentifierSeparator string
	InsertLayout        string
	JoinLayout          string
	OnLayout            string
	OrKeyword           string
	OrderByLayout       string
	SelectLayout        string
	SortByColumnLayout  string
	TableAliasLayout    string
	TruncateLayout      string
	UpdateLayout        string
	UsingLayout         string
	ValueQuote          string
	ValueSeparator      string
	WhereLayout         string

	ComparisonOperator map[db.ComparisonOperator]string

	*cache.Cache
	// contains filtered or unexported fields
}

Template is an SQL template.

func (*Template) MustCompile

func (layout *Template) MustCompile(templateText string, data interface{}) string

type Type

type Type uint

Type is the type of SQL query the statement represents.

type Using

type Using Columns

Using represents a USING function.

func UsingColumns

func UsingColumns(columns ...Fragment) *Using

UsingColumns builds a Using from the given columns.

func (*Using) Compile

func (u *Using) Compile(layout *Template) (compiled string, err error)

Compile transforms the Using into an equivalent SQL representation.

func (*Using) Hash

func (u *Using) Hash() string

Hash returns a unique identifier.

type Value

type Value struct {
	V interface{}
	// contains filtered or unexported fields
}

Value represents an escaped SQL value.

func NewValue

func NewValue(v interface{}) *Value

NewValue creates and returns a Value.

func (*Value) Compile

func (v *Value) Compile(layout *Template) (compiled string, err error)

Compile transforms the Value into an equivalent SQL representation.

func (*Value) Hash

func (v *Value) Hash() string

Hash returns a unique identifier for the struct.

func (*Value) IsEmpty

func (v *Value) IsEmpty() bool

type ValueGroups

type ValueGroups struct {
	Values []*Values
	// contains filtered or unexported fields
}

ValueGroups represents an array of value groups.

func JoinValueGroups

func JoinValueGroups(values ...*Values) *ValueGroups

JoinValueGroups creates a new *ValueGroups object.

func (*ValueGroups) Compile

func (vg *ValueGroups) Compile(layout *Template) (compiled string, err error)

Compile transforms the ValueGroups into an equivalent SQL representation.

func (*ValueGroups) Hash

func (vg *ValueGroups) Hash() string

Hash returns a unique identifier for the struct.

func (*ValueGroups) IsEmpty

func (vg *ValueGroups) IsEmpty() bool

type Values

type Values struct {
	Values []Fragment
	// contains filtered or unexported fields
}

Values represents an array of Value.

func NewValueGroup

func NewValueGroup(v ...Fragment) *Values

NewValueGroup creates and returns an array of values.

func (*Values) Compile

func (vs *Values) Compile(layout *Template) (compiled string, err error)

Compile transforms the Values into an equivalent SQL representation.

func (*Values) Hash

func (vs *Values) Hash() string

Hash returns a unique identifier for the struct.

func (*Values) IsEmpty

func (vs *Values) IsEmpty() bool

type Where

type Where struct {
	Conditions []Fragment
	// contains filtered or unexported fields
}

Where represents an SQL WHERE clause.

func WhereConditions

func WhereConditions(conditions ...Fragment) *Where

WhereConditions creates and retuens a new Where.

func (*Where) Append

func (w *Where) Append(a *Where) *Where

Appends adds the conditions to the ones that already exist.

func (*Where) Compile

func (w *Where) Compile(layout *Template) (compiled string, err error)

Compile transforms the Where into an equivalent SQL representation.

func (*Where) Hash

func (w *Where) Hash() string

Hash returns a unique identifier for the struct.

Jump to

Keyboard shortcuts

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