gokvstore

package module
v0.0.0-...-a0f82cf Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2020 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

gokvstore

Key Value stores built with relational DBs: Postgres, SQLite, (MySQL coming soon)

Builds

Build Status

Examples:

  import "github.com/korovkin/gokvstore"

	s, err := gokvstore.NewStoreSqlite("kv_test", ".")
	defer s.Close()

  // Add Key, Value, Tag:
	s.AddValueKVT("kk", "33", "t")

  // Add Key JSON(Value), Tag:
  m := map[string]interface{}{
    "name": "superman",
  }
  s.AddValueAsJSON("superman", "t", m)

SQLite:

store_sqlite_test.go

Postgres:

store_postgres_test.go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type StorePostgres

type StorePostgres struct {
	Db                   *sql.DB
	Name                 string
	InsertStmt           *sql.Stmt
	GetStmt              *sql.Stmt
	IterateStmt          *sql.Stmt
	IterateAllStmt       *sql.Stmt
	IterateByPrefixASCEQ *sql.Stmt
	IterateByPrefixDSCEQ *sql.Stmt
	DeleteStmt           *sql.Stmt
	DeleteStmtTag        *sql.Stmt
	DeleteStmtTagLT      *sql.Stmt
	DeleteAllStmt        *sql.Stmt
	CountAllStmt         *sql.Stmt
}

StorePostgres is a 'key value' store based on Postgres DB table

func NewStorePostgres

func NewStorePostgres(name string, connection string, db *sql.DB) (*StorePostgres, error)

NewStorePostgres allocates a new instance and connected to the store

func NewStorePostgresWithValueType

func NewStorePostgresWithValueType(name string, valueType string, connection string, db *sql.DB) (*StorePostgres, error)

NewStorePostgresWithValueType allocates a new instance and connected to the store

func (*StorePostgres) AddValueAsJSON

func (s *StorePostgres) AddValueAsJSON(k string, t string, o interface{}) error

AddValueAsJSON store o under (k, t)

func (*StorePostgres) AddValueKV

func (s *StorePostgres) AddValueKV(k string, v string) error

AddValueKV add a (K, V) entry to the store

func (*StorePostgres) AddValueKVT

func (s *StorePostgres) AddValueKVT(k string, v string, t string) error

AddValueKVT add a (K,V,T) entry to the store

func (*StorePostgres) Close

func (s *StorePostgres) Close()

Close the connection to the store

func (*StorePostgres) CountAll

func (s *StorePostgres) CountAll() (int64, string, string)

CountAll will compute the count, min, max for the store

func (*StorePostgres) DeleteAll

func (s *StorePostgres) DeleteAll() error

DeleteAll delete all items from the store

func (*StorePostgres) DeleteAllWithTag

func (s *StorePostgres) DeleteAllWithTag(t string) error

DeleteAllWithTag delete all entries from the store with with the given tag t

func (*StorePostgres) DeleteValue

func (s *StorePostgres) DeleteValue(k string) error

DeleteValue deletes the given k from the store

func (*StorePostgres) DeleteWhereTagLT

func (s *StorePostgres) DeleteWhereTagLT(t string) error

DeleteWhereTagLT delete all entries with tag less than t

func (*StorePostgres) GetValue

func (s *StorePostgres) GetValue(k string) *string

GetValue get the value for key k

func (*StorePostgres) GetValueAsJSON

func (s *StorePostgres) GetValueAsJSON(k string, o interface{}) error

GetValueAsJSON gets the value stored for the key k

func (*StorePostgres) IterateAll

func (s *StorePostgres) IterateAll(
	o interface{},
	block func(k string, v string, t string, stop *bool))

IterateAll traverse all the stored items

func (*StorePostgres) IterateByKeyPrefixASCEQ

func (s *StorePostgres) IterateByKeyPrefixASCEQ(
	keyPrefix string,
	limit int,
	block func(k *string, t *string, v *string, stop *bool)) error

IterateByKeyPrefixASCEQ traverse the stored items by key prefix (ascending)

func (*StorePostgres) IterateByKeyPrefixDESCEQ

func (s *StorePostgres) IterateByKeyPrefixDESCEQ(
	keyPrefix string,
	limit int,
	block func(k *string, t *string, v *string, stop *bool)) error

IterateByKeyPrefixDESCEQ traverse the stored items by key prefix (descending)

type StoreSqlite

type StoreSqlite struct {
	Db                 *sql.DB   `json:"-"`
	InsertStmt         *sql.Stmt `json:"-"`
	GetStmt            *sql.Stmt `json:"-"`
	IterateStmt        *sql.Stmt `json:"-"`
	IterateAllStmt     *sql.Stmt `json:"-"`
	IterateByPrefixASC *sql.Stmt `json:"-"`
	IterateByPrefixDSC *sql.Stmt `json:"-"`
	DeleteStmt         *sql.Stmt `json:"-"`
	DeleteAllStmt      *sql.Stmt `json:"-"`
	DeleteStmtTag      *sql.Stmt `json:"-"`
	CountAllStmt       *sql.Stmt `json:"-"`
	Filename           string    `json:"filename"`
	// contains filtered or unexported fields
}

StoreSqlite sqlite based key value store

func NewStoreSqlite

func NewStoreSqlite(tableName string, folder string) (*StoreSqlite, error)

NewStoreSqlite allocate a new instance of StoreSqlite will create a sqlite file name 'tableName' in 'folder'

func (*StoreSqlite) AddValueAsJSON

func (s *StoreSqlite) AddValueAsJSON(k string, t string, o interface{}) error

AddValueAsJSON add (k, t, json(o)) to the store

func (*StoreSqlite) AddValueKV

func (s *StoreSqlite) AddValueKV(k string, v string) error

AddValueKV add (k,v) to the store

func (*StoreSqlite) AddValueKVT

func (s *StoreSqlite) AddValueKVT(k string, v string, t string) error

AddValueKVT add (k,v,t) to the store

func (*StoreSqlite) Close

func (s *StoreSqlite) Close()

Close close all the statements and the sqlite db

func (*StoreSqlite) CloseAndDelete

func (s *StoreSqlite) CloseAndDelete()

CloseAndDelete deletes the sqlite DB from the file system

func (*StoreSqlite) Commit

func (s *StoreSqlite) Commit()

Commit execute "COMMIT;" on the sqlite store

func (*StoreSqlite) CountAll

func (s *StoreSqlite) CountAll() (int64, string, string)

CountAll count number of items in the store

func (*StoreSqlite) DeleteAll

func (s *StoreSqlite) DeleteAll() error

DeleteAll delete all the data in the store

func (*StoreSqlite) DeleteAllWithTag

func (s *StoreSqlite) DeleteAllWithTag(t string) error

DeleteAllWithTag delete all value with tag t from the store

func (*StoreSqlite) DeleteValue

func (s *StoreSqlite) DeleteValue(k string) error

DeleteValue delete k from the store

func (*StoreSqlite) GetValue

func (s *StoreSqlite) GetValue(k string) *string

GetValue get the value for the given k

func (*StoreSqlite) GetValueAsJSON

func (s *StoreSqlite) GetValueAsJSON(k string, o interface{}) error

GetValueAsJSON get the value for the given k into o

func (*StoreSqlite) IterateAll

func (s *StoreSqlite) IterateAll(
	o interface{},
	block func(k string, t string, v string, stop *bool))

IterateAll traverse all the items in the store

func (*StoreSqlite) IterateByKeyPrefixASC

func (s *StoreSqlite) IterateByKeyPrefixASC(
	keyPrefix string,
	limit int,
	block func(k *string, t *string, v *string, stop *bool)) error

IterateByKeyPrefixASC traverse all the items by keyPrefix in ASC order

func (*StoreSqlite) IterateByKeyPrefixDESC

func (s *StoreSqlite) IterateByKeyPrefixDESC(
	keyPrefix string,
	limit int,
	block func(k *string, t *string, v *string, stop *bool)) error

IterateByKeyPrefixDESC traverse items by key prefix in DESC order

func (*StoreSqlite) Transaction

func (s *StoreSqlite) Transaction(block func()) error

Transaction run the given block under a sqlite transaction

Jump to

Keyboard shortcuts

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