Module-documentation

version 1.0.0
module: client-db
maintanance: Marco Asbreuk
home
all modules

database storage

This example uses a prompt to retrieve the name. The returnvalue is handled by the promise and will be shown by an alert.

Code-example:

<script src="itsabuild-min.js"></script>
<script>
    var databaseName = 'my_database',
        version = 1,
        tables = [
            {
                name: 'presidents',
                uniqueIndexes: ['name'],
                indexes: ['birth', 'lastName']
            }
        ],
        db, savePromise;

    db = new ITSA.DB(databaseName, version, tables);

    savePromise = db.set('president1', {name: 'Barack', lastName: 'Obama', 'birth': 1961});

    // wait for saving to be finished before reading it
    savePromise.then(
        function() {
            db.read('presidents', 'birth', 1961).then(
                function(president) {
                    ITSA.alert('found: '+president.name+' '+president.lastName);
                }
            ).catch(function(err) {ITSA.warn(err);});
        }
    ).catch(function(err) {ITSA.warn(err);})
    .finally(function() {
        // cleanup
        db.deleteDatabase();
    });
</script>
API Docs

Examples