Jump to content

ips.utils.db

Description

Modern browsers provide a mechanism for storing persistent data directly on a user's computer, called localStorage. This utility exposes some methods for working with localStorage in IPS4. 

 

Example

ips.utils.db.set( 'myCategory', 'myKey', 'Hello world' );
ips.utils.db.get( 'myCategory', 'myKey' );
// -> Hello world
ips.utils.db.isEnabled();
// -> true
ips.utils.db.removeByType( 'myCategory' );
// -> 1

 

Methods

void set( string type, string key, mixed value )

Sets a new value, or overwrites an existing balue with the same type and key.

  • type
    Name of category in which to store this value. Categories are used for later retrieving sets of related values.
  • key
    The unique key for this value
  • value
    The value to be stored.

 

void get( string type [, string key ] )

Retrieves a previously set value. If no key is provided, all values in the type are returned.

  • type
    The category containing the key to fetch.
  • key
    The key of the value to fetch.

 

void remove( string type [, string key] )

Removes a previously set value. If no key is provided, all values in the type are removed.

  • type
    The category containing the key to remove.
  • key
    The key of the value to remove.

 

object getByType( string type )

Returns an object of all values in the category with the provided name.

  • type
    The category name

 

number removeByType( string type )

Removes all values from the category with the provided name, returning a count of the number of removed items.

  • type
    The category name

 

boolean isEnabled()

Returns a boolean indicating whether the localStorage utility is enabled in this user's browser.


  Report Guide


×
×
  • Create New...