I saw that some mods (e.g. portals, node ownership) use quite weird plain text file formats.
I'm working on a database interface for Lua. Main idea is that each mod may create a database in its own directory. It would be something like "world/mods_data/<mod_name>/data.sqlite" or sth similar.
See what i have already done:
Quick help on database accessing (not real code, ofc)
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
minetest.get_db(database_name) -> database object
database object:
: get_table(name,key_type [,data_type]) -> table object
table object:
: get(key [,data_type]) -> value/nil
: set(key, data [,data_type])
: remove(key)
possible types: string, int, bool, double, v3s16, v3f, v3fpos
Example (real code)
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
-- create/load a database
db = minetest.get_db("my_database")
-- create/load a table from db with v3s16 keys, and bool data
tab = db:get_table("my_table1","v3s16","bool")
-- get value with key (1,2,3)
value = tab:get({x=1,y=2,=3})
-- set value 'true' to (6,6,6)
tab:set({x=6,y=6,z=6},true)
-- remove (1,2,3) record
tab:remove({x=1,y=2,z=3})
-- create/load a table from db with string keys, and any data type
tab2 = db:get_table("my_table2","v3s16")
-- get record with key "jachoo:real_name", and assume its value is a string
real_name = tab2:get("jachoo:real_name","string")
-- get record with key "jachoo:age", and assume its value is an int
age = tab2:get("jachoo:age","int")
-- set value for "jachoo:is_active" to bool 'true'
tab2:set("jachoo:is_active",true,"bool")
-- remove value for "jachoo:temporary"
tab2:remove("jachoo:temporary")
I have many ideas how to improve and extend that, but I'd rather listen to you. Tell me exactly what you think you will need from such database interface.