Page 1 of 1

To all modders: databases & metadata in Lua - what you need?

PostPosted: Sat Mar 03, 2012 11:43
by jachoo
Hello modders!

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.

PostPosted: Sat Mar 03, 2012 15:21
by Death Dealer
what would be the advantage of having a database file in all the mods?

PostPosted: Sat Mar 03, 2012 19:01
by Jeija
Some database would be quite cool.
I may need one for the rollback mod and e.g. the mesecons mod.
I'm not sure if it is really necessary, I mean it also works without a database and keeps minetest more lightweight.

PostPosted: Sat Mar 03, 2012 20:31
by cosarara97
I think plain text files are easier to read. Can you put an example of a weird plain text file format?

PostPosted: Sun Mar 04, 2012 06:09
by randomproof
There is a module for LUA that can access a SQLite database(Google "lua sqlite" and you will see a few). I actually used it when I first made the node ownership mod, but I dropped it because it would require most people to build or install a library (DLL or .so) and most people here are not really up for that. So exporting the SQLite function from the builtin version would be nice, but in all possiblility I think using an actually database for these uses (less than 100 rows) would be overkill and likely slower.

FYI, the plain text format I use is really just lua code that loads a table into memory. (The one I used Different ones here)

PostPosted: Wed Mar 07, 2012 10:39
by RabbiBob

PostPosted: Wed Mar 07, 2012 13:33
by jordan4ibanez
^ditto

PostPosted: Wed Mar 07, 2012 15:50
by sfan5
meh...