LevelDB wrapper for Nim
Go to file
Michał Zieliński c531156f45
Merge pull request #19 from zielmicha/try-github-pages
Fix document compilation and publishing features
2020-06-23 23:00:19 +02:00
.github/workflows compile the documentation separately 2020-06-23 16:13:49 +08:00
src add documentation 2020-02-27 20:38:12 +08:00
tests add proc getOrDefault 2020-02-27 20:31:06 +08:00
.gitignore add documentation 2020-02-27 20:38:12 +08:00
.travis.yml support minimum nim version 0.18.0 2020-02-18 23:46:17 +08:00
LICENSE Initial commit 2016-05-17 21:31:18 +02:00
README.md update readme 2020-02-29 14:08:20 +08:00
leveldb.nimble tool rename 2020-02-24 23:53:44 +08:00

README.md

leveldb.nim

A LevelDB wrapper for Nim in a Nim friendly way.

Create a database:

   import leveldb
   import options

   var db = leveldb.open("/tmp/mydata")

Read or modify the database content:

   assert db.getOrDefault("nothing", "") == ""

   db.put("hello", "world")
   db.put("bin", "GIF89a\1\0")
   echo db.get("hello")
   assert db.get("hello").isSome()

   var key, val = ""
   for key, val in db.iter():
     echo key, ": ", repr(val)

   db.delete("hello")
   assert db.get("hello").isNone()

Batch writes:

   let batch = newBatch()
   for i in 1..10:
     batch.put("key" & $i, $i)
   batch.delete("bin")
   db.write(batch)

Iterate over subset of database content:

   for key, val in db.iterPrefix(prefix = "key1"):
     echo key, ": ", val
   for key, val in db.iter(seek = "key3", reverse = true):
     echo key, ": ", val

   db.close()