I thought LevelDB is a good one, so I made client command with Go.

yuuichifujioka

yuuichi fujioka

Posted on July 10, 2018

I thought LevelDB is a good one, so I made client command with Go.

Suddenly, I looked for KVS that can be used as a library like SQLite and found it in LevelDB.

GitHub logo google / leveldb

LevelDB is a fast key-value storage library written at Google that provides an ordered mapping from string keys to string values.

LevelDB is a fast key-value storage library written at Google that provides an ordered mapping from string keys to string values.

This repository is receiving very limited maintenance. We will only review the following types of changes.

  • Fixes for critical bugs, such as data loss or memory corruption
  • Changes absolutely needed by internally supported leveldb clients. These typically fix breakage introduced by a language/standard library/OS update

ci

Authors: Sanjay Ghemawat (sanjay@google.com) and Jeff Dean (jeff@google.com)

Features

  • Keys and values are arbitrary byte arrays.
  • Data is stored sorted by key.
  • Callers can provide a custom comparison function to override the sort order.
  • The basic operations are Put(key,value), Get(key), Delete(key).
  • Multiple changes can be made in one atomic batch.
  • Users can create a transient snapshot to get a consistent view of data.
  • Forward and backward iteration is supported over the data.
  • Data is automatically compressed using…

It was a pleasure to use plyvel of Python's LevelDB library, but I decided to create a client command because I don't want to not write Python every time to retrieve a list or list of keys or to delete unnecessary keys.

And here is the one.

GitHub logo yuuichi-fujioka / go-leveldbctl

LevelDB control command

leveldbctl

Build Status Coverage Status

LevelDB control command.

This command provides easy way to CRUD operation on LevelDB.

$ leveldbctl put foo bar
put foo: bar into ./
$ leveldbctl get foo
bar
Enter fullscreen mode Exit fullscreen mode

Features

  • Initialize LevelDB
  • Put key/value into LevelDB
  • Get value with key
  • Delete key
  • Dump all key/values in LevelDB
  • Print all keys

Install

$ export GO111MODULE=on
$ go get github.com/yuuichi-fujioka/go-leveldbctl/cmd/leveldbctl
Enter fullscreen mode Exit fullscreen mode

Usage

NAME
   leveldbctl - A new cli application

USAGE:
   leveldbctl [global options] command [command options] [arguments...]

VERSION:
   0.0.0

COMMANDS:
     init, i    Initialize a LevelDB
     walk, w    Walk in a LevelDB
     keys, k    Search all keys in a LevelDB
     put, p     Put a value into a LevelDB
     get, g     Gut a value from a LevelDB
     delete, d  Delete a value from a LevelDB
     help, h    Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --dbdir value, -d value  LevelDB Directory (default: "./") [$LEVELDB_DIR]
   --hexkey, --xk
Enter fullscreen mode Exit fullscreen mode

It can be used by installing with go get.

$ go get github.com/yuuichi-fujioka/go-leveldbctl/cmd/leveldbctl
$ leveldbctl -h
NAME:
   leveldbctl - A new cli application

USAGE:
   leveldbctl [global options] command [command options] [arguments...]

VERSION:
   0.0.0

COMMANDS:
     init, i    Initialize a LevelDB
     walk, w    Walk in a LevelDB
     keys, k    Search all keys in a LevelDB
     put, p     Put a value into a LevelDB
     get, g     Gut a value from a LevelDB
     delete, d  Delete a value from a LevelDB
     help, h    Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --dbdir value, -d value  LevelDB Directory (default: "./") [$LEVELDB_DIR]
   --help, -h               show help
   --version, -v            print the version
Enter fullscreen mode Exit fullscreen mode

How to Use

It can initialize and CRUD operation, assuming that the current directory is a directory of LevelDB. (Specific directories may be set as LevelDB with the options --dbdir or -d)

Initialize with init, make it with put, get it with get, delete it with delete.

$ leveldbctl init   #  Initialize. Several files are created.
./ is initialized as LevelDB
$ leveldbctl get aaa  # When a key is not exist in db, it is displayed that it cannot be found.
aaa is not found.
$ leveldbctl put aaa bbb  # Put bbb into aaa.
put aaa: bbb into ./.
$ leveldbctl get aaa  # Got bbb
bbb
$ leveldbctl delete aaa  # Delete it.
aaa is deleted
Enter fullscreen mode Exit fullscreen mode

walk can output all key values,keys can output all keys.

$ leveldbctl keys
egg
foo
hoge
$ leveldbctl walk
egg: spam
foo: bar
hoge: fuga
Enter fullscreen mode Exit fullscreen mode

Misc

  • I tested it On Mac OS High Sierra and Ubuntu 16.04.4 LTS.。
  • CLI is implemented using github.com/urfave/cli.
  • LevelDB operation uses github.com/syndtr/goleveldb/leveldb.
💖 💪 🙅 🚩
yuuichifujioka
yuuichi fujioka

Posted on July 10, 2018

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related