pisces

package module
v0.0.0-...-2ca223a Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2022 License: AGPL-3.0 Imports: 10 Imported by: 2

Documentation

Index

Constants

View Source
const MaxKVClassLen = 255

MaxKVClassLen is the maximum length of the class string of a hashed KV.

View Source
const MaxKVKeyLen = 255

MaxKVKeyLen is the maximum key length of ordered key-value pair storage.

View Source
const MaxKeyLen = 255

MaxKeyLen is the maximum length of a hashed KV.

Variables

View Source
var ErrCancel = errors.New("operation cancelled")

ErrCancel is the error when the operation is canclled.

View Source
var ErrUnordered = errors.New("the index is unordered")

ErrUnordered is the error when an ordered table operation is operated on an unordered table.

Functions

func PsqlCreateKV

func PsqlCreateKV(db *sqlx.DB, table string) error

PsqlCreateKV creates a key value pair postgres table.

func PsqlCreateKVMissing

func PsqlCreateKVMissing(db *sqlx.DB, table string) error

PsqlCreateKVMissing creates a key value pair postgres table if the table does not exist.

func PsqlCreateTable

func PsqlCreateTable(db *sqlx.DB, table, scheme string) error

PsqlCreateTable creates a postgres table for the given table name and scheme.

func PsqlCreateTableMissing

func PsqlCreateTableMissing(db *sqlx.DB, table, scheme string) error

PsqlCreateTableMissing creates a postgres table if it does not exist, using the given table name and scheme.

func PsqlDrop

func PsqlDrop(db *sqlx.DB, table string) error

PsqlDrop destroys the specific postgres table.

func PsqlDropExist

func PsqlDropExist(db *sqlx.DB, table string) error

PsqlDropExist destroys the table if the table exists. It does nothing if the table does not exist.

func Sqlite3CreateKV

func Sqlite3CreateKV(db *sqlx.DB, table string) error

Sqlite3CreateKV creates a key value pair sqlite3 table.

func Sqlite3CreateKVMissing

func Sqlite3CreateKVMissing(db *sqlx.DB, table string) error

Sqlite3CreateKVMissing creates a key value pair sqlite3 table if the table does not exist.

func Sqlite3CreateTable

func Sqlite3CreateTable(db *sqlx.DB, table, scheme string) error

Sqlite3CreateTable creates a table for the given table for the given table name and scheme.

func Sqlite3CreateTableMissing

func Sqlite3CreateTableMissing(db *sqlx.DB, table, scheme string) error

Sqlite3CreateTableMissing creates a postgres table if it does not exist, using the given table name and scheme.

func Sqlite3Drop

func Sqlite3Drop(db *sqlx.DB, table string) error

Sqlite3Drop destroys the specific sqlite3 table.

func Sqlite3DropExist

func Sqlite3DropExist(db *sqlx.DB, table string) error

Sqlite3DropExist destroys the table if the table exists. It does nothing if the table does not exist.

Types

type Iter

type Iter struct {
	Make func() interface{}
	Do   func(cls string, v interface{}) error
}

Iter is an interator.

type KV

type KV struct {
	// contains filtered or unexported fields
}

KV provides a key-value pair table.

func NewMemKV

func NewMemKV() *KV

NewMemKV creates a new key-value pair in memory.

func NewOrderedMemKV

func NewOrderedMemKV() *KV

NewOrderedMemKV creates a new ordered key-value pair in memory.

func NewOrderedPsqlKV

func NewOrderedPsqlKV(db *sqlx.DB, table string) *KV

NewOrderedPsqlKV creates a new postgresql backed ordered key-value pair storage.

func NewOrderedSqlite3KV

func NewOrderedSqlite3KV(db *sqlx.DB, table string) *KV

NewOrderedSqlite3KV creates a new sqlite3 backed ordered key-value pair storage.

func NewPsqlKV

func NewPsqlKV(db *sqlx.DB, table string) *KV

NewPsqlKV creates a new postgresql backed unordered key-value pair storage.

func NewSqlite3KV

func NewSqlite3KV(db *sqlx.DB, table string) *KV

NewSqlite3KV creates a new sqlite3 backed unordered key-value pair storage.

func (*KV) Add

func (b *KV) Add(k string, v interface{}) error

Add is a short-hand for AddClass but with cls set to empty string.

func (*KV) AddClass

func (b *KV) AddClass(k, cls string, v interface{}) error

AddClass adds an entry with a particular class.

func (*KV) AppendBytes

func (b *KV) AppendBytes(k string, bs []byte) error

AppendBytes appends the byte slice to the existing value of the entry of the specified key. Creates the key if not exist.

func (*KV) Clear

func (b *KV) Clear() error

Clear clears the entire table.

func (*KV) Count

func (b *KV) Count() (int64, error)

Count returns the total number of entries.

func (*KV) Create

func (b *KV) Create() error

Create creates the table.

func (*KV) CreateMissing

func (b *KV) CreateMissing() error

CreateMissing creates the table if the table is missing.

func (*KV) Destroy

func (b *KV) Destroy() error

Destroy destroys the table.

func (*KV) Emplace

func (b *KV) Emplace(k string, v interface{}) error

Emplace sets the value for a particular key. Does nothing if the key already exists.

func (*KV) Get

func (b *KV) Get(k string, v interface{}) error

Get gets the value and JSON marshals it into v.

func (*KV) GetBytes

func (b *KV) GetBytes(k string) ([]byte, error)

GetBytes gets the value bytes for the specific key.

func (*KV) Has

func (b *KV) Has(k string) (bool, error)

Has checks if there exists an entry with the particular key.

func (*KV) Mutate

func (b *KV) Mutate(
	k string, v interface{}, f func(v interface{}) error,
) error

Mutate applies a function to an entry's value.

func (*KV) Remove

func (b *KV) Remove(k string) error

Remove removes the entry with the specific key.

func (*KV) Replace

func (b *KV) Replace(k string, v interface{}) error

Replace sets the value for a particular key. Creates the key if not exist.

func (*KV) Set

func (b *KV) Set(k string, v interface{}) error

Set updates the JSON value of a particular entry.

func (*KV) SetBytes

func (b *KV) SetBytes(k string, bs []byte) error

SetBytes updates the value bytes of a particular entry.

func (*KV) SetClass

func (b *KV) SetClass(k, cls string) error

SetClass set an entry's class string.

func (*KV) Walk

func (b *KV) Walk(it *Iter) error

Walk iterates through all entriess in the key-value store.

func (*KV) WalkClass

func (b *KV) WalkClass(cls string, it *Iter) error

WalkClass iterates through all entries in the key-value store of a particular class.

func (*KV) WalkPartial

func (b *KV) WalkPartial(p *KVPartial, it *Iter) error

WalkPartial iterates through a part of the entries in the key-value store, specificed by the partial option.

func (*KV) WalkPartialClass

func (b *KV) WalkPartialClass(cls string, p *KVPartial, it *Iter) error

WalkPartialClass iterates through a part of the entries of a particular class in the key-value store, specified by the partial option.

type KVOps

type KVOps struct {
	Clear    func() error
	Add      func(key, cls string, bs []byte) error
	Get      func(key string) ([]byte, error)
	Has      func(key string) (bool, error)
	Set      func(key string, bs []byte) error
	SetClass func(key, cls string) error
	Mutate   func(key string, f func(bs []byte) ([]byte, error)) error
	Remove   func(key string) error
	Emplace  func(key, cls string, bs []byte) error
	Replace  func(key, cls string, bs []byte) error
	Append   func(key string, bs []byte) error

	Walk             func(f WalkFunc) error
	WalkClass        func(cls string, f WalkFunc) error
	WalkPartial      func(p *KVPartial, f WalkFunc) error
	WalkPartialClass func(cls string, p *KVPartial, f WalkFunc) error
	Count            func() (int64, error)

	Create        func() error
	CreateMissing func() error
	Destroy       func() error
}

KVOps provides operations to operate over an unordered key-value pair table.

type KVPartial

type KVPartial struct {
	Offset uint64
	N      uint64
	Desc   bool
}

KVPartial specifies a part of a query result.

type Table

type Table interface {
	// Create creates table.
	Create() error

	// CreateMissing creates the table if it is missing.
	CreateMissing() error

	// Destroy destroys the table.
	Destroy() error
}

Table contains common operations for creating and destroying a table.

type Tables

type Tables struct {
	// contains filtered or unexported fields
}

Tables saves a set of psql tables that are backed by a postgres database backend, or backed by memory.

func NewMemTables

func NewMemTables() *Tables

NewMemTables creates a new table set that reside entirely inside memory.

func NewTables

func NewTables(db *sqlx.DB) *Tables

NewTables creates a new table set using the given database backend. When db is nil, it uses memory.

func OpenPsqlTables

func OpenPsqlTables(spec string) (*Tables, error)

OpenPsqlTables dials into a postgresql connection and creates PsqlTables with it.

func OpenSqlite3Tables

func OpenSqlite3Tables(file string) (*Tables, error)

OpenSqlite3Tables opens a sqlite3 database using the given file.

func (*Tables) Add

func (ts *Tables) Add(t Table)

Add adds a table into the table set.

func (*Tables) Create

func (ts *Tables) Create() error

Create creates all tables.

func (*Tables) CreateMissing

func (ts *Tables) CreateMissing() error

CreateMissing creates all missing tables.

func (*Tables) DB

func (ts *Tables) DB() *sqlx.DB

DB returns the underlying database link.

func (*Tables) Destroy

func (ts *Tables) Destroy() error

Destroy drops all tables.

func (*Tables) NewKV

func (ts *Tables) NewKV(table string) *KV

NewKV creates a key-value pair table.

func (*Tables) NewOrderedKV

func (ts *Tables) NewOrderedKV(table string) *KV

NewOrderedKV creates an ordered key-value pair table.

type WalkFunc

type WalkFunc func(k, cls string, bs []byte) error

WalkFunc is the a function type for walking through a table query result.

Directories

Path Synopsis
Package settings provides a generic, simple key-value pair like interface for saving application settings.
Package settings provides a generic, simple key-value pair like interface for saving application settings.

Jump to

Keyboard shortcuts

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