Documentation
¶
Overview ¶
The store plugin module, implemented against the plugin SDK (pkg/plugin). The same implementation serves both builds: compiled into the OpenRun binary as "store.in" (registered below as a local provider), and as the out-of-process provider executable in ./storeprovider (loadable as "store.ex", or "store.in" in a binary without the compiled-in module).
Index ¶
- Constants
- Variables
- func CreateType(name string, entry *Entry) (*starlark_type.StarlarkType, error)
- func NewStoreModule() plugin.Module
- func ProviderConfig(version string) *plugin.ServeConfig
- type Document
- type Entry
- type EntryId
- type EntryIterator
- type SqlStore
- func (s *SqlStore) Begin(ctx context.Context) (*sql.Tx, error)
- func (s *SqlStore) Commit(ctx context.Context, tx *sql.Tx) error
- func (s *SqlStore) Count(ctx context.Context, tx *sql.Tx, table string, filter map[string]any) (int64, error)
- func (s *SqlStore) Delete(ctx context.Context, tx *sql.Tx, table string, filter map[string]any) (int64, error)
- func (s *SqlStore) DeleteById(ctx context.Context, tx *sql.Tx, table string, id EntryId) (int64, error)
- func (s *SqlStore) Insert(ctx context.Context, tx *sql.Tx, table string, entry *Entry) (EntryId, error)
- func (s *SqlStore) Rollback(ctx context.Context, tx *sql.Tx) error
- func (s *SqlStore) Select(ctx context.Context, tx *sql.Tx, thread *starlark.Thread, table string, ...) (starlark.Iterable, error)
- func (s *SqlStore) SelectById(ctx context.Context, tx *sql.Tx, table string, id EntryId) (*Entry, error)
- func (s *SqlStore) SelectEntries(ctx context.Context, tx *sql.Tx, table string, filter map[string]any, ...) (*EntryIterator, error)
- func (s *SqlStore) SelectOne(ctx context.Context, tx *sql.Tx, table string, filter map[string]any) (*Entry, error)
- func (s *SqlStore) Update(ctx context.Context, tx *sql.Tx, table string, entry *Entry) (int64, error)
- type Store
- type StoreEntryIterable
- type StoreEntryIterator
- type UserId
Constants ¶
const ( AND_CONDITION = "$AND" OR_CONDITION = "$OR" )
const ( SELECT_MAX_LIMIT = 100_000 SELECT_DEFAULT_LIMIT = 10_000 SORT_ASCENDING = "asc" SORT_DESCENDING = "desc" MAX_TABLE_NAME_LEN = 63 )
const ( ID_FIELD = "_id" VERSION_FIELD = "_version" CREATED_BY_FIELD = "_created_by" UPDATED_BY_FIELD = "_updated_by" CREATED_AT_FIELD = "_created_at" UPDATED_AT_FIELD = "_updated_at" JSON_FIELD = "_json" )
const TRANSACTION_KEY = "transaction"
Variables ¶
var RESERVED_FIELDS = map[string]bool{ ID_FIELD: true, VERSION_FIELD: true, CREATED_BY_FIELD: true, UPDATED_BY_FIELD: true, CREATED_AT_FIELD: true, UPDATED_AT_FIELD: true, JSON_FIELD: true, }
Functions ¶
func CreateType ¶
func CreateType(name string, entry *Entry) (*starlark_type.StarlarkType, error)
func NewStoreModule ¶ added in v0.19.0
func ProviderConfig ¶ added in v0.19.0
func ProviderConfig(version string) *plugin.ServeConfig
ProviderConfig returns the store plugin's provider config, shared by the compiled-in registration above and the storeprovider executable.
Types ¶
type Entry ¶
type EntryIterator ¶ added in v0.19.0
type EntryIterator struct {
// contains filtered or unexported fields
}
EntryIterator lazily iterates the rows of a select, converting each row to an Entry. It is starlark-free so the external store provider can stream results through it.
func (*EntryIterator) Close ¶ added in v0.19.0
func (it *EntryIterator) Close() error
Close releases the underlying cursor. Safe to call after exhaustion.
func (*EntryIterator) LeakKey ¶ added in v0.19.0
func (it *EntryIterator) LeakKey() string
LeakKey names the strict deferred-cleanup entry registered for this iterator: if the app never consumes or closes the cursor, the request fails citing this key.
func (*EntryIterator) Next ¶ added in v0.19.0
func (it *EntryIterator) Next() (*Entry, bool, error)
Next returns the next entry, or ok=false when the rows are exhausted (the underlying cursor is closed implicitly then). A scan error closes the cursor and is returned.
func (*EntryIterator) Table ¶ added in v0.19.0
func (it *EntryIterator) Table() string
Table returns the physical table name the iterator reads from.
type SqlStore ¶
func NewSqlStore ¶
func NewSqlStore(pluginContext *types.PluginContext) (*SqlStore, error)
func (*SqlStore) Count ¶
func (s *SqlStore) Count(ctx context.Context, tx *sql.Tx, table string, filter map[string]any) (int64, error)
Count returns the number of entries matching the filter
func (*SqlStore) Delete ¶
func (s *SqlStore) Delete(ctx context.Context, tx *sql.Tx, table string, filter map[string]any) (int64, error)
Delete entries from the store matching the filter
func (*SqlStore) DeleteById ¶
func (s *SqlStore) DeleteById(ctx context.Context, tx *sql.Tx, table string, id EntryId) (int64, error)
DeleteById an entry from the store by id
func (*SqlStore) Insert ¶
func (s *SqlStore) Insert(ctx context.Context, tx *sql.Tx, table string, entry *Entry) (EntryId, error)
Insert a new entry in the store
func (*SqlStore) Select ¶
func (s *SqlStore) Select(ctx context.Context, tx *sql.Tx, thread *starlark.Thread, table string, filter map[string]any, sort []string, offset, limit int64) (starlark.Iterable, error)
Select returns the entries matching the filter
func (*SqlStore) SelectById ¶
func (s *SqlStore) SelectById(ctx context.Context, tx *sql.Tx, table string, id EntryId) (*Entry, error)
SelectById returns a single item from the store
func (*SqlStore) SelectEntries ¶ added in v0.19.0
func (s *SqlStore) SelectEntries(ctx context.Context, tx *sql.Tx, table string, filter map[string]any, sort []string, offset, limit int64) (*EntryIterator, error)
SelectEntries runs a select and returns a Go-level lazy iterator over the matching entries. This is the starlark-free core beneath Select, shared with the external store plugin provider; the caller owns closing the iterator (or fully draining it, which closes it implicitly).
type Store ¶
type Store interface {
// Begin starts a new transaction
Begin(ctx context.Context) (*sql.Tx, error)
// Commit commits a transaction
Commit(ctx context.Context, tx *sql.Tx) error
// Rollback rolls back a transaction
Rollback(ctx context.Context, tx *sql.Tx) error
// Insert a new entry in the store
Insert(ctx context.Context, tx *sql.Tx, table string, Entry *Entry) (EntryId, error)
// SelectById returns a single item from the store
SelectById(ctx context.Context, tx *sql.Tx, table string, id EntryId) (*Entry, error)
// SelectOne returns a single item from the store
SelectOne(ctx context.Context, tx *sql.Tx, table string, filter map[string]any) (*Entry, error)
// Select returns the entries matching the filter
Select(ctx context.Context, tx *sql.Tx, thread *starlark.Thread, table string, filter map[string]any, sort []string, offset, limit int64) (starlark.Iterable, error)
// Count returns the count of entries matching the filter
Count(ctx context.Context, tx *sql.Tx, table string, filter map[string]any) (int64, error)
// Update an existing entry in the store
Update(ctx context.Context, tx *sql.Tx, table string, Entry *Entry) (int64, error)
// DeleteById an entry from the store by id
DeleteById(ctx context.Context, tx *sql.Tx, table string, id EntryId) (int64, error)
// Delete entries from the store matching the filter
Delete(ctx context.Context, tx *sql.Tx, table string, filter map[string]any) (int64, error)
}
Store is the interface for a OpenRun document store. These API are exposed by the db plugin
type StoreEntryIterable ¶
func NewStoreEntryIterabe ¶
func NewStoreEntryIterabe(thread *starlark.Thread, logger *types.Logger, modulePath, table string, iterator *EntryIterator) *StoreEntryIterable
func (*StoreEntryIterable) Freeze ¶
func (s *StoreEntryIterable) Freeze()
func (*StoreEntryIterable) Hash ¶
func (s *StoreEntryIterable) Hash() (uint32, error)
func (*StoreEntryIterable) Iterate ¶
func (s *StoreEntryIterable) Iterate() starlark.Iterator
func (*StoreEntryIterable) String ¶
func (s *StoreEntryIterable) String() string
func (*StoreEntryIterable) Truth ¶
func (s *StoreEntryIterable) Truth() starlark.Bool
func (*StoreEntryIterable) Type ¶
func (s *StoreEntryIterable) Type() string
type StoreEntryIterator ¶
func NewStoreEntryIterator ¶
func NewStoreEntryIterator(thread *starlark.Thread, logger *types.Logger, modulePath, table string, iterator *EntryIterator) *StoreEntryIterator
func (*StoreEntryIterator) Done ¶
func (i *StoreEntryIterator) Done()
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Command storeprovider is the out-of-process provider build of the store plugin: the same module implementation that is compiled into OpenRun as "store.in" (internal/app/store), served as an external provider.
|
Command storeprovider is the out-of-process provider build of the store plugin: the same module implementation that is compiled into OpenRun as "store.in" (internal/app/store), served as an external provider. |