query

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrResultClosed = errors.New("result already closed")

ErrResultClosed is returned when trying to close an already closed result.

Functions

This section is empty.

Types

type CreateIndexStmt

type CreateIndexStmt struct {
	IndexName   string
	TableName   string
	Path        document.ValuePath
	IfNotExists bool
	Unique      bool
}

CreateIndexStmt is a DSL that allows creating a full CREATE INDEX statement. It is typically created using the CreateIndex function.

func (CreateIndexStmt) IsReadOnly

func (stmt CreateIndexStmt) IsReadOnly() bool

IsReadOnly always returns false. It implements the Statement interface.

func (CreateIndexStmt) Run

func (stmt CreateIndexStmt) Run(tx *database.Transaction, args []expr.Param) (Result, error)

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

type CreateTableStmt

type CreateTableStmt struct {
	TableName   string
	IfNotExists bool
	Config      database.TableConfig
}

CreateTableStmt is a DSL that allows creating a full CREATE TABLE statement.

func (CreateTableStmt) IsReadOnly

func (stmt CreateTableStmt) IsReadOnly() bool

IsReadOnly always returns false. It implements the Statement interface.

func (CreateTableStmt) Run

func (stmt CreateTableStmt) Run(tx *database.Transaction, args []expr.Param) (Result, error)

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

type DropIndexStmt

type DropIndexStmt struct {
	IndexName string
	IfExists  bool
}

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

func (DropIndexStmt) IsReadOnly

func (stmt DropIndexStmt) IsReadOnly() bool

IsReadOnly always returns false. It implements the Statement interface.

func (DropIndexStmt) Run

func (stmt DropIndexStmt) Run(tx *database.Transaction, args []expr.Param) (Result, error)

Run runs the DropIndex 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) IsReadOnly

func (stmt DropTableStmt) IsReadOnly() bool

IsReadOnly always returns false. It implements the Statement interface.

func (DropTableStmt) Run

func (stmt DropTableStmt) Run(tx *database.Transaction, args []expr.Param) (Result, error)

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

type InsertStmt

type InsertStmt struct {
	TableName  string
	FieldNames []string
	Values     expr.LiteralExprList
}

InsertStmt is a DSL that allows creating a full Insert query.

func (InsertStmt) IsReadOnly

func (stmt InsertStmt) IsReadOnly() bool

IsReadOnly always returns false. It implements the Statement interface.

func (InsertStmt) Run

func (stmt InsertStmt) Run(tx *database.Transaction, args []expr.Param) (Result, error)

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

type Query

type Query struct {
	Statements []Statement
}

A Query can execute statements against the database. It can read or write data from any table, or even alter the structure of the database. Results are returned as streams.

func New

func New(statements ...Statement) Query

New creates a new query with the given statements.

func (Query) Exec

func (q Query) Exec(tx *database.Transaction, args []expr.Param, forceReadOnly bool) (*Result, error)

Exec the query within the given transaction. If the one of the statements requires a read-write transaction and tx is not, tx will get promoted.

func (Query) Run

func (q Query) Run(db *database.Database, args []expr.Param) (*Result, error)

Run executes all the statements in their own transaction and returns the last result.

type Result

type Result struct {
	document.Stream
	RowsAffected  int64
	LastInsertKey []byte
	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 ErrResultClosed.

type Statement

type Statement interface {
	Run(*database.Transaction, []expr.Param) (Result, error)
	IsReadOnly() bool
}

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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