query

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2025 License: Apache-2.0 Imports: 8 Imported by: 9

Documentation

Index

Constants

View Source
const (
	UnknownData = iota
	BigIntData
	BinaryData
	BitData
	BlobData
	BooleanData
	CharData
	CharacterData
	ClobData
	DateData
	DateTimeData
	DecimalData
	DoubleData
	DoublePrecision
	FloatData
	IntData
	IntegerData
	LongBlobData
	LongTextData
	MediumBlobData
	MediumIntData
	MediumTextData
	NumericData
	RealData
	SetData
	SmallIntData
	TextData
	TimeData
	TimeStampData
	TinyBlobData
	TinyIntData
	TinyTextData
	VarBinaryData
	VarCharData
	VarCharacterData
	YearData
)
View Source
const (
	// Math.
	AbsFunctionName   = "ABS"
	CeilFunctionName  = "CEIL"
	FloorFunctionName = "FLOOR"
	// Aggregator.
	MaxFunctionName   = "MAX"
	MinFunctionName   = "MIN"
	SumFunctionName   = "SUM"
	AvgFunctionName   = "AVG"
	CountFunctionName = "COUNT"
)
View Source
const (
	UnknownLiteral = iota
	StringLiteral
)
View Source
const (
	CreateDatabaseStatement = iota
	CreateTableStatement
	CreateIndexStatement
	InsertStatement
	SelectStatement
	UpdateStatement
	DeleteStatement
	DropDatabaseStatement
	DropTableStatement
	DropIndexStatement
	AlterDatabaseStatement
	AlterTableStatement
	AlterIndexStatement
	CopyStatement
	CommitStatement
	VacuumStatement
	TruncateStatement
	BeginStatement
	RollbackStatement
	UseStatement
)
View Source
const (
	// Asterisk is a asterisk string.
	Asterisk = "*"
)
View Source
const GroupByNone = ""

GroupByNone represents an empty GROUP BY clause.

View Source
const TableNameSep = "."

TableNameSep represents a table name separator.

Variables

View Source
var ErrInvalid = errors.New("invalid")

ErrInvalid is returned when the value is invalid.

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned when the data type is invalid.

View Source
var ErrNotSupported = errors.New("not supported")

ErrNotSupported is returned when the function is not supported.

View Source
var NullLiteral = NewLiteralWith(nil)

NullLiteral represents a null value.

Functions

func ExecuteFunction added in v1.1.1

func ExecuteFunction(name string, args ...any) (any, error)

ExecuteFunction returns the executed value with the specified arguments.

func NewAlterDatabaseWith

func NewAlterDatabaseWith(name string, to string) *alterDatabaseStmt

NewAlterDatabaseWith returns a new alterDatabase statement instance with the specified options.

func NewBegin added in v1.2.0

func NewBegin() *beginStmt

NewBegin returns a new begin statement.

func NewBindParamWith added in v0.9.1

func NewBindParamWith(name string) *bindParam

NewBindParam returns a bind param instance.

func NewCommit added in v0.9.2

func NewCommit() *commitStmt

NewCommitWith returns a new commitStmt statement instance with the specified parameters.

func NewCopyWith added in v0.9.2

func NewCopyWith(tblName string, src string, opts ...CopyOption) *copyStmt

NewCopyWith returns a new copyStmt statement instance with the specified parameters.

func NewDropDatabaseWith

func NewDropDatabaseWith(name string, ife *IfExistsOpt) *dropDatabaseStmt

NewDropDatabaseWith returns a new dropDatabase statement instance with the specified parameters.

func NewDropTableWith

func NewDropTableWith(tbls TableList, ife *IfExistsOpt) *dropTableStmt

NewDropTableWith returns a new dropTable statement instance with the specified parameters.

func NewGroupBy added in v1.1.1

func NewGroupBy() *groupBy

NewGroupBy returns a new groupBy instance.

func NewGroupByWith added in v1.1.1

func NewGroupByWith(column string) *groupBy

NewGroupByWith returns a new groupBy instance with the specified column name.

func NewLimitWith added in v1.0.0

func NewLimitWith(offset int, limit int) *limitParam

NewLimitWith returns a new limitParam instance with the specified offset and limit.

func NewRollback added in v1.2.0

func NewRollback() *rollbackStmt

NewRollbackWith returns a new rollbackStmt statement instance with the specified parameters.

func NewSelectWith

func NewSelectWith(selectors Selectors, tbls TableList, w Condition, opts ...SelectOption) *selectStmt

NewSelectWith returns a new selectStmt statement instance with the specified parameters.

func NewTruncateWith added in v0.9.2

func NewTruncateWith(tbls TableList) *truncateStmt

NewTruncateWith returns a new truncate statement instance with the specified parameters.

func NewUseWith added in v1.3.5

func NewUseWith(name string) *useStmt

func NewVacuum added in v0.9.2

func NewVacuum() *vacuumStmt

NewVacuum returns a new vacuum statement instance.

func NewVacuumWith added in v0.9.2

func NewVacuumWith(tbl Table) *vacuumStmt

NewVacuumWith returns a new vacuum statement instance with the specified parameters.

func WithAlterTableAddColumn added in v0.9.2

func WithAlterTableAddColumn(column Column) func(*alterTableStmt)

WithAlterTableAddColumn sets an add column.

func WithAlterTableAddIndex added in v1.2.6

func WithAlterTableAddIndex(index Index) func(*alterTableStmt)

WithAlterTableAddIndex sets an add index.

func WithAlterTableDropColumn added in v0.9.2

func WithAlterTableDropColumn(column Column) func(*alterTableStmt)

WithAlterTableDropColumn sets a drop column.

func WithAlterTableDropIndex added in v1.3.2

func WithAlterTableDropIndex(index Index) func(*alterTableStmt)

WithAlterTableDropColumn sets a drop index.

func WithAlterTableRenameColumn added in v0.9.2

func WithAlterTableRenameColumn(from Column, to Column) func(*alterTableStmt)

WithAlterTableRenameColumn sets a rename column.

func WithAlterTableRenameTo added in v0.9.2

func WithAlterTableRenameTo(tbl Table) func(*alterTableStmt)

WithAlterTableRenameTo sets a rename table.

func WithAlterTableSchema added in v0.9.2

func WithAlterTableSchema(name string) func(*alterTableStmt)

WithAlterTableSchema sets a schema.

func WithColumnArguments added in v1.2.3

func WithColumnArguments(args []any) func(*column)

WithColumnArguments sets column arguments.

func WithColumnData added in v0.9.1

func WithColumnData(data ColumnDef) func(*column)

WithColumnData sets a column data.

func WithColumnFunction added in v1.2.3

func WithColumnFunction(fn FunctionExecutor) func(*column)

WithColumnFunction sets a column function.

func WithColumnLiteral added in v0.9.1

func WithColumnLiteral(l *Literal) func(*column)

WithColumnLiteral sets a column data.

func WithColumnName added in v0.9.1

func WithColumnName(name string) func(*column)

WithColumnName sets a column name.

func WithCopyColumns added in v1.2.4

func WithCopyColumns(columns ...Column) func(*copyStmt)

WithCopyColumns returns a copy option to set the columns.

func WithCopyFormat added in v1.2.4

func WithCopyFormat(fmt string) func(*copyStmt)

WithCopyFormat returns a copy option to set the format.

func WithLiteralType added in v0.9.1

func WithLiteralType(t LiteralType) func(*Literal)

WithSchemaColumns returns a schema option to set the columns.

func WithSchemaColumns added in v0.9.1

func WithSchemaColumns(columns Columns) func(*schema)

WithSchemaColumns returns a schema option to set the columns.

func WithSchemaIndexes added in v0.9.1

func WithSchemaIndexes(idxes Indexes) func(*schema)

WithSchemaIndexes returns a schema option to set the indexes.

func WithSelectGroupBy added in v1.1.1

func WithSelectGroupBy(name string) func(*selectStmt)

WithSelectOrderBy sets order by options.

func WithSelectLimit added in v1.0.0

func WithSelectLimit(offset int, limit int) func(*selectStmt)

WithSelectLimit sets order by options.

func WithSelectOrderBy added in v1.0.0

func WithSelectOrderBy(orderBy OrderBy) func(*selectStmt)

WithSelectOrderBy sets order by options.

func WithTableSchema added in v1.2.4

func WithTableSchema(schema string) func(*table)

WithTableSchema sets a table schema.

Types

type AggregateFunc added in v1.1.1

type AggregateFunc func(int, float64, float64) float64

AggregateFunc represents an aggregator function.

type AggregateFunction added in v1.1.1

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

AggregateFunction represents a base aggregator function.

func NewAggregateFunctionWith added in v1.1.1

func NewAggregateFunctionWith(name string, fn AggregateFunc) *AggregateFunction

NewAggregateFunctionWith returns a new base aggregator function with the specified name and aggregator.

func NewAvgFunction added in v1.1.1

func NewAvgFunction() *AggregateFunction

NewAvgFunction returns a new avg function.

func NewCountFunction added in v1.1.1

func NewCountFunction() *AggregateFunction

NewCountFunction returns a new count function.

func NewMaxFunction added in v1.1.1

func NewMaxFunction() *AggregateFunction

NewMaxFunction returns a new max function.

func NewMinFunction added in v1.1.1

func NewMinFunction() *AggregateFunction

NewMinFunction returns a new min function.

func NewSumFunction added in v1.1.1

func NewSumFunction() *AggregateFunction

NewSumFunction returns a new sum function.

func (*AggregateFunction) Execute added in v1.1.1

func (fn *AggregateFunction) Execute(args ...any) (any, error)

Execute returns the executed value with the specified arguments.

func (*AggregateFunction) Name added in v1.1.1

func (fn *AggregateFunction) Name() string

Name returns the name of the function.

func (*AggregateFunction) ResultSet added in v1.1.1

func (fn *AggregateFunction) ResultSet() AggregateResultSet

Aggregate returns the latest aggregated value.

func (*AggregateFunction) Type added in v1.1.1

func (fn *AggregateFunction) Type() FunctionType

Type returns the type of the function.

type AggregateResultSet added in v1.1.1

type AggregateResultSet map[any]float64

AggregateResultSet represents a result set of an aggregator function.

type AlterDatabase

type AlterDatabase interface {
	Statement
	// DatabaseName returns the database name.
	DatabaseName() string
	// RenameTo returns the "TO" database.
	RenameTo() Database
}

AlterDatabase represents a "ALTER DATABASE" statement interface.

type AlterTable

type AlterTable interface {
	Statement
	// TableName returns the table name.
	TableName() string
	// RenameTo returns the rename table.
	RenameTo() (Table, bool)
	// RenameColumns returns the rename columns.
	AddColumn() (Column, bool)
	// DropColumn returns the drop column.
	DropColumn() (Column, bool)
	// RenameColumns returns the rename columns.
	RenameColumns() (Column, Column, bool)
	// AddIndex returns the add index.
	AddIndex() (Index, bool)
	// DropIndex returns the drop index.
	DropIndex() (Index, bool)
}

AlterTable represents a "ALTER TABLE" statement interface.

func NewAlterTableFrom added in v1.4.2

func NewAlterTableFrom(stmt Statement) (AlterTable, error)

NewAlterTableFrom convert the specified statement to an AlterTable.

func NewAlterTableWith

func NewAlterTableWith(tblName string, opts ...AlterTableOption) AlterTable

NewAlterTableWith returns a new alterTable statement instance with the specified options.

type AlterTableOption added in v0.9.2

type AlterTableOption = func(*alterTableStmt)

AlterTableOption represents an alter table option function.

type AndExpr

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

AndExpr represents an AND expression.

func NewAndExpr added in v1.5.0

func NewAndExpr(left Expr, right Expr) *AndExpr

NewAndExpr returns a new AndExpr.

func (*AndExpr) Left

func (expr *AndExpr) Left() Expr

Left returns the left expression.

func (*AndExpr) Right

func (expr *AndExpr) Right() Expr

Right returns the right expression.

func (*AndExpr) String added in v1.5.0

func (expr *AndExpr) String() string

String returns the index string representation.

type Argument added in v1.1.0

type Argument string

Argument represents am argument in a function.

func NewArgumentWith added in v1.1.0

func NewArgumentWith(arg string) Argument

NewArgument returns a new argument instance from the specified string.

func (Argument) IsAsterisk added in v1.1.1

func (arg Argument) IsAsterisk() bool

IsAsterisk returns true whether the argument name is the asterisk.

func (Argument) IsName added in v1.1.1

func (arg Argument) IsName(name string) bool

IsName returns true whether the argument name is the specified one.

func (Argument) Name added in v1.1.1

func (arg Argument) Name() string

Name returns the name of the argument.

func (Argument) String added in v1.1.1

func (arg Argument) String() string

String returns the string representation of the argument.

type ArgumentList added in v1.1.0

type ArgumentList []Argument

ArgumentList represens an argument array in a function.

func NewArguments added in v1.1.0

func NewArguments() ArgumentList

NewArguments returns an empty argument array instance.

func NewArgumentsWith added in v1.1.0

func NewArgumentsWith(args ...Argument) ArgumentList

NewArgumentsWith returns an argument array instance with the specified arguments.

func (ArgumentList) Arguments added in v1.1.0

func (arguments ArgumentList) Arguments() ArgumentList

Argument returns an argument array.

func (ArgumentList) String added in v1.1.0

func (arguments ArgumentList) String() string

String returns a string representation of the the argument list.

type ArithFunc added in v1.2.3

type ArithFunc func(any, any) (any, error)

ArithFunc represents an arithmetic function.

type ArithFunction added in v1.2.3

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

ArithFunction represents a base arithmetic function.

func NewAddFunction added in v1.2.3

func NewAddFunction(name string) *ArithFunction

NewAddFunction returns a new add function.

func NewArithFunctionWith added in v1.2.3

func NewArithFunctionWith(name string, fn ArithFunc) *ArithFunction

NewArithFunctionWith returns a new base arithmetic function with the specified name and arithmetic.

func NewDivFunction added in v1.2.3

func NewDivFunction(name string) *ArithFunction

NewDivFunction returns a new division function.

func NewModFunction added in v1.2.3

func NewModFunction(name string) *ArithFunction

NewModFunction returns a new mod function.

func NewMulFunction added in v1.2.3

func NewMulFunction(name string) *ArithFunction

NewMulFunction returns a new multiple function.

func NewSubFunction added in v1.2.3

func NewSubFunction(name string) *ArithFunction

NewSubFunction returns a new sub function.

func (*ArithFunction) Execute added in v1.2.3

func (fn *ArithFunction) Execute(args ...any) (any, error)

Execute returns the executed value with the specified arguments.

func (*ArithFunction) Name added in v1.2.3

func (fn *ArithFunction) Name() string

Name returns the name of the function.

func (*ArithFunction) Type added in v1.2.3

func (fn *ArithFunction) Type() FunctionType

Type returns the type of the function.

type Begin added in v1.2.0

type Begin interface {
	Statement
}

Begin represents a "BEGIN" statement interface.

type BindParam added in v0.9.1

type BindParam interface {
	Name() string
}

type BindParams added in v0.9.1

type BindParams []BindParam

BindParams represens a bind param array.

func NewBindParams added in v0.9.1

func NewBindParams() BindParams

NewBindParams returns a bind param array instance.

type CastFunc added in v1.1.1

type CastFunc = func(any) (any, error)

CastFunc returns the latest aggregated value.

type CastFunction added in v1.1.1

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

CastFunction represents a base cast function.

func NewCastFunctionWith added in v1.1.1

func NewCastFunctionWith(name string, cast CastFunc) *CastFunction

NewCastFunctionWith returns a new base cast function with the specified name and cast.

func (*CastFunction) Execute added in v1.1.1

func (fn *CastFunction) Execute(args ...any) (any, error)

Execute returns the executed value with the specified arguments.

func (*CastFunction) Name added in v1.1.1

func (fn *CastFunction) Name() string

Name returns the name of the function.

func (*CastFunction) Type added in v1.1.1

func (fn *CastFunction) Type() FunctionType

Type returns the type of the function.

type CmpExpr added in v0.9.1

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

CmpExpr represents an comparison expression.

func NewCmpExprWith added in v1.2.4

func NewCmpExprWith(op CmpExprOperator, left Column, right *Literal) *CmpExpr

NewCmpExprWith returns a new CompExpr instance with the specified parameters.

func NewEQWith added in v1.2.4

func NewEQWith(left Column, right *Literal) *CmpExpr

NewEQ returns a new CompExpr instance with the specified parameters.

func NewGEWith added in v1.2.4

func NewGEWith(left Column, right *Literal) *CmpExpr

NewGE returns a new CompExpr instance with the specified parameters.

func NewGTWith added in v1.2.4

func NewGTWith(left Column, right *Literal) *CmpExpr

NewGT returns a new CompExpr instance with the specified parameters.

func NewLEWith added in v1.2.4

func NewLEWith(left Column, right *Literal) *CmpExpr

NewLE returns a new CompExpr instance with the specified parameters.

func NewLTWith added in v1.2.4

func NewLTWith(left Column, right *Literal) *CmpExpr

NewLT returns a new CompExpr instance with the specified parameters.

func NewNEQWith added in v1.2.4

func NewNEQWith(left Column, right *Literal) *CmpExpr

NewNEQ returns a new CompExpr instance with the specified parameters.

func (*CmpExpr) Left added in v0.9.1

func (expr *CmpExpr) Left() Column

Left returns the left column.

func (*CmpExpr) Operator added in v0.9.1

func (expr *CmpExpr) Operator() CmpExprOperator

Operator returns the operator.

func (*CmpExpr) Right added in v0.9.1

func (expr *CmpExpr) Right() *Literal

Right returns the right literal.

func (*CmpExpr) String added in v0.9.1

func (expr *CmpExpr) String() string

String returns the index string representation.

type CmpExprOperator added in v0.9.1

type CmpExprOperator uint8

CmpExprOperator is an enum for CompExpr.Operator.

const (
	EQ CmpExprOperator = iota
	NEQ
	LT
	GT
	LE
	GE
	IN
	NIN
)

Constants for Enum Type - CompExprOperator.

func (CmpExprOperator) String added in v0.9.1

func (t CmpExprOperator) String() string

String returns the string representation.

type Column

type Column interface {
	// Name returns the column name.
	Name() string
	// IsName returns true whether the column name is the specified one.
	IsName(string) bool
	// Definition returns the column definition.
	Definition() ColumnDef
	// Constraint returns the column constrains.
	Constraint() Constraint
	// DataType returns the column data type.
	DataType() DataType
	// DataTypeSize returns the column data type size.
	DataTypeSize() int
	// HasValue returns true whether the column has a value.
	HasValue() bool
	// SetValue sets a value.
	SetValue(any) error
	// Value returns the column value.
	Value() any
	// ValueType returns the column value type.
	ValueType() LiteralType
	// ValueString returns the column value string.
	ValueString() string
	// IsPlaceHolder returns true whether the column is a place holder.
	IsPlaceHolder() bool
	// IsFunction returns true whether the column is a function.
	IsFunction() (Function, bool)
	// Arguments returns the executor arguments.
	Arguments() []any
	// Copy returns a copy of the column.
	Copy() Column
	// String returns the string representation.
	String() string
}

Column represents a column interface.

func NewColumnWithName

func NewColumnWithName(name string) Column

NewColumn returns a column instance.

func NewColumnWithOptions added in v0.9.1

func NewColumnWithOptions(opts ...ColumnOption) Column

NewColumn returns a column instance.

type ColumnDef added in v1.4.0

type ColumnDef interface {
	// Constraint returns the column constrains.
	Constraint() Constraint
	// DataType returns the column data type.
	DataType() DataType
	// DataTypeSize returns the column data type size.
	DataTypeSize() int
	// String returns the string representation.
	String() string
}

ColumnDef represents a data definition interface.

func NewDataDef added in v1.4.0

func NewDataDef(t DataType, l int) ColumnDef

NewDataDef returns a new DataType instance with the specified type and length.

func NewDataDefFrom added in v1.4.0

func NewDataDefFrom(s string, l int) (ColumnDef, error)

NewDataDefFrom returns the data type of the specified string.

func NewUnknownDataDef added in v1.4.0

func NewUnknownDataDef() ColumnDef

NewUnknownDataDef returns a new unknown data type instance.

type ColumnOption added in v0.9.1

type ColumnOption = func(*column)

ColumnOption represents a column option function.

type Columns

type Columns []Column

Columns represens a column array.

func NewColumns

func NewColumns() Columns

NewColumns returns a column array instance.

func NewColumnsWith

func NewColumnsWith(columns ...Column) Columns

NewColumnsWith returns a column array instance with the specified columns.

func (Columns) ColumnAt added in v1.4.0

func (columns Columns) ColumnAt(n int) (Column, error)

ColumnAt returns a column by the specified index.

func (Columns) ColumnNames added in v1.4.0

func (columns Columns) ColumnNames() []string

ColumnNames returns a column name array.

func (Columns) Columns

func (columns Columns) Columns() Columns

Column returns a column array.

func (Columns) Copy added in v1.4.0

func (columns Columns) Copy() Columns

Copy returns a copy of the column list.

func (Columns) DefinitionString added in v1.4.0

func (columns Columns) DefinitionString() string

DefinitionString returns a string representation of the the column definitions.

func (Columns) IsAsterisk added in v1.4.0

func (columns Columns) IsAsterisk() bool

IsAsterisk returns true if the column list is "*".

func (Columns) Len added in v1.4.0

func (columns Columns) Len() int

Len returns the length of the column array.

func (Columns) LookupColumn added in v1.4.0

func (columns Columns) LookupColumn(name string) (Column, error)

LookupColumn returns a column by the specified name.

func (Columns) LookupIndexOfColumn added in v1.4.0

func (columns Columns) LookupIndexOfColumn(name string) (int, error)

LookupIndexOfColumn returns the index of the column by the specified name.

func (Columns) NameString

func (columns Columns) NameString() string

NameString returns a string representation of the the column names.

func (Columns) Names

func (columns Columns) Names() []string

Names returns a column name array.

func (Columns) Selectors added in v1.4.0

func (columns Columns) Selectors() Selectors

Selectors returns a selector array.

func (Columns) SetSchema added in v1.4.0

func (columns Columns) SetSchema(schema Schema) error

SetSchema sets a schema to update column values.

func (Columns) ValueString

func (columns Columns) ValueString() string

ValueString returns a string representation of the the column values.

type Commit added in v0.9.2

type Commit interface {
	Statement
}

Commit represents a "COMMIT" statement interface.

type Condition added in v0.9.1

type Condition interface {
	// HasConditions returns true if the condition has conditions.
	HasConditions() bool
	// Expr returns the top expression.
	Expr() Expr
	// String returns the string representation.
	String() string
}

Condition represents a where condition interface.

func NewCondition added in v1.4.0

func NewCondition() Condition

NewCondition returns a new where condition instance.

func NewConditionWith added in v0.9.1

func NewConditionWith(expr Expr) Condition

NewConditionWith returns a new where condition instance with the specified parameters.

type Constraint added in v1.4.0

type Constraint int

Constraint represents a column constraint.

const (
	// ConstraintNone represents no constraint.
	ConstraintNone       Constraint = 0x00
	PrimaryKeyConstraint Constraint = 0x01
	NotNullConstraint    Constraint = 0x02
	UniqueConstraint     Constraint = 0x04
)

func (Constraint) IsNotNull added in v1.5.0

func (c Constraint) IsNotNull() bool

IsNotNull returns true whether the column is not null.

func (Constraint) IsPrimaryKey added in v1.4.0

func (c Constraint) IsPrimaryKey() bool

IsPrimaryKey returns true whether the column is a primary key.

func (Constraint) IsUnique added in v1.5.0

func (c Constraint) IsUnique() bool

IsUnique returns true whether the column is unique.

func (Constraint) String added in v1.4.0

func (c Constraint) String() string

String returns the string representation.

type Copy added in v0.9.2

type Copy interface {
	Statement
	// TableName returns the table name.
	TableName() string
	// Columns returns the column list.
	Columns() Columns
}

Copy represents a "COPY" statement interface.

type CopyFormat added in v1.2.4

type CopyFormat uint8

CopyFormat represents a copy format.

const (
	// CopyFormatText represents a text format.
	CopyFormatText CopyFormat = iota
	// CopyFormatCSV represents a CSV format.
	CopyFormatCSV
	// CopyFormatBinary represents a binary format.
	CopyFormatBinary
)

func (CopyFormat) String added in v1.2.4

func (fmt CopyFormat) String() string

String returns the string representation of the format.

type CopyOption added in v1.2.4

type CopyOption = func(*copyStmt)

CopyOption represents a copy option.

type CreateDatabase

type CreateDatabase interface {
	Statement
	// DatabaseName returns the database name.
	DatabaseName() string
	// IfNotExists returns true if the "IF NOT EXISTS" option is set.
	IfNotExists() bool
}

CreateDatabase represents a "CREATE DATABASE" statement interface.

func NewCreateDatabaseWith

func NewCreateDatabaseWith(name string, ifne *IfNotExistsOpt) CreateDatabase

NewCreateDatabaseWith returns a new createDatabase statement instance with the specified options.

type CreateIndex

type CreateIndex interface {
	Statement
	// TableName returns the table name.
	TableName() string
	// Index returns the index.
	Index() Index
	// IfNotExists returns true if the "IF NOT EXISTS" option is set.
	IfNotExists() bool
}

CreateIndex is a "CREATE INDEX" statement interface.

func NewCreateIndexWith

func NewCreateIndexWith(schema Schema, ifne *IfNotExistsOpt) CreateIndex

NewCreateIndexWith returns a new createIndex statement instance with the specified parameters.

type CreateTable

type CreateTable interface {
	Statement
	// TableName returns the table name.
	TableName() string
	// Schema returns the schema.
	Schema() Schema
	// IfNotExists returns true if the "IF NOT EXISTS" option is set.
	IfNotExists() bool
}

CreateTable represents a "CREATE TABLE" statement interface.

func NewCreateTableWith

func NewCreateTableWith(schema Schema, ifne *IfNotExistsOpt) CreateTable

NewCreateTableWith returns a new createTable statement instance with the specified options.

type DataType

type DataType uint8

DataType represents a data type.

func NewDataTypeFrom added in v1.5.0

func NewDataTypeFrom(a any) (DataType, error)

NewDataTypeFrom create a data type from the specified value.

func (DataType) String

func (t DataType) String() string

String returns the string representation.

type Database

type Database interface {
	DatabaseName() string
}

Database represents a database interface.

func NewDatabaseWith

func NewDatabaseWith(name string) Database

NewDatabaseWith returns a new database instance with the specified name.

type Delete

type Delete interface {
	Statement
	// Table returns the table.
	TableName() string
	// HasConditions returns true if the statement has conditions.
	HasConditions() bool
	// Where returns the condition.
	Where() Condition
}

Delete represents a "DELETE" statement interface.

func NewDeleteWith

func NewDeleteWith(tbl Table, w Condition, opts ...DeleteOption) Delete

NewDeleteWith returns a new deleteStmt statement instance with the specified parameters.

type DeleteOption added in v1.2.2

type DeleteOption = func(*deleteStmt)

DeleteOption represents a delete option function.

type DropDatabase

type DropDatabase interface {
	Statement
	// DatabaseName returns the database name.
	DatabaseName() string
	// IfExists returns true if the "IF EXISTS" option is set.
	IfExists() bool
}

DropDatabase represents a "DROP DATABASE" statement interface.

type DropIndex

type DropIndex interface {
	Statement
	// TableName returns the table name.
	TableName() string
	// Indexreturns the index.
	Index() Index
	// IndexName returns the index name.
	IndexName() string
	// IfExists returns true if the "IF EXISTS" option is set.
	IfExists() bool
}

DropIndex is a "DROP INDEX" statement interface.

func NewDropIndexWith

func NewDropIndexWith(schemaName string, idxName string, ife *IfExistsOpt) DropIndex

NewDropIndexWith returns a new dropIndex statement instance with the specified parameters.

type DropTable

type DropTable interface {
	Statement
	// Tables returns the table list.
	Tables() TableList
	// TableNames returns the table names.
	TableNames() []string
	// IfExists returns true if the "IF EXISTS" option is set.
	IfExists() bool
}

DropTable represents a "DROP TABLE" statement interface.

type Expr

type Expr interface {
	// String returns the index string representation.
	String() string
}

Expr represents an expression.

type Function added in v1.1.0

type Function interface {
	// Name returns the function name.
	Name() string
	// IsName returns true whether the function name is the specified one.
	IsName(string) bool
	// Arguments returns the argument list.
	Arguments() ArgumentList
	// IsAsterisk returns true if the argument list is "*".
	IsAsterisk() bool
	// Executor returns the executor of the function.
	Executor() (FunctionExecutor, error)
	// Execute executes the executor with the specified row.
	Execute(col Column, row map[string]any) (any, error)
	// String returns a string representation of the function.
	String() string
}

Function represents a .

func NewFunctionWith added in v1.1.0

func NewFunctionWith(opts ...FunctionOption) Function

NewFunctionWith returns a function instance.

type FunctionExecutor added in v1.1.1

type FunctionExecutor interface {
	// Name returns the name of the function.
	Name() string
	// Type returns the type of the function.
	Type() FunctionType
	// Execute returns the executed value with the specified arguments.
	Execute(...any) (any, error)
}

FunctionExecutor represents a function executor interface.

func GetFunctionExecutor added in v1.1.1

func GetFunctionExecutor(name string) (FunctionExecutor, error)

GetFunctionExecutor returns a function executor with the specified name.

type FunctionOption added in v1.4.0

type FunctionOption = func(*function)

FunctionOption represents a function option function.

func WithFunctionArguments added in v1.4.0

func WithFunctionArguments(args ...Argument) FunctionOption

WithFunctionArguments sets the function arguments.

func WithFunctionExecutor added in v1.4.0

func WithFunctionExecutor(executor FunctionExecutor) FunctionOption

WithFunctionExecutor sets the function executor.

func WithFunctionName added in v1.4.0

func WithFunctionName(name string) FunctionOption

WithFunctionName sets the function name.

type FunctionType added in v1.1.1

type FunctionType int

FunctionType represents a function type.

const (
	MathFunctionType FunctionType = iota
	AggregateFunctionType
	CastFunctionType
	ArithFunctionType
)

type GroupBy added in v1.1.1

type GroupBy interface {
	// ColumnName returns the column name.
	ColumnName() string
	// String returns the string representation.
	String() string
}

GroupBy represents an GROUP interface.

type IfExistsOpt added in v0.9.1

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

IfExistsOpt represents a IF EXISTS option.

func NewIfExistsWith

func NewIfExistsWith(v bool) *IfExistsOpt

NewIfExistsWith returns a new IfExists option instance.

func (*IfExistsOpt) IfExists added in v0.9.1

func (opt *IfExistsOpt) IfExists() bool

IfExists returns the IF EXISTS option.

func (*IfExistsOpt) String added in v0.9.1

func (opt *IfExistsOpt) String() string

String returns the string representation.

type IfNotExistsOpt added in v0.9.1

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

IfNotExistsOpt represents a IF NOT EXISTS option.

func NewIfNotExistsWith

func NewIfNotExistsWith(v bool) *IfNotExistsOpt

NewIfNotExistsWith returns a new IfNotExists option instance.

func (*IfNotExistsOpt) IfNotExists added in v0.9.1

func (opt *IfNotExistsOpt) IfNotExists() bool

IfNotExists returns the IF NOT EXISTS option.

func (*IfNotExistsOpt) String added in v0.9.1

func (opt *IfNotExistsOpt) String() string

String returns the string representation.

type Index

type Index interface {
	// Name returns the index name.
	Name() string
	// Type returns the index type.
	Type() IndexType
	// String returns the index string representation.
	Columns() Columns
	// DefinitionString returns the index definition string representation.
	DefinitionString() string
}

Index represents a index interface.

func NewIndexWith

func NewIndexWith(name string, t IndexType, columns Columns) Index

NewIndexWith returns a new index instance.

func NewPrimaryIndexWith

func NewPrimaryIndexWith(columns Columns) Index

NewPrimaryIndexWith returns a new primary index instance.

func NewSecondaryIndexWith

func NewSecondaryIndexWith(name string, columns Columns) Index

NewSecondaryIndexWith returns a new secondary index instance.

type IndexType

type IndexType uint8

IndexType represents a index type.

const (
	UnknownIndex   IndexType = 0
	PrimaryIndex   IndexType = 1
	SecondaryIndex IndexType = 2
)

func (IndexType) String

func (t IndexType) String() string

String returns the string representation.

type Indexes

type Indexes []Index

Indexes represents an index array.

func NewIndexes

func NewIndexes() Indexes

NewIndexes returns a new Indexes instance.

func (Indexes) DefinitionString added in v1.4.0

func (indexes Indexes) DefinitionString() string

DefinitionString returns the index definition string representation.

func (Indexes) IndexNames added in v1.4.0

func (indexes Indexes) IndexNames() []string

IndexNames returns an index name array.

func (Indexes) Indexes

func (indexes Indexes) Indexes() Indexes

Indexes returns an index array.

func (Indexes) LookupIndex added in v1.4.0

func (indexes Indexes) LookupIndex(name string) (Index, error)

LookupIndex returns an index by the specified name.

func (Indexes) LookupIndexOfIndex added in v1.4.0

func (indexes Indexes) LookupIndexOfIndex(name string) (int, error)

LookupIndexOfIndex returns an index index by the specified name.

type Insert

type Insert interface {
	Statement
	// TableName returns the table name.
	TableName() string
	// Columns returns the columns.
	Columns() Columns
}

Insert represents a "INSERT" statement interface.

func NewInsertWith

func NewInsertWith(tbl Table, columns Columns) Insert

NewInsertWith returns a new insert statement instance with the specified parameters.

type Limit added in v1.0.0

type Limit interface {
	// Offset returns the offset.
	Offset() int
	// Limit returns the limit.
	Limit() int
	// String returns the string representation.
	String() string
}

Limit represents a LIMIT interface.

func NewLimit added in v1.0.0

func NewLimit() Limit

NewLimit returns a new limit instance.

type Literal

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

Literal represents a constant value.

func NewLiteral added in v1.2.3

func NewLiteral() *Literal

NewLiteral returns a new Literal instance.

func NewLiteralWith

func NewLiteralWith(v any, opts ...LiteralOption) *Literal

NewLiteralWith returns a new Literal instance with the specified value.

func (*Literal) HasValue added in v1.4.0

func (lit *Literal) HasValue() bool

HasValue returns true whether the literal has a value.

func (*Literal) IsPlaceHolder added in v1.5.0

func (lit *Literal) IsPlaceHolder() bool

IsPlaceHolder returns true whether the literal is a place holder.

func (*Literal) SetValue added in v0.9.1

func (lit *Literal) SetValue(v any) *Literal

SetValue sets a value.

func (*Literal) SetValueType added in v1.4.0

func (lit *Literal) SetValueType(t LiteralType) *Literal

SetValueType sets a literal type.

func (*Literal) String

func (lit *Literal) String() string

String returns the string representation.

func (*Literal) Value

func (lit *Literal) Value() any

Value returns the literal value.

func (*Literal) ValueString added in v0.9.1

func (lit *Literal) ValueString() string

ValueString returns the string representation.

func (*Literal) ValueType added in v0.9.1

func (lit *Literal) ValueType() LiteralType

ValueType returns the literal type.

type LiteralOption added in v0.9.1

type LiteralOption = func(*Literal)

LiteralOption represents a literal option function.

type LiteralType added in v0.9.1

type LiteralType uint8

LiteralType represents a literal type.

type MathFunc added in v1.1.1

type MathFunc func(any) (any, error)

MathFunc represents an math function.

type MathFunction added in v1.1.1

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

MathFunction represents a base math function.

func NewAbsFunction added in v1.1.1

func NewAbsFunction() *MathFunction

NewAbsFunction returns a new abs function.

func NewCeilFunction added in v1.1.1

func NewCeilFunction() *MathFunction

NewCeilFunction returns a new ceil function.

func NewFloorFunction added in v1.1.1

func NewFloorFunction() *MathFunction

NewFloorFunction returns a new floor function.

func NewMathFunctionWith added in v1.1.1

func NewMathFunctionWith(name string, fn MathFunc) *MathFunction

NewMathFunctionWith returns a new base math function with the specified name and math.

func (*MathFunction) Execute added in v1.1.1

func (fn *MathFunction) Execute(args ...any) (any, error)

Execute returns the executed value with the specified arguments.

func (*MathFunction) Name added in v1.1.1

func (fn *MathFunction) Name() string

Name returns the name of the function.

func (*MathFunction) Type added in v1.1.1

func (fn *MathFunction) Type() FunctionType

Type returns the type of the function.

type MathResultSet added in v1.1.1

type MathResultSet map[any]float64

MathResultSet represents a result set of an math function.

type OrExpr

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

OrExpr represents an OR expression.

func NewOrExpr added in v1.5.0

func NewOrExpr(left Expr, right Expr) *OrExpr

NewOrExpr returns a new OrExpr.

func (*OrExpr) Left

func (expr *OrExpr) Left() Expr

Left returns the left expression.

func (*OrExpr) Right

func (expr *OrExpr) Right() Expr

Right returns the right expression.

func (*OrExpr) String added in v1.5.0

func (expr *OrExpr) String() string

String returns the index string representation.

type Order added in v1.0.0

type Order interface {
	// ColumnName returns the column name.
	ColumnName() string
	// Type returns the order type.
	Type() OrderType
	// IsNone returns true whether the order is none.
	IsNone() bool
	// IsAsc returns true whether the order is asc.
	IsAsc() bool
	// IsDesc returns true whether the order is desc.
	IsDesc() bool
	// String returns the string representation.
	String() string
}

Order represents an ORDER BY interface.

func NewOrder added in v1.2.1

func NewOrder() Order

NewOrder returns a new order instance.

func NewOrderWith added in v1.1.1

func NewOrderWith(column string, order OrderType) Order

NewOrderWith returns a new order instance with the specified column and order.

type OrderBy added in v1.0.0

type OrderBy interface {
	Orders() []Order
	String() string
}

OrderBy represents an ORDER BY interface.

func NewOrderBy added in v1.0.0

func NewOrderBy() OrderBy

NewOrderBy returns a new orderByParam instance.

func NewOrderByWith added in v1.0.0

func NewOrderByWith(orders []Order) OrderBy

NewOrderByWith returns a new orderByParam instance with the specified orders.

type OrderType

type OrderType uint8

OrderType represents an ordertype.

const (
	// OrderNone represents none order.
	OrderNone OrderType = iota
	// OrderAsc represents asc order.
	OrderAsc
	// OrderDesc represents desc order.
	OrderDesc
)

func NewOrderTypeWith added in v1.2.1

func NewOrderTypeWith(order string) OrderType

NewOrderTypeWith returns a new OrderType instance.

func (OrderType) IsAsc added in v1.2.1

func (t OrderType) IsAsc() bool

IsAsc returns true whether the order is asc.

func (OrderType) IsDesc added in v1.2.1

func (t OrderType) IsDesc() bool

IsDesc returns true whether the order is desc.

func (OrderType) IsNone added in v1.2.1

func (t OrderType) IsNone() bool

IsNone returns true whether the order is none.

func (OrderType) String

func (t OrderType) String() string

String returns the string representation.

type Rollback added in v1.2.0

type Rollback interface {
	Statement
}

Rollback represents a "ROLLBACK" statement interface.

type Schema

type Schema interface {
	// FullTableName returns the full table name.
	FullTableName() string
	// SchemaName returns the schema name.
	SchemaName() string
	// TableName returns the table name.
	TableName() string
	// Columns returns the all columns.
	Columns() Columns
	// LookupColumn returns a column by the specified name.
	LookupColumn(string) (Column, error)
	// Indexes returns the all indexes.
	Indexes() Indexes
	// LookupIndex returns an index by the specified name.
	LookupIndex(string) (Index, error)
	// Alter alters the schema.
	Alter(AlterTable) error
	// AddColumn adds a column.
	AddColumn(Column) error
	// DropColumn drops a column by the specified name.
	DropColumn(string) error
	// AddIndex adds an index.
	AddIndex(Index) error
	// DropIndex drops an index by the specified name.
	DropIndex(string) error
	// Selectors returns the all selectors from the columns.
	Selectors() Selectors
}

Schema represents a table schema interface.

func NewSchemaWith

func NewSchemaWith(name string, opts ...SchemaOption) Schema

NewSchemaWith returns a new schema statement instance with the parameters.

type SchemaOption added in v0.9.1

type SchemaOption = func(*schema)

SchemaOption represents a schema option function.

type Select

type Select interface {
	Statement
	// IsAsterisk returns true if the statement is a "SELECT *".
	IsAsterisk() bool
	// Selectors returns the selectors.
	Selectors() Selectors
	// From returns the source table list.
	From() TableList
	// Limit returns the limit clause.
	Limit() Limit
	// GroupBy returns the group by clause.
	GroupBy() GroupBy
	// OrderBy returns the order by clause.
	OrderBy() OrderBy
	// Where returns the condition.
	Where() Condition
}

Select represents a "SELECT" statement interface.

type SelectOption added in v1.0.0

type SelectOption = func(*selectStmt)

SelectOption represents a select option function.

type Selector added in v1.1.0

type Selector interface {
	// Name returns the name of the selector.
	Name() string
}

Selector represents a selector in a select query.

type Selectors added in v1.4.0

type Selectors []Selector

Selectors represens a selector array.

func NewSelectors added in v1.1.0

func NewSelectors() Selectors

NewSelectors returns a selector array instance.

func NewSelectorsWith added in v1.1.0

func NewSelectorsWith(selectors ...Selector) Selectors

NewSelectorsWith returns a selector array instance with the specified selectors.

func NewSelectorsWithColums added in v1.1.0

func NewSelectorsWithColums(selectors ...Column) Selectors

NewSelectorsWithColums returns a selector array instance with the specified selectors.

func (Selectors) AggregateFunctions added in v1.4.0

func (selectors Selectors) AggregateFunctions() ([]FunctionExecutor, error)

AggregateFunctions returns an aggregate function array.

func (Selectors) Columns added in v1.4.0

func (selectors Selectors) Columns() []Column

Column returns a column array.

func (Selectors) FunctionExecutors added in v1.4.0

func (selectors Selectors) FunctionExecutors() ([]FunctionExecutor, error)

FunctionExecutors returns a function executor array.

func (Selectors) FunctionExecutorsForType added in v1.4.0

func (selectors Selectors) FunctionExecutorsForType(t FunctionType) ([]FunctionExecutor, error)

FunctionExecutorsForType returns a function executor array with the specified type.

func (Selectors) Functions added in v1.4.0

func (selectors Selectors) Functions() []Function

Functions returns a function array.

func (Selectors) HasAggregateFunction added in v1.4.0

func (selectors Selectors) HasAggregateFunction() bool

HasAggregateFunction returns true if the selector list has an aggregate function.

func (Selectors) HasFunction added in v1.4.0

func (selectors Selectors) HasFunction() bool

HasFunction returns true if the selector list has a function.

func (Selectors) HasFunctionWithType added in v1.4.0

func (selectors Selectors) HasFunctionWithType(t FunctionType) bool

HasFunctionWithType returns true if the selector list has a function with the specified type.

func (Selectors) IsAsterisk added in v1.4.0

func (selectors Selectors) IsAsterisk() bool

IsAsterisk returns true if the selector list is "*".

func (Selectors) Len added in v1.4.0

func (selectors Selectors) Len() int

Len returns the length of the selector array.

func (Selectors) LookupFunction added in v1.4.0

func (selectors Selectors) LookupFunction(name string) (Function, error)

LookupFunction returns a function with the specified name.

func (Selectors) LookupFunctionExecutor added in v1.4.0

func (selectors Selectors) LookupFunctionExecutor(name string) (FunctionExecutor, error)

LookupFunctionExecutor returns a function executor with the specified name.

func (Selectors) SelectorNames added in v1.4.1

func (selectors Selectors) SelectorNames() []string

SelectorNames returns a name array.

func (Selectors) SelectorString added in v1.4.0

func (selectors Selectors) SelectorString() string

SelectorString returns a string representation of the selector array.

func (Selectors) Selectors added in v1.4.0

func (selectors Selectors) Selectors() Selectors

Selector returns a selector array.

type Statement

type Statement interface {
	// StatementType returns the statement type.
	StatementType() StatementType
	// String returns the statement string representation.
	String() string
}

Statement represents a statement interface.

type StatementList

type StatementList = []Statement

StatementList represents a statement list.

func NewStatementList

func NewStatementList() StatementList

NewStatementList returns a new statement list.

type StatementType

type StatementType uint8

StatementType is a statement type.

func (StatementType) String added in v1.2.6

func (stmtType StatementType) String() string

StatementType returns the statement type.

type Table

type Table interface {
	// FullTableName returns the full name of the table including schema and table name.
	FullTableName() string
	// IsFullTableName returns true if the provided name matches the full name of the table,
	IsFullTableName(name string) bool
	// SchemaName returns the table schema name.
	SchemaName() string
	// IsSchemaName returns true whether the table is named.
	IsSchemaName(name string) bool
	// TableName returns the table name for embedded use.
	TableName() string
	// IsTableName returns true whether the table is named.
	IsTableName(name string) bool
}

Table represents a table interface.

func NewTableWith

func NewTableWith(name string, opts ...TableOption) Table

NewTableWith returns a new table instance with the specified name.

type TableList added in v0.9.1

type TableList []Table

TableList represens a column array.

func NewTables

func NewTables() TableList

NewTables returns a column array instance.

func NewTablesWith

func NewTablesWith(tables ...Table) TableList

NewTablesWith returns a column array instance with the specified columns.

func (TableList) HasSchemaTable added in v1.2.4

func (tbls TableList) HasSchemaTable(names ...string) bool

HasSchemaTable returns true whether the table array has the specified table schema.

func (TableList) HasTable added in v1.2.4

func (tbls TableList) HasTable(names ...string) bool

HasTable returns true whether the table array has the specified table name.

func (TableList) HasTableName added in v1.2.4

func (tbls TableList) HasTableName(names ...string) bool

HasTableName returns true whether the table array has the specified table name.

func (TableList) String added in v0.9.1

func (tbls TableList) String() string

String returns a string representation.

func (TableList) TableNames added in v1.4.0

func (tbls TableList) TableNames() []string

TableNames returns the table names.

func (TableList) Tables added in v0.9.1

func (tbls TableList) Tables() TableList

Table returns a column array.

type TableOption added in v1.2.4

type TableOption = func(*table)

TableOption represents a table option function.

type Truncate added in v0.9.2

type Truncate interface {
	Statement
	// Tables returns the table list.
	Tables() TableList
	// TableNames returns the table names.
	TableNames() []string
}

Truncate represents a "TRUNCATE" statement interface.

type Update

type Update interface {
	Statement
	// Table returns the table.
	TableName() string
	// Columns returns the columns.
	Columns() Columns
	// Where returns the condition.
	Where() Condition
}

Update represents a "UPDATE" statement interface.

func NewUpdateWith

func NewUpdateWith(tbl Table, columns Columns, w Condition) Update

NewUpdateWith returns a new updateStmt statement instance with the specified parameters.

type Use added in v1.3.5

type Use interface {
	Statement
	// DatabaseName returns the database name.
	DatabaseName() string
}

Use represents a "USE" statement interface.

type Vacuum added in v0.9.2

type Vacuum interface {
	Statement
	// Table returns the table.
	Table() Table
	// TableName returns the table name.
	TableName() string
}

Vacuum represents a "VACUUM" statement interface.

Directories

Path Synopsis
response

Jump to

Keyboard shortcuts

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