Re: Can I work with databases?
Posted: Wed Apr 29, 2015 7:39 pm
Remember that Luasocket is included in LÖVE, there's no need to search for it and download it
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!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.
Thank you, I didn't notice it!Nixola wrote:Remember that Luasocket is included in LÖVE, there's no need to search for it and download it
Not really my case, but it's good to know. Thanks for answering!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.
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.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!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.
The is how minecraft stores worlds on client and server.
So database on client has it's uses.
Yep your right it is very important to note that is perhaps the biggest use for a database. 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.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).