Class: UWA.Storage

UWA/Storage. UWA.Storage

new UWA.Storage(options)

Cross-Platform Data Storage API providing methods for store persistent Key/Value database into the current platform.

Features:

  • NoSQL Key/Value storage
  • Multiple databases support
  • API support JSON Object value storage
  • Support expiration of data using <get> second argument.
Example
var myStorage = new UWA.Storage({
    adapter: 'Cookies',
    database: 'myDatabase'
});

// Store value
myStorage.set("toto", {
    "name": "titi"
});

// Read value
myStorage.get("toto");

// Read value that expire after one hour
myStorage.get("toto", 3600000);

// Clear value
myStorage.remove("toto");
Parameters
Name Type Description
options Object

Options hash or a option/value pair.

Mixes In

  • UWA.Class.Options
  • UWA.Class.Debug

Index

Members

currentAdapter :UWA.Storage.Adapter.Abstract

The current adapter to use for storage.

Type
  • UWA.Storage.Adapter.Abstract

Methods

initAvailableAdapters()

Initialize available Adapters.

isAvailableAdapter(adapterName) → {Boolean}

Check if Adapter is available by Adapter name.

Parameters
Name Type Description
adapterName String

Adapter name to check availability

Returns

true if available else false.

Type
Boolean

getAdapterInstance(adapterName) → {Object}

Get Adapter instance by Adapter name.

Parameters
Name Type Description
adapterName String

Adapter name requested instance

Returns

An instance of UWA.Storage.Adapter.Abstract.

Type
Object

detectAvailableAdapter()

Update options.availableAdapters by testing each adapter with <isAvailableAdapter>.

setCurrentAdapterFromDetected()

Update <currentAdapter> with values from <detectAvailableAdapter>

setCurrentAdapter()

Set the current storage adapter and connect it to current database.

store(key, value) → {Void}

Provide a simple interface for storing/getting values.

Example
// Store Key Value
myStorage.store("myKey", "Hello");
// Or get Key Value
myStorage.store("myKey");
Parameters
Name Type Description
key String

The key of value to store/get

value String

The value of value to store

Returns

The current key value.

Type
Void

remove(key) → {Void}

Provide a simple interface for removing values.

Parameters
Name Type Description
key String

The key of value to remove

Returns

Previous key value.

Type
Void

get(key, time) → {Void}

Alias access for reading key value.

Parameters
Name Type Description
key String

The key of value to get

time String

The key expiration time in milliseconds

Returns

Current key value.

Type
Void

set(key, value) → {Void}

Alias access for store key value.

Parameters
Name Type Description
key String

The key of value to store

value String

The value of value to store

Returns

Current key value.

Type
Void

getAll() → {Array}

Get All keys values.

Returns

Current keys values indexed by Key.

Type
Array

safeStore(value) → {String}

Parse a value as JSON before its stored.

Parameters
Name Type Description
value Void

Value to store

Returns

Clean string.

Type
String

safeResurrect(value) → {Void}

Restores JSON'd values before returning.

Parameters
Name Type Description
value Void

Value to restore

Returns

Restored String/Object.

Type
Void

getLastUpdateDate() → {Number}

Get Last update timestamp.

Returns

Last update timestamp.

Type
Number