builder

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2024 License: MIT Imports: 4 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ASC

func ASC(v bool) string

ASC returns ASC if v is true else DESC.

func DESC

func DESC(v bool) string

DESC returns DESC if v is true else ASC.

Types

type Binds

type Binds map[string]string

Binds is used to bind column to another one. (Raw version, no secure)

func (Binds) String

func (b Binds) String() string

String

type Columns

type Columns interface {
	// Add columns to the list.
	Add(...string) Columns

	// String convert Columns to string.
	String() string

	// Len says the size of the string.
	Len() int

	// Reset resets the list of columns.
	Reset()
}

Columns is list of columns.

func NewColumns

func NewColumns() Columns

NewColumns create a new Columns.

func ParseColumns

func ParseColumns(cols ...string) Columns

ParseColumns create a new Columns based on a string(s) input. This function should be called to initiate the Columns field.

type Delete

type Delete struct {
	Table string
	Where Where
}

Delete is the representation of an Delete statement.

func NewDelete added in v0.0.7

func NewDelete(t string) *Delete

NewDelete create a new delete.

func (*Delete) Args

func (d *Delete) Args() (out []any)

Args compute the arguments of the delete statement.

func (*Delete) String

func (d *Delete) String() string

String convert the delete into string.

type GroupBy

type GroupBy interface {
	Columns
}

GroupBy is the representation of the GROUP BY clause.

func NewGroupBy

func NewGroupBy() GroupBy

NewGroupBy create a new GroupBy.

func ParseGroupBy

func ParseGroupBy(cols ...string) GroupBy

ParseGroupBy create a new GroupBy based on a string(s) input. This function should be called to initiate the GroupBy field.

type H

type H map[string]any

H is the representation of an insert or update values.

func (H) Keys

func (v H) Keys() Keys

Keys return sorted keys of the values.

type Having

type Having interface {
	Where
}

Having is the representation of the Having clause.

func MakeHaving

func MakeHaving(f func(having Having)) (out Having)

MakeHaving create a new Having with complex rules. This function should be called to initiate the Having field.

func NewHaving

func NewHaving() Having

NewHaving create a new Having.

func ParseHaving

func ParseHaving(str string, args ...any) Having

ParseHaving create a new Having based on string input. This function should be called to initiate the Having field.

type Insert

type Insert struct {
	Table      string
	Select     Select
	IgnoreMode bool
	Values     H

	OnUpdateKeys    Keys
	OnUpdateRawKeys RawKeys
	// contains filtered or unexported fields
}

Insert is the representation of an Insert statement.

func NewInsert added in v0.0.7

func NewInsert(t string) *Insert

NewInsert create a new insert.

func (*Insert) Args

func (i *Insert) Args() (out []any)

Args compute the arguments of the insert statement.

func (*Insert) String

func (i *Insert) String() string

String convert the insert to string.

type Join

type Join struct {
	Table string
	Type  string
	On    On
}

Join is the representation of the Join.

func NewJoin added in v0.0.9

func NewJoin() Join

NewJoin create a new Join.

func NewLeftJoin added in v0.0.9

func NewLeftJoin() Join

NewLeftJoin create a new left Join.

func ParseJoin added in v0.0.9

func ParseJoin(t string, on On) Join

ParseJoin create a new Join.

func ParseLeftJoin added in v0.0.9

func ParseLeftJoin(t string, on On) Join

ParseLeftJoin create a new left Join.

func (*Join) Args

func (j *Join) Args() (args []any)

Args return the arguments for the join.

func (*Join) String

func (j *Join) String() string

String convert Join to string.

type Joins

type Joins []Join

Joins is a slice of Join.

func (*Joins) Add

func (j *Joins) Add(joins ...Join) *Joins

Add a new Join to the list.

func (Joins) Args

func (j Joins) Args() []any

Args return the args of the joins.

func (Joins) Len

func (j Joins) Len() int

Len return the number of join.

func (Joins) String

func (j Joins) String() string

String convert Joins to string.

type Keys

type Keys []string

Keys is a slice of string representing a list of key.

type On

type On interface {
	Where
}

On is the representation of the On clause.

func MakeOn

func MakeOn(f func(o On)) On

MakeOn create a new On with complex rules. This function should be called to initiate the On field from Joins.

func NewOn

func NewOn() On

NewOn create a new On.

func ParseOn

func ParseOn(str string, args ...any) On

ParseOn create a new Where based on string input. This function should be called to initiate the On field from Join.

type OrderBy

type OrderBy interface {
	Columns
}

OrderBy clause for the SELECT query.

func NewOrderBy added in v0.0.2

func NewOrderBy() OrderBy

NewOrderBy create a new OrderBy.

func ParseOrderBy

func ParseOrderBy(cols ...string) OrderBy

ParseOrderBy create a new OrderBy based on a string(s) input. This function should be called to initiate the OrderBy field.

type Query

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

Query is the representation of an Query statement.

func NewQuery

func NewQuery(str string, args ...any) *Query

NewQuery create a new Query based on string input.

func ParseQuery added in v0.0.6

func ParseQuery(str string, args ...any) *Query

ParseQuery create a new Query based on string input.

func (*Query) Args

func (q *Query) Args() []any

Args return the arguments of the query.

func (*Query) String

func (q *Query) String() string

String convert query to string.

type RawKeys

type RawKeys map[string]string

RawKeys is used to map keys to expression (On Duplicate Key Update case).

type Select

type Select struct {
	Table   string
	Columns Columns
	Joins   Joins
	Where   Where
	Having  Having
	GroupBy GroupBy
	OrderBy OrderBy
	Limit   uint64
	Offset  uint64
}

Select is the representation of the Select statement.

func NewSelect added in v0.0.7

func NewSelect(t string) *Select

NewSelect create a new select.

func (*Select) Args

func (s *Select) Args() (out []any)

Args compute the arguments of the select query.

func (*Select) String

func (s *Select) String() string

String convert the select to string.

type Slicer

type Slicer interface {
	Len() int
	S() []any
}

Slicer abstract a slice (until generics are supported)

type Update

type Update struct {
	Table  string
	Values H
	Binds  Binds
	Joins  Joins
	Where  Where
}

Update is the representation of an Update statement.

func NewUpdate added in v0.0.7

func NewUpdate(t string) *Update

NewUpdate create a new update.

func (*Update) Args

func (u *Update) Args() (out []any)

Args compute the arguments of the update statement.

func (*Update) String

func (u *Update) String() string

String convert the update to string.

type Where

type Where interface {
	// Args return the arguments of the where.
	Args() []any

	// String convert Where to string.
	String() string

	// And add a new condition "AND".
	And(str string, args ...any) Where

	// AndIf a new condition "AND" if args is Valid & and not Zero.
	AndIf(str string, arg any) Where

	// AndIn add a new condition "AND" with the operator IN.
	AndIn(col string, s Slicer) Where

	// AndNotIn add a new condition "AND" with the operator NOT IN.
	AndNotIn(col string, s Slicer) Where

	// AndWhere merge Where's inside parenthesis with AND condition.
	// AND ( where )
	AndWhere(in ...Where) Where

	// Or add a new condition "OR".
	Or(str string, args ...any) Where

	// OrIf a new condition "or" if args is Valid & and not Zero.
	OrIf(str string, arg any) Where

	// OrIn add a new condition "OR" with the operator IN.
	OrIn(col string, s Slicer) Where

	// OrNotIn add a new condition "OR" with the operator NOT IN.
	OrNotIn(col string, s Slicer) Where

	// OrWhere merge Where's inside parenthesis with OR condition.
	// OR ( where )
	OrWhere(in ...Where) Where

	// Len says the length of the string.
	Len() int
}

Where clause for the SQL query.

func MakeWhere

func MakeWhere(f func(w Where)) Where

MakeWhere create a new Where with complex rules. This function should be called to initiate the Where field.

func NewWhere

func NewWhere() Where

NewWhere create a new Where.

func ParseWhere

func ParseWhere(str string, args ...any) Where

ParseWhere create a new Where based on string input. This function should be called to initiate the Where field.

Jump to

Keyboard shortcuts

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