Can I work with databases?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Can I work with databases?

Post by Nixola »

Remember that Luasocket is included in LÖVE, there's no need to search for it and download it
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
I~=Spam
Party member
Posts: 206
Joined: Fri Dec 14, 2012 11:59 pm

Re: Can I work with databases?

Post by I~=Spam »

bobbyjones wrote:You should use files on client. And database on backend. And using a database for high scores is a wonderful idea. If you must use a database on client you can use SQLite3. P.S you shouldn't need one for client. Please don't do it lol.
If one plans to store large amounts of data that must be fetched quickly a database is essential. What makes databases (even on client) so useful is that only a part of the file needs to be read. When a table of values is loaded in lua from a file the entire contents of the file must be loaded into memory for reading. What if the file is 100MB or even 1GB but you only need 1KB of data? That is a HUGE waste because the 100MB or 1GB of data is being freed immediately after use and that memory wasn't even necessary!

The is how minecraft stores worlds on client and server.

So database on client has it's uses.
My Tox ID: 0F1FB9170B94694A90FBCF6C4DDBDB9F58A9E4CDD0B4267E50BF9CDD62A0F947E376C5482610
BGBgus
Prole
Posts: 10
Joined: Wed Apr 29, 2015 7:47 am
Location: Terrassa, Barcelona, Spain

Re: Can I work with databases?

Post by BGBgus »

Nixola wrote:Remember that Luasocket is included in LÖVE, there's no need to search for it and download it
Thank you, I didn't notice it!
I~=Spam wrote: If one plans to store large amounts of data that must be fetched quickly a database is essential. What makes databases (even on client) so useful is that only a part of the file needs to be read. When a table of values is loaded in lua from a file the entire contents of the file must be loaded into memory for reading. What if the file is 100MB or even 1GB but you only need 1KB of data? That is a HUGE waste because the 100MB or 1GB of data is being freed immediately after use and that memory wasn't even necessary!

The is how minecraft stores worlds on client and server.

So database on client has it's uses.
Not really my case, but it's good to know. Thanks for answering!
User avatar
I~=Spam
Party member
Posts: 206
Joined: Fri Dec 14, 2012 11:59 pm

Re: Can I work with databases?

Post by I~=Spam »

This might be what you are looking for: http://www.keplerproject.org/luasql/
or this (I like sqlite better): http://lua.sqlite.org/index.cgi/index
My Tox ID: 0F1FB9170B94694A90FBCF6C4DDBDB9F58A9E4CDD0B4267E50BF9CDD62A0F947E376C5482610
User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

Re: Can I work with databases?

Post by arampl »

SQLite is supreme tool.
And not only you don't need to load entire file.
You don't need to do any file parsing which is really a hell.
And you can always store all data as a simple txt sql scenarios with comments.
Even BG:EE now uses such approach to work with settings.
BGBgus
Prole
Posts: 10
Joined: Wed Apr 29, 2015 7:47 am
Location: Terrassa, Barcelona, Spain

Re: Can I work with databases?

Post by BGBgus »

Well, guys, thank you all, I'll keep in mind all your advices and I already saved all those links you shared with me. Great community, in less than a day I have, not only a solution, but a lot of them.

Again, thank you, guys!
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: Can I work with databases?

Post by T-Bone »

I~=Spam wrote:
bobbyjones wrote:You should use files on client. And database on backend. And using a database for high scores is a wonderful idea. If you must use a database on client you can use SQLite3. P.S you shouldn't need one for client. Please don't do it lol.
If one plans to store large amounts of data that must be fetched quickly a database is essential. What makes databases (even on client) so useful is that only a part of the file needs to be read. When a table of values is loaded in lua from a file the entire contents of the file must be loaded into memory for reading. What if the file is 100MB or even 1GB but you only need 1KB of data? That is a HUGE waste because the 100MB or 1GB of data is being freed immediately after use and that memory wasn't even necessary!

The is how minecraft stores worlds on client and server.

So database on client has it's uses.
It's true that databases have uses in clients, but your argument is a bit strange. Just because you're not using a database doesn't mean you're not structuring your data at all. Just put that huge data in smaller files, structured logically, and it will work just fine.

The main advantage of databases is that they make it easy to structure and search through data efficiently, not that they allow "more data" (because data can be well structured without a database).
User avatar
I~=Spam
Party member
Posts: 206
Joined: Fri Dec 14, 2012 11:59 pm

Re: Can I work with databases?

Post by I~=Spam »

T-Bone wrote:It's true that databases have uses in clients, but your argument is a bit strange. Just because you're not using a database doesn't mean you're not structuring your data at all. Just put that huge data in smaller files, structured logically, and it will work just fine.

The main advantage of databases is that they make it easy to structure and search through data efficiently, not that they allow "more data" (because data can be well structured without a database).
Yep your right it is very important to note that is perhaps the biggest use for a database. :megagrin: To the person I was responding to I thought that they would likely respond something like "I can organize my data in an xml file or a lua table in a file." So I just skipped that altogether and assumed that they didn't know anything about databases. :roll:

Any yeah thanks for pointing that out... I meant to mention that in my post. :P
My Tox ID: 0F1FB9170B94694A90FBCF6C4DDBDB9F58A9E4CDD0B4267E50BF9CDD62A0F947E376C5482610
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest