Skip to content

saromanov/lightstore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lightstore

Go Report Card Codacy Badge Build Status Coverage Status

Key-Value store in Progress

Table of Contents

Getting Started

Installing

$ go get github.com/saromanov/lightstore/...

Create Database

Easy steps for create a new database

package main

import "github.com/saromanov/lightstore/store"

func main() {
    light, err := store.Open(nil)
    if err != nil {
        panic(err)
    }
	defer light.Close()
}

This creates a new database with default config

Or create database only with path to db file

light, err := store.OpenStrict("db.db")
if err != nil {
	panic(err)
}
defer light.Close()

Write transactions

For make new transaction, need to open new transaction and then commit changes

err = light.Write(func(txn *store.Txn) error {
		for i := 0; i < 20; i++ {
			err := txn.Set([]byte(fmt.Sprintf("%d", i)), []byte(fmt.Sprintf("bar+%d", i)))
			if err != nil {
				return err
			}
		}
		return txn.Commit()
	})
	if err != nil {
		log.Fatalf("unable to write data: %v", err)
    }

Iterator

light.View(func(txn *store.Txn) error {
		it, _ := txn.NewIterator(store.IteratorOptions{})
		for it.First(); it.Valid(); it.Next() {
			itm := it.Item()
			fmt.Println(string(itm.Key()), string(itm.Value()))
		}
		return nil
})

About

Key-Value Store ⚡

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages