statement

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindExpr added in v0.17.0

func BindExpr(ctx *Context, tableName string, e expr.Expr) (err error)

Types

type AlterTableAddColumnStmt

type AlterTableAddColumnStmt struct {
	TableName        string
	ColumnConstraint *database.ColumnConstraint
	TableConstraints database.TableConstraints
}

func (*AlterTableAddColumnStmt) Run

func (stmt *AlterTableAddColumnStmt) Run(ctx *Context) (*Result, error)

Run runs the ALTER TABLE ADD COLUMN statement in the given transaction. It implements the Statement interface. The statement rebuilds the table.

type AlterTableRenameStmt

type AlterTableRenameStmt struct {
	TableName    string
	NewTableName string
}

AlterTableRenameStmt is a DSL that allows creating a full ALTER TABLE query.

func (*AlterTableRenameStmt) Run

func (stmt *AlterTableRenameStmt) Run(ctx *Context) (*Result, error)

Run runs the ALTER TABLE statement in the given transaction. It implements the Statement interface.

type Bindable added in v0.18.0

type Bindable interface {
	Bind(*Context) error
}

Optional interface that allows a statement to specify if they need to be bound to database objects.

type Context

type Context struct {
	DB     *database.Database
	Conn   *database.Connection
	Params []environment.Param
}

type CreateIndexStmt

type CreateIndexStmt struct {
	IfNotExists bool
	Info        database.IndexInfo
}

CreateIndexStmt represents a parsed CREATE INDEX statement.

func (*CreateIndexStmt) Run

func (stmt *CreateIndexStmt) Run(ctx *Context) (*Result, error)

Run runs the Create index statement in the given transaction. It implements the Statement interface.

type CreateSequenceStmt

type CreateSequenceStmt struct {
	IfNotExists bool
	Info        database.SequenceInfo
}

CreateSequenceStmt represents a parsed CREATE SEQUENCE statement.

func (*CreateSequenceStmt) Run

func (stmt *CreateSequenceStmt) Run(ctx *Context) (*Result, error)

Run the statement in the given transaction. It implements the Statement interface.

type CreateTableStmt

type CreateTableStmt struct {
	IfNotExists bool
	Info        database.TableInfo
}

CreateTableStmt represents a parsed CREATE TABLE statement.

func (*CreateTableStmt) Run

func (stmt *CreateTableStmt) Run(ctx *Context) (*Result, error)

Run runs the Create table statement in the given transaction. It implements the Statement interface.

type DeleteStmt

type DeleteStmt struct {
	PreparedStreamStmt

	TableName        string
	WhereExpr        expr.Expr
	OffsetExpr       expr.Expr
	OrderBy          *expr.Column
	LimitExpr        expr.Expr
	OrderByDirection scanner.Token
}

DeleteConfig holds DELETE configuration.

func (*DeleteStmt) Bind added in v0.17.0

func (stmt *DeleteStmt) Bind(ctx *Context) error

func (*DeleteStmt) Prepare

func (stmt *DeleteStmt) Prepare(c *Context) (Statement, error)

type DropIndexStmt

type DropIndexStmt struct {
	IndexName string
	IfExists  bool
}

DropIndexStmt is a DSL that allows creating a DROP INDEX query.

func (*DropIndexStmt) Bind added in v0.17.0

func (stmt *DropIndexStmt) Bind(ctx *Context) error

func (*DropIndexStmt) IsReadOnly

func (stmt *DropIndexStmt) IsReadOnly() bool

IsReadOnly always returns false. It implements the Statement interface.

func (*DropIndexStmt) Run

func (stmt *DropIndexStmt) Run(ctx *Context) (*Result, error)

Run runs the DropIndex statement in the given transaction. It implements the Statement interface.

type DropSequenceStmt

type DropSequenceStmt struct {
	SequenceName string
	IfExists     bool
}

DropSequenceStmt is a DSL that allows creating a DROP INDEX query.

func (*DropSequenceStmt) Bind added in v0.17.0

func (stmt *DropSequenceStmt) Bind(ctx *Context) error

func (*DropSequenceStmt) IsReadOnly

func (stmt *DropSequenceStmt) IsReadOnly() bool

IsReadOnly always returns false. It implements the Statement interface.

func (*DropSequenceStmt) Run

func (stmt *DropSequenceStmt) Run(ctx *Context) (*Result, error)

Run runs the DropSequence statement in the given transaction. It implements the Statement interface.

type DropTableStmt

type DropTableStmt struct {
	TableName string
	IfExists  bool
}

DropTableStmt is a DSL that allows creating a DROP TABLE query.

func (*DropTableStmt) Bind added in v0.17.0

func (stmt *DropTableStmt) Bind(ctx *Context) error

func (*DropTableStmt) IsReadOnly

func (stmt *DropTableStmt) IsReadOnly() bool

IsReadOnly always returns false. It implements the Statement interface.

func (*DropTableStmt) Run

func (stmt *DropTableStmt) Run(ctx *Context) (*Result, error)

Run runs the DropTable statement in the given transaction. It implements the Statement interface.

type ExplainStmt

type ExplainStmt struct {
	Statement Preparer
}

ExplainStmt is a Statement that displays information about how a statement is going to be executed, without executing it.

func (*ExplainStmt) Bind added in v0.17.0

func (stmt *ExplainStmt) Bind(ctx *Context) error

func (*ExplainStmt) IsReadOnly

func (s *ExplainStmt) IsReadOnly() bool

IsReadOnly indicates that this statement doesn't write anything into the database.

func (*ExplainStmt) Run

func (stmt *ExplainStmt) Run(ctx *Context) (*Result, error)

Run analyses the inner statement and displays its execution plan. If the statement is a stream, Optimize will be called prior to displaying all the operations. Explain currently only works on SELECT, UPDATE, INSERT and DELETE statements.

type InsertStmt

type InsertStmt struct {
	PreparedStreamStmt

	TableName  string
	Values     []expr.Expr
	Columns    []string
	SelectStmt Preparer
	Returning  []expr.Expr
	OnConflict database.OnConflictAction
}

InsertStmt holds INSERT configuration.

func (*InsertStmt) Bind added in v0.17.0

func (stmt *InsertStmt) Bind(ctx *Context) error

func (*InsertStmt) Prepare

func (stmt *InsertStmt) Prepare(c *Context) (Statement, error)

type PreparedStreamStmt

type PreparedStreamStmt struct {
	Stream *stream.Stream
}

PreparedStreamStmt is a PreparedStreamStmt using a Stream.

func (*PreparedStreamStmt) Run

func (s *PreparedStreamStmt) Run(ctx *Context) (*Result, error)

Run returns a result containing the stream. The stream will be executed by calling the Iterate method of the result.

func (*PreparedStreamStmt) String

func (s *PreparedStreamStmt) String() string

type Preparer

type Preparer interface {
	Prepare(*Context) (Statement, error)
}

type ReIndexStmt

type ReIndexStmt struct {
	PreparedStreamStmt

	TableOrIndexName string
}

ReIndexStmt is a DSL that allows creating a full REINDEX statement.

func (*ReIndexStmt) Prepare

func (stmt *ReIndexStmt) Prepare(ctx *Context) (Statement, error)

Prepare implements the Preparer interface.

type ReadOnly added in v0.18.0

type ReadOnly interface {
	IsReadOnly() bool
}

Optional interface that allows a statement to specify if it is read-only. Defaults to false if not implemented.

type Result

type Result struct {
	Result database.Result
	Tx     *database.Transaction
	// contains filtered or unexported fields
}

Result of a query.

func (*Result) Close

func (r *Result) Close() (err error)

Close the result stream. After closing the result, Stream is not supposed to be used. If the result stream was already closed, it returns an error.

func (*Result) Columns added in v0.17.0

func (r *Result) Columns() ([]string, error)

func (*Result) Iterate

func (r *Result) Iterate(fn func(r database.Row) error) (err error)

func (*Result) Iterator

func (r *Result) Iterator() (database.Iterator, error)

func (*Result) Skip added in v0.17.0

func (r *Result) Skip(ctx context.Context) (err error)

Skip iterates over the result and skips all rows. It is useful when you need the query to be executed but don't care about the results.

type SelectCoreStmt

type SelectCoreStmt struct {
	TableName       string
	Distinct        bool
	WhereExpr       expr.Expr
	GroupByExpr     expr.Expr
	ProjectionExprs []expr.Expr
}

func (*SelectCoreStmt) Bind added in v0.17.0

func (stmt *SelectCoreStmt) Bind(ctx *Context) error

func (*SelectCoreStmt) IsReadOnly added in v0.18.0

func (stmt *SelectCoreStmt) IsReadOnly() bool

func (*SelectCoreStmt) Prepare

func (stmt *SelectCoreStmt) Prepare(ctx *Context) (*stream.Stream, error)

type SelectStmt

type SelectStmt struct {
	PreparedStreamStmt

	CompoundSelect    []*SelectCoreStmt
	CompoundOperators []scanner.Token
	OrderBy           *expr.Column
	OrderByDirection  scanner.Token
	OffsetExpr        expr.Expr
	LimitExpr         expr.Expr
}

SelectStmt holds SELECT configuration.

func (*SelectStmt) Bind added in v0.17.0

func (stmt *SelectStmt) Bind(ctx *Context) error

func (*SelectStmt) IsReadOnly

func (stmt *SelectStmt) IsReadOnly() bool

func (*SelectStmt) Prepare

func (stmt *SelectStmt) Prepare(ctx *Context) (Statement, error)

Prepare implements the Preparer interface.

type Statement

type Statement interface {
	Run(*Context) (*Result, error)
}

A Statement represents a unique action that can be executed against the database.

type StreamStmt

type StreamStmt struct {
	Stream   *stream.Stream
	ReadOnly bool
}

StreamStmt is a StreamStmt using a Stream.

type StreamStmtResult added in v0.17.0

type StreamStmtResult struct {
	Stream  *stream.Stream
	Context *Context
}

StreamStmtResult iterates over a stream.

func (*StreamStmtResult) Iterator added in v0.17.0

func (s *StreamStmtResult) Iterator() (database.Iterator, error)

type Transactional added in v0.18.0

type Transactional interface {
	NeedsTransaction() bool
}

Optional interface that allows a statement to specify if they need a transaction. Defaults to true if not implemented. If true, the engine will auto-commit.

type UpdateSetPair

type UpdateSetPair struct {
	Column *expr.Column
	E      expr.Expr
}

type UpdateStmt

type UpdateStmt struct {
	PreparedStreamStmt

	TableName string

	// SetPairs is used along with the Set clause. It holds
	// each column with its corresponding value that
	// should be set in the row.
	SetPairs []UpdateSetPair

	WhereExpr expr.Expr
}

UpdateConfig holds UPDATE configuration.

func (*UpdateStmt) Bind added in v0.17.0

func (stmt *UpdateStmt) Bind(ctx *Context) error

func (*UpdateStmt) Prepare

func (stmt *UpdateStmt) Prepare(c *Context) (Statement, error)

Prepare implements the Preparer interface.

Jump to

Keyboard shortcuts

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