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

jachoo
Member
 
Posts: 45
Joined: Mon Sep 12, 2011 08:29

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

by jachoo » Sat Mar 03, 2012 11:43

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.
Last edited by jachoo on Sat Mar 03, 2012 11:44, edited 1 time in total.
 

User avatar
Death Dealer
Member
 
Posts: 1379
Joined: Wed Feb 15, 2012 18:46

by Death Dealer » Sat Mar 03, 2012 15:21

what would be the advantage of having a database file in all the mods?
Keep calm and code python^_^
 

User avatar
Jeija
Member
 
Posts: 686
Joined: Fri Dec 23, 2011 21:46

by Jeija » Sat Mar 03, 2012 19:01

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.
Redstone for minetest: Mesecons (mesecons.net)
 

cosarara97
Member
 
Posts: 180
Joined: Tue Nov 01, 2011 18:53

by cosarara97 » Sat Mar 03, 2012 20:31

I think plain text files are easier to read. Can you put an example of a weird plain text file format?
:D
 

randomproof
Member
 
Posts: 214
Joined: Thu Nov 17, 2011 06:31

by randomproof » Sun Mar 04, 2012 06:09

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)
Last edited by randomproof on Sun Mar 04, 2012 06:13, edited 1 time in total.
 

User avatar
RabbiBob
Member
 
Posts: 335
Joined: Sat Jan 28, 2012 22:40

by RabbiBob » Wed Mar 07, 2012 10:39

 

User avatar
jordan4ibanez
Member
 
Posts: 1865
Joined: Tue Sep 27, 2011 18:44
GitHub: jordan4ibanez
IRC: jordan4ibanez
In-game: jordan4ibanez

by jordan4ibanez » Wed Mar 07, 2012 13:33

^ditto
If you can think it, you can make it.
 

User avatar
sfan5
Member
 
Posts: 3636
Joined: Wed Aug 24, 2011 09:44
GitHub: sfan5
IRC: sfan5

by sfan5 » Wed Mar 07, 2012 15:50

meh...
Mods: Mesecons | WorldEdit | Nuke
Minetest builds for Windows (32-bit & 64-bit)
 


Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 16 guests

cron