store

package
v0.19.1 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

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

View Source
const (
	AND_CONDITION = "$AND"
	OR_CONDITION  = "$OR"
)
View Source
const (
	SELECT_MAX_LIMIT     = 100_000
	SELECT_DEFAULT_LIMIT = 10_000
	SORT_ASCENDING       = "asc"
	SORT_DESCENDING      = "desc"
	MAX_TABLE_NAME_LEN   = 63
)
View Source
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"
)
View Source
const TRANSACTION_KEY = "transaction"

Variables

Functions

func CreateType

func CreateType(name string, entry *Entry) (*starlark_type.StarlarkType, error)

func NewStoreModule added in v0.19.0

func NewStoreModule() plugin.Module

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 Document

type Document map[string]any

type Entry

type Entry struct {
	Id        EntryId
	Version   int64
	CreatedBy UserId
	UpdatedBy UserId
	CreatedAt time.Time
	UpdatedAt time.Time
	Data      Document
}

func (*Entry) Unpack

func (e *Entry) Unpack(value starlark.Value) error

type EntryId

type EntryId int64

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

type SqlStore struct {
	*types.Logger
	sync.Mutex
	// contains filtered or unexported fields
}

func NewSqlStore

func NewSqlStore(pluginContext *types.PluginContext) (*SqlStore, error)

func (*SqlStore) Begin

func (s *SqlStore) Begin(ctx context.Context) (*sql.Tx, error)

func (*SqlStore) Commit

func (s *SqlStore) Commit(ctx context.Context, tx *sql.Tx) 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) Rollback

func (s *SqlStore) Rollback(ctx context.Context, tx *sql.Tx) error

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).

func (*SqlStore) SelectOne

func (s *SqlStore) SelectOne(ctx context.Context, tx *sql.Tx, table string, filter map[string]any) (*Entry, error)

SelectOne returns a single item from the store

func (*SqlStore) Update

func (s *SqlStore) Update(ctx context.Context, tx *sql.Tx, table string, entry *Entry) (int64, error)

Update an existing entry in the store

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

type StoreEntryIterable struct {
	*types.Logger
	// contains filtered or unexported fields
}

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

type StoreEntryIterator struct {
	*types.Logger
	// contains filtered or unexported fields
}

func NewStoreEntryIterator

func NewStoreEntryIterator(thread *starlark.Thread, logger *types.Logger, modulePath, table string, iterator *EntryIterator) *StoreEntryIterator

func (*StoreEntryIterator) Done

func (i *StoreEntryIterator) Done()

func (*StoreEntryIterator) Next

func (i *StoreEntryIterator) Next(value *starlark.Value) bool

type UserId

type UserId string

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.

Jump to

Keyboard shortcuts

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