forked from mtcontrib/colddb
51 lines
1.4 KiB
Markdown
51 lines
1.4 KiB
Markdown
ColdDB
|
|
===========
|
|
|
|
ColdDB is a minetest mod that implements a serverless, asynchronous, NoSQL database engine.<br>
|
|
It provides a key or key-value based storage system using plain Lua tables.<br>
|
|
|
|
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<br>
|
|
Write this code in your lua file.
|
|
1. create a directory and link it as a database.
|
|
```lua
|
|
coldbase = colddb.Colddb("mydb")
|
|
```
|
|
2. store key item(this key has no value)
|
|
```lua
|
|
coldbase.set_key("MyKey")
|
|
```
|
|
3. store key-value item
|
|
```lua
|
|
coldbase.set("MyKeyAndValue", "Hello world")
|
|
```
|
|
4. retrieve items (get_key's callback(arg) will return true, false, or nil)
|
|
```lua
|
|
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)
|
|
```
|
|
5. delete key(file) this function works on both keys and key-value keys.
|
|
```lua
|
|
coldbase.remove("MyKeyAndValue")
|
|
```
|
|
6. 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.
|
|
```lua
|
|
coldbase.add_to_mem_pool = true
|
|
```
|
|
|
|
License
|
|
===========
|
|
|
|
ColdDB is distributed under the LGPLv2.1+ license. |