Persistent data store

Introduction

If you want to store and retrieve information across interfaces cross-message this is module provides an easy way to do it.

We strongly recommend using the store2.lua module. However we will continue to maintain the store.lua module for backward compatibility.

This page shows examples using the store2.lua and the (historical) store.lua module to store key/value pairs in a persistent storage mechanism.

These modules use the embedded SQLite engine which provides a very convenient way to implement such a store.

If you have any questions please contact us at support@interfaceware.com.

Using the store2.lua Code [top]

  • Import the Persistent data store channel from the Builtin: Iguana Tools repository
  • Experiment with the code to find out how it works
  • Then add the module to your Translator project
  • Copy the require statement from the channel and add it at the top of your script
    Note: This module uses require to return a table
  • Adapt the code to your own requirements
  • Use local <store variable name> = store2.connect(“<store file name>”)
    For example: local MyStore = store2.connect(“store2.db”)
  • Use the following functions:
    • MyStore:put() to store information
    • MyStore:get() to get information
    • MyStore:info() to return all stored data
    • MyStore:reset() to empty the store (deletes all stored data)
    • MyStore:delete() to delete the store database file
  • Interactive scripting help is included for this module

This is the github code store2_example.lua example from this channel:

Note: We considered a single database with multiple tables to implement stores. However it would have made the code more complicated, and the only advantage is saving 1K disk space per table (so 1,000 stores would only use an extra megabyte).

Using the store.lua Code [top]

  • Import the Persistent key/value data store channel from the Builtin: Iguana Tools repository
  • Experiment with the code to find out how it works
  • Then add the module(s) to your Translator project
  • Copy the require statement from the channel and add it at the top of your script
    Note: This module uses require to return a table
  • Adapt the code to your own requirements
  • Use the following functions:
    • store.init('mystore.db') to specify the database file to use
      Note: If no file is specified the store.db file is used by default
    • store.put() to store information
    • store.get() to get information
    • store.getTableState() to return all stored data
    • store.resetTableState() to empty the store (deletes all stored data)
  • Interactive scripting help is included for this module

This is the github code store_example.lua example from this channel:

How it works [top]

Under the hood these modules use the specified SQLite database, which has a table called ‘store’ that contains the name=value pairs. However you don’t need to understand the internals to use the modules.

More information [top]

Leave A Comment?