summaryrefslogtreecommitdiff
path: root/db.lua
diff options
context:
space:
mode:
Diffstat (limited to 'db.lua')
-rw-r--r--db.lua29
1 files changed, 29 insertions, 0 deletions
diff --git a/db.lua b/db.lua
new file mode 100644
index 0000000..c01d717
--- /dev/null
+++ b/db.lua
@@ -0,0 +1,29 @@
+local lmdb = require 'lmdb'
+
+local M = {}
+
+local db
+
+function M.get()
+ if not db then
+ db = assert(lmdb.open("data", {maxdbs = 256}))
+ end
+ local txn = db:txn_begin(true)
+ local meta = txn:open("meta", true)
+ if not meta.version then
+ version = 1
+ end
+ txn:open("users", true)
+ txn:open("usernames", true)
+ txn:open("emails", true)
+ txn:commit()
+ return db
+end
+
+function M.txn(write_enabled)
+ return M.get():txn_begin(write_enabled)
+end
+
+M.next = lmdb.next
+
+return M