2018-11-06 03:05:04 +01:00
ColdDB
===========
2018-11-11 04:40:49 +01:00
ColdDB is a minetest mod that implements a serverless, asynchronous, NoSQL database engine.< br >
2019-01-15 01:17:45 +01:00
It provides a key or key-value based storage system using plain Lua tables.< br >
2018-11-06 05:13:37 +01:00
Usage
===========
2018-11-12 06:48:15 +01:00
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 >
2018-11-06 05:13:37 +01:00
Write this code in your lua file.
1. create a directory and link it as a database.
```lua
2019-01-08 07:32:34 +01:00
coldbase = colddb.Colddb("mydb")
2018-11-06 05:13:37 +01:00
```
2019-01-09 07:25:55 +01:00
2. store key item(this key has no value)
2018-11-06 05:13:37 +01:00
```lua
2019-01-08 07:32:34 +01:00
coldbase.set_key("MyKey")
2018-11-06 05:13:37 +01:00
```
2019-01-09 07:25:55 +01:00
3. store key-value item
2018-11-06 05:13:37 +01:00
```lua
2019-01-08 07:32:34 +01:00
coldbase.set("MyKeyAndValue", "Hello world")
2018-11-06 05:13:37 +01:00
```
2019-01-09 07:25:55 +01:00
4. retrieve items (get_key's callback(arg) will return true, false, or nil)
2018-11-06 05:13:37 +01:00
```lua
2019-01-08 07:32:34 +01:00
coldbase.get("MyKeyAndValue", nil, function(arg)
2018-11-11 04:40:49 +01:00
if arg then
2019-01-08 07:32:34 +01:00
minetest.log(string.format("value:%s", arg))
2018-11-11 04:40:49 +01:00
end
end)
2019-01-08 07:32:34 +01:00
coldbase.get_key("MyKey", nil, function(arg)
2018-11-11 04:40:49 +01:00
if arg then
minetest.log("Found key")
else
minetest.log("Key not found")
end
end)
2018-11-06 05:13:37 +01:00
```
2019-01-09 07:25:55 +01:00
5. delete key(file) this function works on both keys and key-value keys.
2018-11-06 05:13:37 +01:00
```lua
2019-01-08 07:32:34 +01:00
coldbase.remove("MyKeyAndValue")
2018-11-06 05:13:37 +01:00
```
2019-01-09 07:25:55 +01:00
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.
2018-11-06 05:13:37 +01:00
```lua
coldbase.add_to_mem_pool = true
```
License
===========
ColdDB is distributed under the LGPLv2.1+ license.