Documentation
¶
Index ¶
- Constants
- Variables
- func FromProtoValue(v *sqlitepb.Value) interface{}
- func RegisterSqliteWorker(r worker.WorkflowRegistry, opts SqliteWorkerOptions)
- func StmtsToProto(stmts []*Stmt) (*sqlitepb.StmtRequest, error)
- func ToProtoValue(v interface{}) (*sqlitepb.Value, error)
- type Client
- func (c *Client) Close()
- func (c *Client) Exec(ctx context.Context, stmts ...*Stmt) ([]*StmtResult, error)
- func (c *Client) ExecMulti(ctx context.Context, multiSQL string) ([]*StmtResultSuccess, error)
- func (c *Client) ExecSimple(ctx context.Context, sql string, args ...interface{}) (*StmtResultSuccess, error)
- func (c *Client) GetRun(ctx context.Context) (sqlitepb.SqliteRun, error)
- func (c *Client) Query(ctx context.Context, stmts ...*Stmt) ([]*StmtResult, error)
- func (c *Client) QueryMulti(ctx context.Context, multiSQL string) ([]*StmtResultSuccess, error)
- func (c *Client) QuerySimple(ctx context.Context, sql string, args ...interface{}) (*StmtResultSuccess, error)
- func (c *Client) Serialize(ctx context.Context) ([]byte, error)
- func (c *Client) StopDB(ctx context.Context) error
- func (c *Client) Update(ctx context.Context, stmts ...*Stmt) error
- func (c *Client) UpdateMulti(ctx context.Context, multiSQL string) error
- func (c *Client) UpdateSimple(ctx context.Context, sql string, args ...interface{}) error
- type ConnectDBOptions
- type SqliteWorkerOptions
- type Stmt
- type StmtResult
- type StmtResultError
- type StmtResultSuccess
Constants ¶
const DefaultRequestsUntilContinueAsNew = 5000
DefaultRequestsUntilContinueAsNew is the default for SqliteWorkerOptions.DefaultRequestsUntilContinueAsNew.
Variables ¶
var DefaultNonDeterministicFuncs = map[string]bool{ "current_date": true, "current_time": true, "current_timestamp": true, "random": true, "random_blob": true, }
DefaultNonDeterministicFuncs is the default set of functions disallowed due to inherit non-determinism.
Functions ¶
func FromProtoValue ¶
FromProtoValue converts the given protobuf value to a Go value. This will return nil, int64, float64, string, or bytes.
func RegisterSqliteWorker ¶
func RegisterSqliteWorker(r worker.WorkflowRegistry, opts SqliteWorkerOptions)
RegisterSqliteWorker registers the SQLite workflow with the given registry.
func StmtsToProto ¶
func StmtsToProto(stmts []*Stmt) (*sqlitepb.StmtRequest, error)
StmtsToProto converts these statements to a protobuf request.
func ToProtoValue ¶
ToProtoValue converts a single Go value to a protobuf value. The value must be nil, bool, integer, float, string, byte slice, or a pointer to any of those.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a client for a DB workflow.
func ConnectDB ¶
ConnectDB starts the DB workflow with the given opts.StartWorkflow.ID unless it already exists and then uses NewClient to return a client. This means the default opts.StartWorkflow.WorkflowIDReusePolicy is WORKFLOW_ID_REUSE_POLICY_REJECT_DUPLICATE if otherwise unset. Callers may want to change this to WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE_FAILED_ONLY to support restarting a failed DB workflow.
func NewClient ¶
NewClient references an existing DB by its workflow ID. Use ConnectDB to potentially start the DB if it doesn't already exist. This also internally starts a worker for handling "Exec" responses and therefore Close should be called by the caller.
func (*Client) Exec ¶
Exec sends an exec signal to the workflow and waits for the response to be reported as an activity.
Since this uses a signal, it cannot be executed on a stopped database.
func (*Client) ExecSimple ¶
func (c *Client) ExecSimple(ctx context.Context, sql string, args ...interface{}) (*StmtResultSuccess, error)
ExecSimple is a convenience shortcut for Exec.
func (*Client) Query ¶
Query sends a read-only query to the workflow. This query must be read-only or it will fail.
Since this uses a query, it can be executed even if the database is stopped.
NOTE: Currently there are rare racy cases where a query can fail when sent while it is restarting (i.e. performing continue-as-new). See https://github.com/temporalio/sdk-go/issues/475 which is waiting on https://github.com/temporalio/temporal/issues/2300.
func (*Client) QueryMulti ¶
QueryMulti is a convenience shortcut for Query.
func (*Client) QuerySimple ¶
func (c *Client) QuerySimple(ctx context.Context, sql string, args ...interface{}) (*StmtResultSuccess, error)
QuerySimple is a convenience shortcut for Query.
func (*Client) Serialize ¶
Serialize sends a query to return a LZ4-compressed set of bytes generated via https://www.sqlite.org/c3ref/serialize.html.
Since this uses a query, it can be executed even if the database is stopped.
func (*Client) Update ¶
Update sends an update signal to the workflow. This returns no response and there is generally no way to know if it succeeded. By default, if this query fails, the entire workflow fails. Most callers may prefer Exec or Query instead.
Since this uses a signal, it cannot be executed on a stopped database.
func (*Client) UpdateMulti ¶
UpdateMulti is a convenience shortcut for Update.
type ConnectDBOptions ¶
type ConnectDBOptions struct { // Workflow start options. This should have ID and TaskQueue always set. StartWorkflow client.StartWorkflowOptions // Optional SQLite workflow configuration. Sqlite *sqlitepb.SqliteOptions }
ConnectDBOptions are options for ConnectDB.
type SqliteWorkerOptions ¶
type SqliteWorkerOptions struct { // Compression options for serialization. CompressionOptions []lz4.Option // Number of requests until a continue-as-new is used to serialize and restart // the workflow. This value is only used if not set in workflow params. // Default is DefaultRequestsUntilContinueAsNew. DefaultRequestsUntilContinueAsNew int // If true, all queries and their successes are logged at debug level. LogQueries bool // If true, all actions of each query are logged at debug level. LogActions bool // Called with the raw SQLite connection to allow custom initialization. InitializeSqlite func(*sqlite.Conn) error // Set of non-deterministic functions to disallow execution of. Should be all // lowercase. If empty, default is DefaultNonDeterministicFuncs. NonDeterministicFuncs map[string]bool // If true, errors from signal-based updates do not fail the workflow. IgnoreUpdateErrors bool }
SqliteWorkerOptions are options for RegisterSqliteWorker. All values are optional.
type Stmt ¶
type Stmt struct { Query string // Param indexes start at 1. Values can be null, bool, integer, float, string, // byte slice, or pointer to any of those. IndexedParams map[int]interface{} NamedParams map[string]interface{} // If true, Query can contain multiple semicolon-delimited queries. The // statement cannot have any parameters set if this value true. If false, // Query can only contain a single query. Multi bool }
Stmt represents a statement used by clients.
func NewMultiStmt ¶
NewMultiStmt creates a new multi-query statement.
func NewSingleStmt ¶
NewSingleStmt creates a new single-query statement with the given indexed params.
type StmtResult ¶
type StmtResult struct { // All successes that occurred. This will only contain the successes up until // the first error. This only has multiple values if Stmt.Multi was true. Successes []*StmtResultSuccess // The first error encountered (and last error since an error stops // execution). Error *StmtResultError }
StmtResult represents a result of a client statement.
func StmtResultsFromProto ¶
func StmtResultsFromProto(res *sqlitepb.StmtResponse) []*StmtResult
StmtResultsFromProto converts the given protobuf response to statement results.
func (*StmtResult) FromProto ¶
func (s *StmtResult) FromProto(res *sqlitepb.StmtResult)
FromProto converts the given protobuf result to this value.
type StmtResultError ¶
StmtResultError represents an error from a statement.
func (*StmtResultError) Error ¶
func (s *StmtResultError) Error() string
Error implements error.Error.
type StmtResultSuccess ¶
type StmtResultSuccess struct { // Column names for the query result. ColumnNames []string // Values can be nil, int64, float64, string, or bytes. Rows [][]interface{} }
StmtResultSuccess represents a single query success (of which a statement can have multiple).