PersistentStorage v0.10.1 PersistentStorage View Source
Stores and retrieves terms from small flat files on embedded systems.
PersistentStorage
is intended for trivial persistent storage of basic system
and application configuration information on embedded systems. It is not
intended to be a replacement for dets, sqlite, or many other far more capable
databases. It favors simplicity and robustness over performance and
capability.
Configuration
Define one or more storage areas in your config.exs as follows...
# my_app/config/config.exs
...
config :persistent_storage, tables: [
settings: [path: "/root/storage/settings"],
provisioning: [path: "/boot/provisioning"]
]
The :path
option is required is used to specify the filesystem path where
files will be written.
Usage
# write to settings (this will create the file at
# /root/storage/settings/network
iex> PersistentStorage.put :settings, :network, %{
ip_address: {192,168,1,100}, mode: :static
}
# later, we can read it (this reads from ets cache if possible)
iex> PersistentStorage.get :settings, :network
%{ip_address: {192,168,1,100}, mode: :static}
# read some provisioning data -- for purposes of this example, we
# assume it was written when device was first flashed)
iex> PersistentStorage.get :provisioning, :device_data
[serial_number: "302F1010", mfg_timestamp: "2016-05-04T03:28:35.279977Z"]
Link to this section Summary
Functions
Removes an entry from storage.
Return the value associated with the given key in the specified storage.
Puts a single key and its associated value into storage.
Put a single key and its associated value into storage.
OTP Application start callback.
Link to this section Types
Link to this section Functions
Removes an entry from storage.
PersistentStorage.delete :network_settings, :router_ip_address
Return the value associated with the given key in the specified storage.
If the storage storage does not contain a key, returns the value of default
(or nil if default
is not provided).
Uses the ets cache if possible, otherwise reads from disk.
Examples
PersistentStorage.get :network_settings, :router_ip_address
PersistentStorage.get :network_settings, :router_ip_address, {0,0,0,0}
Puts a single key and its associated value into storage.
This is simple syntactic sugar for put/3 to allow specifying arguments with a keyword list consisting of a single key/value pair.
Example
PersistentStorage.put :network_settings, router_ip_address: {192,168,15,1}
Put a single key and its associated value into storage.
Example
PersistentStorage.put :network_settings, :router_ip_address, {192,168,15,1}
OTP Application start callback.
Starts a supervisor with only one child process to own ETS tables.