src/CRUD.SqliteAdapter.js
function createTables() {
            return Promise.all(Object.keys(CRUD.EntityManager.entities).map(function(entityName) {
                var entity = CRUD.EntityManager.entities[entityName];
                if (tables.indexOf(entity.table) == -1) {
                    if (!entity.createStatement) {
                        throw "No create statement found for " + entity.getType() + ". Don't know how to create table.";
                    }
                    return db.execute(entity.createStatement).then(function() {
                        tables.push(entity.table);
                        localStorage.setItem('database.version.' + entity.table, ('migrations' in entity) ? Math.max.apply(Math, Object.keys(entity.migrations)) : 1);
                        CRUD.log(entity.table + " table created.");
                        return entity;
                    }, function(err) {
                        CRUD.log("Error creating " + entity.table, err, entity.createStatement);
                        throw "Error creating table: " + entity.table;
                    }).then(createFixtures).then(function() {
                        CRUD.log("Table created and fixtures inserted for ", entityName);
                        return;
                    });
                }
                return;
            }));
        }
function createTables() {
            return Promise.all(Object.keys(CRUD.EntityManager.entities).map(function(entityName) {
                var entity = CRUD.EntityManager.entities[entityName];
                if (tables.indexOf(entity.table) == -1) {
                    if (!entity.createStatement) {
                        throw "No create statement found for " + entity.getType() + ". Don't know how to create table.";
                    }
                    return db.execute(entity.createStatement).then(function() {
                        tables.push(entity.table);
                        localStorage.setItem('database.version.' + entity.table, ('migrations' in entity) ? Math.max.apply(Math, Object.keys(entity.migrations)) : 1);
                        CRUD.log(entity.table + " table created.");
                        return entity;
                    }, function(err) {
                        CRUD.log("Error creating " + entity.table, err, entity.createStatement);
                        throw "Error creating table: " + entity.table;
                    }).then(createFixtures).then(function() {
                        CRUD.log("Table created and fixtures inserted for ", entityName);
                        return;
                    });
                }
                return;
            }));
        }
function createTables ( ) { return Promise . all ( Object . keys ( CRUD . EntityManager . entities ) . map ( function ( entityName ) { var entity = CRUD . EntityManager . entities [ entityName ] ; if ( tables . indexOf ( entity . table ) == - 1 ) { if ( ! entity . createStatement ) { throw "No create statement found for " + entity . getType ( ) + ". Don't know how to create table." ; } return db . execute ( entity . createStatement ) . then ( function ( ) { tables . push ( entity . table ) ; localStorage . setItem ( 'database.version.' + entity . table , ( 'migrations' in entity ) ? Math . max . apply ( Math , Object . keys ( entity . migrations ) ) : 1 ) ; CRUD . log ( entity . table + " table created." ) ; return entity ; } , function ( err ) { CRUD . log ( "Error creating " + entity . table , err , entity . createStatement ) ; throw "Error creating table: " + entity . table ; } ) . then ( createFixtures ) . then ( function ( ) { CRUD . log ( "Table created and fixtures inserted for " , entityName ) ; return ; } ) ; } return ; } ) ) ; }
Iterate the list of registered entities and creates their tables if they don't exist.
Run the migrations when needed if the table version is out of sync
@return {void} void
Iterate the list of registered entities and creates their tables if they don t exist . Run the migrations when needed if the table version is out of sync