exql

package
v4.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FragmentType_None uint64 = iota + 713910251627

	FragmentType_And
	FragmentType_Column
	FragmentType_ColumnValue
	FragmentType_ColumnValues
	FragmentType_Columns
	FragmentType_Database
	FragmentType_GroupBy
	FragmentType_Join
	FragmentType_Joins
	FragmentType_Nil
	FragmentType_Or
	FragmentType_Limit
	FragmentType_Offset
	FragmentType_OrderBy
	FragmentType_Order
	FragmentType_Raw
	FragmentType_Returning
	FragmentType_SortBy
	FragmentType_SortColumn
	FragmentType_SortColumns
	FragmentType_Statement
	FragmentType_StatementType
	FragmentType_Table
	FragmentType_Value
	FragmentType_On
	FragmentType_Using
	FragmentType_ValueGroups
	FragmentType_Values
	FragmentType_Where
)

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() uint64

Hash returns a unique identifier.

type Column

type Column struct {
	Name interface{}
}

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() uint64

Hash returns a unique identifier for the struct.

type ColumnValue

type ColumnValue struct {
	Column   Fragment
	Operator string
	Value    Fragment
}

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() uint64

Hash returns a unique identifier for the struct.

type ColumnValues

type ColumnValues struct {
	ColumnValues []Fragment
}

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() uint64

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
}

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() uint64

Hash returns a unique identifier.

func (*Columns) IsEmpty

func (c *Columns) IsEmpty() bool

IsEmpty

type Database

type Database struct {
	Name string
}

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() uint64

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
}

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() uint64

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
}

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() uint64

Hash returns a unique identifier for the struct.

type Joins

type Joins struct {
	Conditions []Fragment
}

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() uint64

Hash returns a unique identifier for the struct.

type Limit

type Limit int64

Limit represents the SQL limit in a query.

func (Limit) Hash added in v4.6.0

func (t Limit) Hash() uint64

type Offset

type Offset int64

Offset represents the SQL offset in a query.

func (Offset) Hash added in v4.6.0

func (t Offset) Hash() uint64

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() uint64

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() uint64

Hash returns a unique identifier.

type Order

type Order uint8

Order represents the order in which SQL results are sorted.

const (
	Order_Default Order = iota

	Order_Ascendent
	Order_Descendent
)

Possible values for Order

func (Order) Compile

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

Compile transforms the SortColumn into an equivalent SQL representation.

func (Order) Hash

func (o Order) Hash() uint64

type OrderBy

type OrderBy struct {
	SortColumns Fragment
}

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() uint64

Hash returns a unique identifier for the struct.

type Raw

type Raw struct {
	Value string
}

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

func NewRawValue added in v4.6.0

func NewRawValue(v interface{}) (*Raw, error)

func (*Raw) Compile

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

Compile returns the raw value.

func (*Raw) Hash

func (r *Raw) Hash() uint64

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
}

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() uint64

Hash returns a unique identifier for the struct.

type SortColumn

type SortColumn struct {
	Column Fragment
	Order
}

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() uint64

Hash returns a unique identifier for the struct.

type SortColumns

type SortColumns struct {
	Columns []Fragment
}

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() uint64

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() uint64

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{}
}

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() uint64

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[adapter.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 uint8

Type is the type of SQL query the statement represents.

const (
	NoOp Type = iota

	Truncate
	DropTable
	DropDatabase
	Count
	Insert
	Select
	Update
	Delete

	SQL
)

Values for Type.

func (Type) Hash added in v4.6.0

func (t Type) Hash() uint64

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() uint64

type Value

type Value struct {
	V interface{}
}

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() uint64

Hash returns a unique identifier for the struct.

type ValueGroups

type ValueGroups struct {
	Values []*Values
}

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() uint64

Hash returns a unique identifier for the struct.

func (*ValueGroups) IsEmpty

func (vg *ValueGroups) IsEmpty() bool

type Values

type Values struct {
	Values []Fragment
}

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() uint64

Hash returns a unique identifier for the struct.

func (*Values) IsEmpty

func (vs *Values) IsEmpty() bool

type Where

type Where struct {
	Conditions []Fragment
}

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() uint64

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