sqlitekv

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2025 License: MIT Imports: 6 Imported by: 0

README

sqlitekv

KV on Sqlite DB

Documentation

Index

Constants

View Source
const (
	EncodeSoftDelete   = 0x1
	EncodeFlagCompress = 0x2
	EncodeFlagUseDict  = 0x4
	DictIDMask         = 0xff00
)

Variables

This section is empty.

Functions

func IsCompressed added in v0.7.0

func IsCompressed(flags int64) bool

func IsDictCompressed added in v0.7.0

func IsDictCompressed(flags int64) bool

Types

type DecodeOptions added in v0.7.0

type DecodeOptions struct {
	DictKey string
}

type Dict added in v0.7.0

type Dict struct {
	Buf []byte
	Ver uint8
}

type DictCollection added in v0.7.0

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

func NewDictCollection added in v0.7.0

func NewDictCollection(db *sql.DB) (c *DictCollection, err error)

func (*DictCollection) DeleteAllVersions added in v0.7.0

func (c *DictCollection) DeleteAllVersions(key string) (err error)

func (*DictCollection) DeleteDict added in v0.7.0

func (c *DictCollection) DeleteDict(key string, ver int64) (err error)

func (*DictCollection) Get added in v0.7.0

func (c *DictCollection) Get(key string, ver uint8) (ok bool, dict Dict, err error)

func (*DictCollection) GetLatest added in v0.7.0

func (c *DictCollection) GetLatest(key string) (ok bool, d Dict, err error)

func (*DictCollection) GetMaxVersion added in v0.7.0

func (c *DictCollection) GetMaxVersion(key string) (maxVer uint8, err error)

func (*DictCollection) Insert added in v0.7.0

func (c *DictCollection) Insert(key string, d Dict) (err error)

type DictStore added in v0.7.0

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

func (*DictStore) GetCDict added in v0.7.0

func (s *DictStore) GetCDict(key string, ver uint8) (cdict *gozstd.CDict)

func (*DictStore) GetDDict added in v0.7.0

func (s *DictStore) GetDDict(key string, ver uint8) (ddict *gozstd.DDict)

func (*DictStore) SetDict added in v0.7.0

func (s *DictStore) SetDict(key string, ver uint8, buf []byte) (err error)

type EncodeOptions added in v0.7.0

type EncodeOptions struct {
	Compress bool
	UseDict  bool
	DictKey  string
	DictVer  uint8
}

type Encoder added in v0.7.0

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

func NewEncoder added in v0.7.0

func NewEncoder(dictColl *DictCollection) (e *Encoder)

func (*Encoder) Decode added in v0.7.0

func (e *Encoder) Decode(src []byte, destObj any, flags int64, opts DecodeOptions) (err error)

func (*Encoder) DecodeBuf added in v0.7.0

func (e *Encoder) DecodeBuf(src []byte, flags int64, opts DecodeOptions) (buf []byte, err error)

func (*Encoder) DictCollection added in v0.7.0

func (e *Encoder) DictCollection() *DictCollection

func (*Encoder) Encode added in v0.7.0

func (e *Encoder) Encode(obj any, opts EncodeOptions) (flags int64, ebuf []byte, err error)

func (*Encoder) TrainWithRows added in v0.7.0

func (e *Encoder) TrainWithRows(db *sql.DB, key string, selectSql string) (d Dict, err error)

type KeyVal added in v0.7.0

type KeyVal[T any] struct {
	// contains filtered or unexported fields
}

func NewKeyVal added in v0.7.0

func NewKeyVal[T any](db *sql.DB, name string, opts KeyValOptions[T]) (kv *KeyVal[T], err error)

func (*KeyVal[T]) Delete added in v0.7.0

func (kv *KeyVal[T]) Delete(pkey any) (affectedCount int64, err error)

func (*KeyVal[T]) Get added in v0.7.0

func (kv *KeyVal[T]) Get(pkey any, obj *T) (ok bool, err error)

func (*KeyVal[T]) GetUnique added in v0.7.0

func (kv *KeyVal[T]) GetUnique(columnName string, pkey any, obj *T) (ok bool, err error)

func (*KeyVal[T]) Insert added in v0.7.0

func (kv *KeyVal[T]) Insert(obj *T) (rid int64, err error)

func (*KeyVal[T]) Select added in v0.7.0

func (kv *KeyVal[T]) Select(bindargs []any, opts SelectOptions[T]) (list []*T, err error)

func (*KeyVal[T]) SoftDelete added in v0.7.0

func (kv *KeyVal[T]) SoftDelete(pkey any) (affectedCount int64, err error)

func (*KeyVal[T]) Table added in v0.7.0

func (kv *KeyVal[T]) Table() *Table

func (*KeyVal[T]) Train added in v0.7.0

func (kv *KeyVal[T]) Train(limit int) (err error)

func (*KeyVal[T]) Upsert added in v0.7.0

func (kv *KeyVal[T]) Upsert(obj *T) (err error)

type KeyValField added in v0.7.0

type KeyValField[T any] struct {
	Name     string
	Type     string
	Unique   bool
	Nullable bool
	Indexed  bool
	Get      func(t *T) any
	GetPtr   func(t *T) any
}

type KeyValOptions added in v0.7.0

type KeyValOptions[T any] struct {
	KeyField    *KeyValField[T]
	Fields      []*KeyValField[T]
	Enc         *Encoder
	OnInsert    func(*T)
	OnUpdate    func(*T)
	Validate    func(*T) error
	Compression bool
	UseDict     bool
}

type SelectOptions

type SelectOptions[T any] struct {
	StmtName string
	Where    string
	Limit    int
	Order    string
}

type StmtStore added in v0.7.0

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

func NewStmtStore added in v0.7.0

func NewStmtStore() *StmtStore

func (*StmtStore) GetOrCreate added in v0.7.0

func (s *StmtStore) GetOrCreate(db *sql.DB, stmtName string, getSql func() string) (*sql.Stmt, error)

type Table added in v0.7.0

type Table struct {
	Name string
	// contains filtered or unexported fields
}

func NewTable added in v0.7.0

func NewTable(db *sql.DB, name string, opts TableOptions) (t *Table, err error)

func (*Table) Insert added in v0.7.0

func (t *Table) Insert(args ...any) (rid int64, err error)

func (*Table) Row added in v0.7.0

func (t *Table) Row(stmtName string, getSql func() string, bindargs []any, args ...any) (ok bool, err error)

func (*Table) Select added in v0.7.0

func (t *Table) Select(selectSql string, bindargs []any, handleRow func(row *sql.Rows) error) (err error)

func (*Table) SelectUsingStmt added in v0.7.0

func (t *Table) SelectUsingStmt(stmtName string, getSql func() string, bindargs []any, handleRow func(row *sql.Rows) error) (err error)

func (Table) StmtStore added in v0.7.0

func (t Table) StmtStore() *StmtStore

func (*Table) Update added in v0.7.0

func (t *Table) Update(updateSql string, args ...any) (affectedCount int64, err error)

func (*Table) Upsert added in v0.7.0

func (t *Table) Upsert(args ...any) (rid int64, err error)

type TableField added in v0.7.0

type TableField struct {
	Name       string
	Type       string
	PrimaryKey bool
	Indexed    bool
	Nullable   bool
	Unique     bool
}

type TableOptions added in v0.7.0

type TableOptions struct {
	Fields []TableField
}

type ZstdDict added in v0.7.0

type ZstdDict struct {
	CDict *gozstd.CDict
	DDict *gozstd.DDict
}

Directories

Path Synopsis
cmd
try command

Jump to

Keyboard shortcuts

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