LevelDB wrapper for Nim
Go to file
Ben c70c51f5b3
Concurrent iterator tests
2024-05-28 10:56:16 +02:00
.github/workflows Revert "speed up ci by using binary" 2024-05-13 11:45:29 +02:00
leveldbstatic Symbol checks (#2) 2024-05-22 09:41:07 -07:00
tests Concurrent iterator tests 2024-05-28 10:56:16 +02:00
vendor@068d5ee1a3 Revert "pins leveldb to v1.23" 2024-05-11 08:08:44 +02:00
.gitignore implements query-iterator object 2024-05-14 09:23:08 +02:00
.gitmodules remove src folder 2024-05-09 15:37:37 +02:00
.travis.yml supported since nim 1.4.0 (#25) 2021-02-03 13:19:14 +08:00
LICENSE Initial commit 2016-05-17 21:31:18 +02:00
README.md Symbol checks (#2) 2024-05-22 09:41:07 -07:00
build.sh Symbol checks (#2) 2024-05-22 09:41:07 -07:00
leveldbstatic.nim Adds raise-lists to Iter callbacks. 2024-05-22 09:29:58 +02:00
leveldbstatic.nimble bumps to 0.1.4 2024-05-23 08:58:28 +02:00
leveldbtool.nim renames to leveldbstatic 2024-05-13 14:08:17 +02:00

README.md

leveldb.nim

A self-contained LevelDB wrapper for Nim in a Nim friendly way. Uses git-submodule and nimterop so that no external libraries have to be installed or linked.

Original nim LevelDB wrapper: HERE

Replacing of system library dependency with self-contained C/CPP interoperability by (Codex.Storage)[https://codex.storage]

Usage

Create a database:

   import leveldbstatic
   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()

Compiling with optimizations

CMake is used during compilation to determine which of the following optimization options are enabled. You can set the following nim compiler flags to 0 or 1 to override them:

  • fdatasync from <unistd.h> --passC:-DHAVE_FDATASYNC=1
  • F_FULLSYNC from <fcntl.h> --passC:-DHAVE_FULLFSYNC=1
  • O_CLOEXEC from <fcntl.h> --passC:-DHAVE_O_CLOEXEC=1
  • crc32c from <crc32c/crc32c.h> --passC:-DHAVE_CRC32C=1
  • snappy from <snappy.h> --passC:-DHAVE_SNAPPY=1
  • zstd from <zstd.h> --passC:-DHAVE_ZSTD=1

Updating

When you want to update this library to a new version of LevelDB, follow these steps:

  • Update LevelDB submodule to new version.
  • Run 'build.sh'.
  • Run 'nimble build' and 'nimble test'.
  • Make sure everything's working.
  • Increment version of this library in 'leveldbstatic.nimble'.
  • Commit the changes.
  • Tag the commit with the new version number.
  • Push.