Access to a database (SOLVED)

Is it possible to access a database (sqlite for example) saved into the app?

How is it saved into the app and what are your options to access it? (driver, web service, etc.) Sorry for the poor support, I haven’t really worked with databases since 12 years ago, I bet a lot has changed. :slight_smile:

There is a wrapper for SQLite. http://lua.sqlite.org/index.cgi/index

But it has to be wrapped as an extension for Defold.

1 Like

The db would be saved into the game app as a file (.db or .sqlite); I would need to open it, execute a query, and close it (I need a database for a words game)

Could I add autonomously this extension to Defold or has it to be deployed by Defold’s Development Team?

As a workaround, you can store all your data in JSON or plain Lua tables. And when you need to perform a search, perform either a direct for loop over the tables or turn them into dictionaries, eg

local words = {one = true, two = true, burger = true}

This manual describes how to add native code (aka native extensions).

I wouldn’t even call this a workaround. This is the way to go. If you have a database such as sqlite, then write a script that reads the content and stores it as json or a Lua table instead.

Have you created the database or someone else? Can you chose to store the data in some other format (such as JSON as suggested above)?

1 Like

Ok, for me my problem is solved.
Thanks.

I have the question if sys.save can in any hypothetic scenario corrupt a file? if the system shutdown unexpectedly.
is it ACID compliant save method like SQLITE databases?

The sys.save() function will write data to a temporary file and then do a rename to the actual file. This means that if the game is shut down while saving only the temporary file will be corrupt.

1 Like