Documentation ¶
Index ¶
- Variables
- type AndOp
- type Cast
- type CmpOp
- type CreateIndexStmt
- type CreateTableStmt
- type DeleteStmt
- type DropIndexStmt
- type DropTableStmt
- type EvalStack
- type Expr
- type FieldSelector
- type InsertStmt
- type KVPair
- type KVPairs
- type LiteralExprList
- type LiteralValue
- func BlobValue(v []byte) LiteralValue
- func BoolValue(v bool) LiteralValue
- func DocumentValue(d document.Document) LiteralValue
- func DurationValue(v time.Duration) LiteralValue
- func Float64Value(v float64) LiteralValue
- func IntValue(v int) LiteralValue
- func NullValue() LiteralValue
- func TextValue(v string) LiteralValue
- type NamedParam
- type OrOp
- type PKFunc
- type PositionalParam
- type Query
- type Result
- type ResultField
- type ResultFieldExpr
- type SelectStmt
- type Statement
- type UpdateStmt
- type Wildcard
Constants ¶
This section is empty.
Variables ¶
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 AndOp ¶
type AndOp struct {
// contains filtered or unexported fields
}
AndOp is the And operator.
func (*AndOp) Eval ¶
Eval implements the Expr interface. It evaluates a and b and returns true if both evalutate to true.
func (AndOp) Precedence ¶
func (op AndOp) Precedence() int
func (AndOp) SetLeftHandExpr ¶
func (op AndOp) SetLeftHandExpr(a Expr)
func (AndOp) SetRightHandExpr ¶
func (op AndOp) SetRightHandExpr(b Expr)
type Cast ¶ added in v0.5.0
Cast represents the CAST expression. It returns the primary key of the current document.
type CmpOp ¶
type CmpOp struct {
// contains filtered or unexported fields
}
A CmpOp is a comparison operator.
func (CmpOp) Eval ¶
Eval compares a and b together using the operator specified when constructing the CmpOp and returns the result of the comparison.
func (CmpOp) Precedence ¶
func (op CmpOp) Precedence() int
func (CmpOp) SetLeftHandExpr ¶
func (op CmpOp) SetLeftHandExpr(a Expr)
func (CmpOp) SetRightHandExpr ¶
func (op CmpOp) SetRightHandExpr(b Expr)
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 []driver.NamedValue) (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 []driver.NamedValue) (Result, error)
Run runs the Create table statement in the given transaction. It implements the Statement interface.
type DeleteStmt ¶
DeleteStmt is a DSL that allows creating a full Delete query.
func (DeleteStmt) IsReadOnly ¶
func (stmt DeleteStmt) IsReadOnly() bool
IsReadOnly always returns false. It implements the Statement interface.
func (DeleteStmt) Run ¶
func (stmt DeleteStmt) Run(tx *database.Transaction, args []driver.NamedValue) (Result, error)
Run deletes matching documents by batches of deleteBufferSize documents. Some engines can't iterate while deleting keys (https://github.com/etcd-io/bbolt/issues/146) and some can't create more than one iterator per read-write transaction (https://github.com/dgraph-io/badger/issues/1093). To deal with these limitations, Run will iterate on a limited number of documents, copy the keys to a buffer and delete them after the iteration is complete, and it will do that until there is no document left to delete. Increasing deleteBufferSize will occasionate less key searches (O(log n) for most engines) but will take more memory.
type DropIndexStmt ¶
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 []driver.NamedValue) (Result, error)
Run runs the DropIndex statement in the given transaction. It implements the Statement interface.
type DropTableStmt ¶
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 []driver.NamedValue) (Result, error)
Run runs the DropTable statement in the given transaction. It implements the Statement interface.
type EvalStack ¶
type EvalStack struct { Tx *database.Transaction Document document.Document Params []driver.NamedValue Cfg *database.TableConfig }
EvalStack contains information about the context in which the expression is evaluated. Any of the members can be nil except the transaction.
type Expr ¶
An Expr evaluates to a value.
func BitwiseAnd ¶ added in v0.5.0
BitwiseAnd creates an expression thats evaluates to the result of a & b.
func BitwiseOr ¶ added in v0.5.0
BitwiseOr creates an expression thats evaluates to the result of a & b.
func BitwiseXor ¶ added in v0.5.0
BitwiseXor creates an expression thats evaluates to the result of a & b.
type FieldSelector ¶
type FieldSelector []string
A FieldSelector is a ResultField that extracts a field from a document at a given path.
func (FieldSelector) Eval ¶
func (f FieldSelector) Eval(stack EvalStack) (document.Value, error)
Eval extracts the document from the context and selects the right field. It implements the Expr interface.
func (FieldSelector) Name ¶
func (f FieldSelector) Name() string
Name joins the chunks of the fields selector with the . separator.
type InsertStmt ¶
type InsertStmt struct { TableName string FieldNames []string Values 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 []driver.NamedValue) (Result, error)
Run the Insert statement in the given transaction. It implements the Statement interface.
type LiteralValue ¶
A LiteralValue represents a litteral value of any type defined by the value package.
func BlobValue ¶ added in v0.5.0
func BlobValue(v []byte) LiteralValue
BlobValue creates a litteral value of type Blob.
func BoolValue ¶
func BoolValue(v bool) LiteralValue
BoolValue creates a litteral value of type Bool.
func DocumentValue ¶
func DocumentValue(d document.Document) LiteralValue
DocumentValue creates a litteral value of type Document.
func DurationValue ¶ added in v0.5.0
func DurationValue(v time.Duration) LiteralValue
DurationValue creates a litteral value of type Duration.
func Float64Value ¶
func Float64Value(v float64) LiteralValue
Float64Value creates a litteral value of type Float64.
func TextValue ¶ added in v0.5.0
func TextValue(v string) LiteralValue
TextValue creates a litteral value of type Text.
type NamedParam ¶
type NamedParam string
NamedParam is an expression which represents the name of a parameter.
type OrOp ¶
type OrOp struct {
// contains filtered or unexported fields
}
OrOp is the And operator.
func (*OrOp) Eval ¶
Eval implements the Expr interface. It evaluates a and b and returns true if a or b evalutate to true.
func (OrOp) Precedence ¶
func (op OrOp) Precedence() int
func (OrOp) SetLeftHandExpr ¶
func (op OrOp) SetLeftHandExpr(a Expr)
func (OrOp) SetRightHandExpr ¶
func (op OrOp) SetRightHandExpr(b Expr)
type PKFunc ¶ added in v0.5.0
type PKFunc struct{}
PKFunc represents the pk() function. It returns the primary key of the current document.
type PositionalParam ¶
type PositionalParam int
PositionalParam is an expression which represents the position of a parameter.
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 (Query) Exec ¶
func (q Query) Exec(tx *database.Transaction, args []driver.NamedValue, 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.
type Result ¶
Result of a query.
func (*Result) Close ¶
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.
func (Result) LastInsertId ¶
LastInsertId is not supported and returns an error. Use LastInsertKey instead.
func (Result) LastInsertKey ¶
LastInsertKey returns the database's auto-generated key after, for example, an INSERT into a table with primary key.
func (Result) RowsAffected ¶
RowsAffected returns the number of rows affected by the query.
type ResultField ¶
type ResultField interface { Iterate(stack EvalStack, fn func(field string, value document.Value) error) error Name() string }
A ResultField is a field that will be part of the result document that will be returned at the end of a Select statement.
type ResultFieldExpr ¶ added in v0.5.0
ResultFieldExpr turns any expression into a ResultField.
func (ResultFieldExpr) Iterate ¶ added in v0.5.0
func (r ResultFieldExpr) Iterate(stack EvalStack, fn func(field string, value document.Value) error) error
Iterate evaluates Expr and calls fn once with the result.
func (ResultFieldExpr) Name ¶ added in v0.5.0
func (r ResultFieldExpr) Name() string
Name returns the raw expression.
type SelectStmt ¶
type SelectStmt struct { TableName string WhereExpr Expr OrderBy FieldSelector OrderByDirection scanner.Token OffsetExpr Expr LimitExpr Expr Selectors []ResultField }
SelectStmt is a DSL that allows creating a full Select query.
func (SelectStmt) IsReadOnly ¶
func (stmt SelectStmt) IsReadOnly() bool
IsReadOnly always returns true. It implements the Statement interface.
func (SelectStmt) Run ¶
func (stmt SelectStmt) Run(tx *database.Transaction, args []driver.NamedValue) (Result, error)
Run the Select statement in the given transaction. It implements the Statement interface.
type Statement ¶
type Statement interface { Run(*database.Transaction, []driver.NamedValue) (Result, error) IsReadOnly() bool }
A Statement represents a unique action that can be executed against the database.
type UpdateStmt ¶
UpdateStmt is a DSL that allows creating a full Update query.
func (UpdateStmt) IsReadOnly ¶
func (stmt UpdateStmt) IsReadOnly() bool
IsReadOnly always returns false. It implements the Statement interface.
func (UpdateStmt) Run ¶
func (stmt UpdateStmt) Run(tx *database.Transaction, args []driver.NamedValue) (Result, error)
Run runs the Update table statement in the given transaction. It implements the Statement interface.