sqlite3kv

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

README

Valkeyrie Sqlite3

GoDoc Build Status

valkeyrie provides a Go native library to store metadata using Distributed Key/Value stores (or common databases).

Compatibility

A storage backend in valkeyrie implements (fully or partially) the Store interface.

Calls SqliteV3
Put 🟢️
Get 🟢️
Delete 🟢️
Exists 🟢️
Watch 🟢️
WatchTree 🟢️
NewLock (Lock/Unlock)
List 🟢️
DeleteTree 🟢️
AtomicPut 🟢️
AtomicDelete 🟢️

Supported Versions

Examples

package main

import (
	"context"
	"log"

	"github.com/kvtools/valkeyrie"
	"github.com/ozanturksever/sqlite3kv"
)

func main() {
	ctx := context.Background()

	config := &sqlite3kv.Config{}

	kv, err := valkeyrie.NewStore(ctx, sqlite3kv.StoreName, []string{ "/tmp/test.db"}, config)
	if err != nil {
		log.Fatal("Cannot create store")
	}

	key := "foo"

	err = kv.Put(ctx, key, []byte("bar"), nil)
	if err != nil {
		log.Fatalf("Error trying to put value at key: %v", key)
	}

	pair, err := kv.Get(ctx, key, nil)
	if err != nil {
		log.Fatalf("Error trying accessing value at key: %v", key)
	}

	log.Printf("value: %s", string(pair.Value))

	err = kv.Delete(ctx, key)
	if err != nil {
		log.Fatalf("Error trying to delete key %v", key)
	}
}

Documentation

Index

Constants

View Source
const StoreName = "sqlite3kv"

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct{}

type SQLiteStore

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

func New

func New(ctx context.Context, endpoints []string, options *Config) (*SQLiteStore, error)

func (*SQLiteStore) AtomicDelete

func (s *SQLiteStore) AtomicDelete(ctx context.Context, key string, previous *store.KVPair) (bool, error)

AtomicDelete performs an atomic delete, ensuring that the current value matches the provided previous value

func (*SQLiteStore) AtomicPut

func (s *SQLiteStore) AtomicPut(ctx context.Context, key string, value []byte, previous *store.KVPair, opts *store.WriteOptions) (bool, *store.KVPair, error)

AtomicPut performs an atomic put, ensuring that the current value matches the provided previous value

func (*SQLiteStore) Close

func (s *SQLiteStore) Close() error

Close closes the database connection

func (*SQLiteStore) Delete

func (s *SQLiteStore) Delete(ctx context.Context, key string) error

func (*SQLiteStore) DeleteTree

func (s *SQLiteStore) DeleteTree(ctx context.Context, directory string) error

func (*SQLiteStore) Exists

func (s *SQLiteStore) Exists(ctx context.Context, key string, opts *store.ReadOptions) (bool, error)

Exists checks if a key exists in the key-value store

func (*SQLiteStore) Get

func (s *SQLiteStore) Get(ctx context.Context, key string, opts *store.ReadOptions) (*store.KVPair, error)

func (*SQLiteStore) List

func (s *SQLiteStore) List(ctx context.Context, directory string, opts *store.ReadOptions) ([]*store.KVPair, error)

func (*SQLiteStore) NewLock

func (s *SQLiteStore) NewLock(ctx context.Context, key string, opts *store.LockOptions) (store.Locker, error)

NewLock creates a distributed lock for a given key

func (*SQLiteStore) Put

func (s *SQLiteStore) Put(ctx context.Context, key string, value []byte, opts *store.WriteOptions) error

func (*SQLiteStore) Watch

func (s *SQLiteStore) Watch(ctx context.Context, key string, opts *store.ReadOptions) (<-chan *store.KVPair, error)

Watch creates a watch channel for a specific key

func (*SQLiteStore) WatchTree

func (s *SQLiteStore) WatchTree(ctx context.Context, directory string, opts *store.ReadOptions) (<-chan []*store.KVPair, error)

WatchTree creates a watch channel for all keys under a directory

Jump to

Keyboard shortcuts

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