Class wink.api.Storage
Implements a access layer to the local storage mechanism. Must be used with a DB plugin (e.g.: SafariDB, GearsDB...)
- Defined in: storage.js
| Constructor Attributes | Constructor Name and Description |
|---|---|
| Compatibility list | Supported platforms / browsers |
|---|---|
|
iOS2, iOS3, iOS4, iOS5, iOS6, Android 1.1, Android 1.5, Android 2.1, Android 2.2, Android 2.3, Android 3.0, Android 3.1, Android 4.0, BlackBerry 6, BlackBerry 7, Bada 1.0
|
Method Summary
Class Detail
wink.api.Storage()
var descriptor =
{
name: 'dummy_db',
tables:
{
contacts:
{
lastname : wink.api.storage.fieldtypes.TEXT,
firstname : wink.api.storage.fieldtypes.TEXT,
age : wink.api.storage.fieldtypes.INTEGER,
phone : wink.api.storage.fieldtypes.TEXT,
email : wink.api.storage.fieldtypes.TEXT
}
}
}
storage = new wink.api.Storage();
storage.connect(descriptor);
- See:
- Test page
Field Detail
{boolean}
dbAvailable
True if a local storage is available, false otherwise
{integer}
uId
Unique identifier
Method Detail
-
connect(descriptor)Connection/creation to/of the specified database
//Note: fieldTypes are defined in the DatabaseFieldTypes object (INTEGER, TEXT, BLOB, BLOB_B64, REAL) //Descriptor example: descriptor = { name = the name of the database tables: { tableName1: { fieldName1 : fieldType1, fieldName2 : fieldType2, fieldName3 : fieldType3 }, tableName2: { fieldName1 : fieldType1, fieldName2 : fieldType2, fieldName3 : fieldType3 } } }- Parameters:
- {object} descriptor
- The database descriptor
-
createTables()Create the tables described in the descriptor (erase all the previously stored datas)
-
emptyDatabase()Remove all the datas and the tables from the database
-
getById(tableName, entryId, callback)Get the entry with the specified id
- Parameters:
- {string} tableName
- The name of the table
- {integer} entryId
- The id of the element to get
- {object|function} callback
- The callback to invoke after the result
-
getList(tableName, callback)Get all the entries of a table
- Parameters:
- {string} tableName
- The name of the table
- {object|function} callback
- The callback to invoke after the result
-
getListByField(tableName, fieldName, fieldValue, callback)Get all the entries with the specified value in the specified field
- Parameters:
- {string} tableName
- The name of the table
- {string} fieldName
- The search field criteria
- {string} fieldValue
- The search field value
- {object|function} callback
- The callback to invoke after the result
-
getTableList(callback)Get the list of all the tables in the database
- Parameters:
- {object|function} callback
- The callback to invoke after the result
-
insert(tableName, entry, callback)Insert a new entry into a database table
- Parameters:
- {string} tableName
- The name of the table
- {object} entry
- An object representing an element of the table
- {object|function} callback Optional
- The callback to invoke after the result
-
remove(tableName, entryId, callback)Remove a particular entry
- Parameters:
- {string} tableName
- The name of the table
- {integer} entryId
- The id of the element to remove
- {object|function} callback Optional
- The callback to invoke after the result
-
update(tableName, entry, callback)Update a particular entry
- Parameters:
- {string} tableName
- The name of the table
- {object} entry
- An object representing an element of the table and containing the id of the element to update
- {object|function} callback Optional
- The callback to invoke after the result