This post was originally published at Tutorial Treasury: Working with files and data

Many apps need to manage data, whether it be saving user settings, keeping track of game statistics, or saving a list of inventory items that the player has. In Corona, there are three basic ways to store/retrieve data:

  • Basic files — Simple text or binary files which are written to your app’s sandboxed data storage folders. With these, you can save and retrieve simple data locally.
  • Local databases (SQLite3) — These provide more of a formal structure to your data, allowing you to set up complex relations, fetch a limited amount of data based on some criteria, and easily update data records without having to rewrite the entire data set.
  • Hosted databases — Hosted database solutions extend the concept of a searchable database to a remote server, making data available to all of the app’s users, not just the local user.

Guides

No matter which method of data storage you use, an essential topic of understanding is how to read and write files from/to the device’s local storage. Even if you are retrieving data from a hosted database, it will typically need to be managed locally. The Reading and Writing Files guide outlines this process.

Video tutorials

The following video tutorials cover the basics of managing data in basic files or local SQLite databases:

Tutorials

Database access using SQLite

In this tutorial, learn all about accessing data in an SQLite database, from creation of the database to adding/updating records to retrieving data.

Saving and loading Lua tables with JSON

In this tutorial, learn how two simple functions can be used to save a table of data to local storage and retrieve the data later, using the power of JSON under the hood.

LuaFileSystem (LFS)

In this tutorial, learn how to use the LuaFileSystem (LFS) API calls to work with directories and organize your app’s data files.

Initializing a writable SQLite database

Some apps include a pre-built SQLite3 database which needs to be updated after the app is installed. This tutorial shows you how to properly copy the database file to a writable area and access its data within the app.

Downloading JSON data from MySQL

This tutorial shows you how to access a remote MySQL database, retrieve data, and return it to your Corona-based app.

Further reading

  • io documentation
  • lfs documentation
  • json documentation
  • sqlite3 documentation

Sample code

Conclusion

These resources should empower you to store, manage, and retrieve the data that your app needs, either locally or remotely in a variety of formats.


Read more – 

This post was originally published at Tutorial Treasury: Working with files and data