store

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AND_CONDITION = "$AND"
	OR_CONDITION  = "$OR"
)
View Source
const (
	DB_CONNECTION_CONFIG = "db_connection"
	SELECT_MAX_LIMIT     = 100_000
	SELECT_DEFAULT_LIMIT = 10_000
	SORT_ASCENDING       = "asc"
	SORT_DESCENDING      = "desc"
)
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) (*utils.StarlarkType, error)

func NewStorePlugin

func NewStorePlugin(pluginContext *utils.PluginContext) (any, error)

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 SqlStore

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

func NewSqlStore

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

func (*SqlStore) Begin added in v0.4.1

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

func (*SqlStore) Commit added in v0.4.1

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 added in v0.4.1

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) 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 Clace document store. These API are exposed by the db plugin

type StoreEntryIterable

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

func NewStoreEntryIterabe

func NewStoreEntryIterabe(thread *starlark.Thread, logger *utils.Logger, table string, rows *sql.Rows) *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 {
	*utils.Logger
	// contains filtered or unexported fields
}

func NewStoreEntryIterator

func NewStoreEntryIterator(thread *starlark.Thread, logger *utils.Logger, table string, rows *sql.Rows) *StoreEntryIterator

func (*StoreEntryIterator) Done

func (i *StoreEntryIterator) Done()

func (*StoreEntryIterator) Next

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

type UserId

type UserId string

Jump to

Keyboard shortcuts

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