data_store

module data_store

Implements app::data_store using shared_preferences

We use the shared preferences named "data_store" to store the data.

Dependencies

Clients

  • http_request: Android implementation of app:http_request
  • ui: Views and services to use the Android native user interface
  • ui_test: Test for app.nit's UI services

Concerns

  • app: app.nit, a framework for portable applications

from app::data_store

DataStore

redef class DataStore

Simple data storage facility

Write values with []= and read with [].

import linux::data_store # Needed for testing only

class A
    serialize

    var b = true
    var f = 1.234
end

var data_store = new DataStore
data_store["one"] = 1
data_store["str"] = "Some string"
data_store["a"] = new A

assert data_store["one"] == 1
assert data_store["str"] == "Some string"
assert data_store["a"].as(A).b
assert data_store["a"].as(A).f == 1.234
assert data_store["other"] == null

Set to null to clear a value.

data_store["one"] = null
assert data_store["one"] == null
Redefines
  • []: Get the object stored at key, or null if nothing is available
  • []=: Store value at key