Using in-memory databases in AIR

Adobe Integrated Runtime (AIR) has support for creating and using SQLite databases through the use of the SQLConnection class in the flash.data package. Using this package you can store a database on a user’s hard drive and even name it with any extension you’d like (registering your app with that extension will let you double click on your “database” file and open the app with that as a parameter, pretty slick).

One feature with the database package often overlooked is its ability to create and use in-memory databases. Using in-memory databases allows for faster read and write to the database and is perfect for operations such as building a code-completion lookup (someone going to rewrite Flex Builder in AIR? :), establishing a temporary search database of all the words in a list of documents that could be used for an autocomplete field, and any other situation where a database would be great to use but doesn’t need to be kept around between application launches.

To create an in-memory database simply leave out the file parameter of the database connection.

var db:SQLConnection = new SQLConnection();
db.open(); // no file is passed in

Then you run your database setup script to create your tables and your good to go.

One Response to “Using in-memory databases in AIR”

  1. Marco Sgnaolin Says:

    Simple and useful. Thanks.

Leave a Reply