From 1becf46aea2ab522c82212d1c74732a77b3142a9 Mon Sep 17 00:00:00 2001 From: the lemons Date: Fri, 7 Apr 2023 03:29:49 -0500 Subject: intial commit --- db.lua | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 db.lua (limited to 'db.lua') 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 -- cgit v1.2.3