sqlitekv

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2025 License: MIT Imports: 12 Imported by: 0

README

sqlitekv

KV on Sqlite DB

Documentation

Index

Constants

View Source
const (
	SQLITE_CONSTRAINT_UNIQUE     = 2067
	SQLITE_CONSTRAINT_PRIMARYKEY = 1555
)

Variables

View Source
var (
	ErrUnimplemented     = errors.New("not implemented")
	ErrUniqueConstraint  = errors.New("constraint failed")
	ErrPrimaryConstraint = errors.New("primary key constraint failed")
)

Functions

func Compress added in v0.5.0

func Compress(src []byte) []byte

Compress a buffer. If you have a destination buffer, the allocation in the call can also be eliminated.

func GenerateID64 added in v0.3.0

func GenerateID64() int64

Types

type Collection

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

func NewCollection added in v0.3.0

func NewCollection(kv *KV, name string, opts *CollectionOptions) (col *Collection, err error)

func (*Collection) Delete added in v0.5.0

func (c *Collection) Delete(ctx context.Context, id int64) (err error)

func (*Collection) Get

func (c *Collection) Get(ctx context.Context, obj CollectionType) (ok bool, err error)

func (*Collection) GetUnique added in v0.3.0

func (c *Collection) GetUnique(ctx context.Context, colname string, colval any, obj CollectionType) (ok bool, err error)

func (*Collection) Insert added in v0.3.0

func (c *Collection) Insert(ctx context.Context, val CollectionType) (changeCount int, err error)

func (*Collection) List

func (c *Collection) List(ctx context.Context, keyPrefix string, fn GetFn, opts ListOptions) (err error)

func (*Collection) Put

func (c *Collection) Put(ctx context.Context, val CollectionType) (changeCount int, err error)

func (*Collection) Search added in v0.2.0

func (c *Collection) Search(ctx context.Context, query string, rowfn RowFn) (err error)

func (*Collection) Select

func (c *Collection) Select(ctx context.Context, rowFn RowFn, opts SelectOptions) (err error)

func (*Collection) Update added in v0.3.0

func (c *Collection) Update(ctx context.Context, obj CollectionType) (changeCount int, err error)

type CollectionOptions

type CollectionOptions struct {
	Columns  []DerivedColumn
	Indexes  []string
	AutoId   bool
	Json     bool
	FTS      *FTSOptions
	Compress bool
}

type CollectionType added in v0.3.0

type CollectionType interface {
	GetId() (id int64)
	SetId(id int64)
	GetVal() (val []byte, err error)
	SetVal(val []byte) error
	Column(i int, name string) (ok bool, val any, err error)
	SetColumn(i int, name string, ok bool, val any) error
}

type Counter

type Counter struct {
	Id           int64
	Start        int64 `json:"start"`
	ReserveCount int64 `json:"reserve_count"`
	Current      int64 `json:"current"`
	Limit        int64 `json:"limit"`
	// contains filtered or unexported fields
}

func NewCounter

func NewCounter(col *Collection, opts CounterOptions) (c *Counter, err error)

func (*Counter) Column added in v0.3.0

func (c *Counter) Column(i int, name string) (ok bool, val any, err error)

func (*Counter) GetId added in v0.3.0

func (c *Counter) GetId() int64

func (*Counter) GetVal added in v0.3.0

func (c *Counter) GetVal() (val []byte, err error)

func (*Counter) Next

func (c *Counter) Next(ctx context.Context) (counter int64, err error)

func (*Counter) SetColumn added in v0.3.0

func (c *Counter) SetColumn(i int, name string, ok bool, val any) error

func (*Counter) SetId added in v0.3.0

func (c *Counter) SetId(id int64)

func (*Counter) SetVal added in v0.3.0

func (c *Counter) SetVal(val []byte) error

type CounterOptions

type CounterOptions struct {
	StartCount   int64
	ReserveCount int64
}

type DerivedColumn added in v0.3.0

type DerivedColumn struct {
	Name     string
	Type     string
	Nullable bool
	Unique   bool
}

type FTSOptions added in v0.3.0

type FTSOptions struct {
	Columns     []string
	ExcludeKeys []string
}

type GetFn

type GetFn func(id int64, key string, rawJson []byte, genColVals []any) error

type KV

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

func Open

func Open(dbpath string, opts *Options) (kv *KV, err error)

func (*KV) Clone added in v0.5.0

func (kv *KV) Clone() (newKv *KV, err error)

func (*KV) Close

func (kv *KV) Close() (err error)

func (*KV) WalCheckpoint added in v0.5.0

func (kv *KV) WalCheckpoint() (err error)

func (*KV) WithTx

func (kv *KV) WithTx(fn func() error) (err error)

type ListOptions

type ListOptions struct {
	OrderBy    []string
	Descending bool
	All        bool
}

type Options

type Options struct {
	JournalMode       string
	BusyRetryInterval time.Duration
}

type ParseFn added in v0.3.0

type ParseFn func(obj CollectionType) error

type RowFn

type RowFn func(parseFn ParseFn) error

func GetAccumulateFn added in v0.3.0

func GetAccumulateFn[T any](out *[]*T) (fn RowFn)

type SelectOptions

type SelectOptions struct {
	Where   string
	OrderBy []string
	Limit   int
}

Directories

Path Synopsis
cmd
kvtest command

Jump to

Keyboard shortcuts

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