forked from mtcontrib/colddb
1.4 KiB
1.4 KiB
ColdDB
ColdDB is a minetest mod that implements a serverless, asynchronous, NoSQL database engine.
It provides a key or key-value based storage system using plain Lua tables.
Usage
Copy both colddb.lua and async files to your minetest mod or game. Copy the code from colddb's init file to your mods init file
Write this code in your lua file.
- create a directory and link it as a database.
coldbase = colddb.Colddb("mydb")
- store key item(this key has no value)
coldbase.set_key("MyKey")
- store key-value item
coldbase.set("MyKeyAndValue", "Hello world")
- retrieve items (get_key's callback(arg) will return true, false, or nil)
coldbase.get("MyKeyAndValue", nil, function(arg)
if arg then
minetest.log(string.format("value:%s", arg))
end
end)
coldbase.get_key("MyKey", nil, function(arg)
if arg then
minetest.log("Found key")
else
minetest.log("Key not found")
end
end)
- delete key(file) this function works on both keys and key-value keys.
coldbase.remove("MyKeyAndValue")
- if add_to_mem_pool is true(true by default). keys are stored in a weak lua table(memory) it will be removed by the gc if its not in-use. Storing data in memory is to prevent the database from constantly loading up data from files.
coldbase.add_to_mem_pool = true
License
ColdDB is distributed under the MIT license.