summaryrefslogtreecommitdiff
path: root/db.lua
diff options
context:
space:
mode:
authorthe lemons <citrons@mondecitronne.com>2023-04-07 03:29:49 -0500
committerthe lemons <citrons@mondecitronne.com>2023-04-07 03:29:49 -0500
commit1becf46aea2ab522c82212d1c74732a77b3142a9 (patch)
treed2861a0584dc68b6271408fddf0cb03c4eefc76d /db.lua
intial commit
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