SqlStorage
SqlStorage uses SQLite or WebSQL (development only!) to store data in a persistent SQL store on the filesystem.
This is the preferred storage engine, as data will be stored in appropriate app storage, unlike Local Storage which is treated differently by the OS.
For convenience, the engine supports key/value storage for simple get/set and blob
storage. The full SQL engine is exposed underneath through the query
method.
Usage
let storage = new Storage(SqlStorage, options);
storage.set('name', 'Max');
storage.get('name').then((name) => {
});
// Sql storage also exposes the full engine underneath
storage.query('insert into projects(name, data) values("Cool Project", "blah")');
storage.query('select * from projects').then((resp) => {})
The SqlStorage
service supports these options:
{
name: the name of the database (__ionicstorage by default)
backupFlag: // where to store the file, default is BACKUP_LOCAL which DOES NOT store to iCloud. Other options: BACKUP_LIBRARY, BACKUP_DOCUMENTS
existingDatabase: whether to load this as an existing database (default is false)
}
Static Members
BACKUP_LOCAL()
BACKUP_LIBRARY()
BACKUP_DOCUMENTS()
Instance Members
query(query, params)
Perform an arbitrary SQL operation on the database. Use this method to have full control over the underlying database through SQL operations like SELECT, INSERT, and UPDATE.
Param | Type | Details |
---|---|---|
query |
string
|
the query to run |
params |
array
|
the additional params to use for query placeholders |
Promise
that resolves or rejects with an object of the form { tx: Transaction, res: Result (or err)}
get(key)
Get the value in the database identified by the given key.
Param | Type | Details |
---|---|---|
key |
string
|
the key |
Promise
that resolves or rejects with an object of the form { tx: Transaction, res: Result (or err)}
set(key, value)
Set the value in the database for the given key. Existing values will be overwritten.
Param | Type | Details |
---|---|---|
key |
string
|
the key |
value |
string
|
The value (as a string) |
Promise
that resolves or rejects with an object of the form { tx: Transaction, res: Result (or err)}
remove(key)
Remove the value in the database for the given key.
Param | Type | Details |
---|---|---|
key |
string
|
the key |
Promise
that resolves or rejects with an object of the form { tx: Transaction, res: Result (or err)}