LimDB 0.3.0 has landed! This is a rather large feature release.
LimDB is a key-value store that makes it as convenient as possible to use the LMDB memory-mapped key-value database by providing an interface that is like a table.
import limdb
let db = initDatabase("myDirectory")
db["foo"] = "bar" # that's it, foo -> bar is now on disk
Now, you can also do that with any type, using a convenient syntax to chose them.
import limdb
let db = initDatabase("myDirectory", (int, float))
db[1] = 2.2 # 1 -> 2.2 is now on disk
There are transaction blocks now for safer, more convenient code.
import os
import limdb
let db = initDatabase("myDirectory", (int, float))
db.withTransaction, t:
echo t[1] = 2.2 # this is not quite on disk
echo t[2] = 4.4 # neither is this
# now both are
db.withTransaction, t:
echo t[1]
sleep 2
echo t[1] # this will never have changed
db.withTransaction, t:
echo t[1] # now it might
You can also conveniently have multiple databases in the same location identified by name and use
import limdb
let db = initDatabase("myDirectory", (foo: int, float, bar: string, int))
db.withTransaction, t:
t.foo[1] = 2.2 #this is not quite on disk
t.bar["fuz"] = 3 #neither is this
# now both are
db.foo[2] = 4.4 # this works too
echo db.bar["fuz'] # so does this
You can get complicated
type
Foo = enum
a, b, c, d
Bar = object
a: int
b: Foo
c: tuple[x: int, y: string]
d: seq[int]
import limdb
let db = initDatabase("myDirectory", (Foo, Bar))
db[a] = Bar(a: 1, b: b, c: (x: 1, y: "z"), d: @[1,2,3]) # well, that's safe on disk now
In the extensive documentation, you can also learn how readonly or readwrite modes are chosen automatically, how to use explicit read/write calls, how to use the ultra-shorthand syntax for explorateive programming, and how to write two small helpers to easily use your own data types.
If you're upgrading, it's backwards-compatible to version 0.2, but you might get speed boost.
Tested on Linux, Windows and OSX. Servus from Munich!