lib/index.js
function generateModelFiles(db, next) {
    var q, templateTable, allNamingErrors = [];

    q = async.queue(function (task, workerCallback) {
        var output = getConfig('output.beautify') ? beautify(task.content, { indent_size: getConfig('output.indent'), preserve_newlines: getConfig('output.preserveNewLines') }) : task.content;
        fs.writeFile(path.join(getConfig('output.folder'), 'definition-files', getFileName(task.table)), output, workerCallback);
        if (getConfig('output.log')) { logger.info('(Created) File \'' + getFileName(task.table) + '\' is created for model \'' + getModelNameFor(task.table) + '\''); }
    }, 4);

    db.schemas(function (schema) {
        schema.tables(function (table) {
            var namingError = '';
            logger.debug('Now parsing table: %s', table.name());
            if (getSpecificConfig(table.name(), 'generate.hasManyThrough') && getSpecificConfig(table.name(), 'generate.belongsToMany')) {
                next(new Error('Configuration error: Both "generate.hasManyThrough" and "generate.belongsToMany" configuration is set to be true for table "' + table.schema().name() + '.' + table.name() + '". They cannot be true at the same time.'));
            }

            if (shouldSkip(table, 'table')) { return; }
            templateTable           = getTableOptions(table);
            table.columns(function (column) {
                templateTable.columns.push(getColumnDetails(column));
            });
            table.hasManies(function (hasMany) {
                if (shouldSkip(hasMany.referencesTable(), 'relation')) { return; }
                templateTable.hasManies.push(getHasManyDetails(hasMany));
            });
            table.hasManyThroughs(function (hasManyThrough) {
                if (getSpecificConfig(table.name(), 'generate.addRelationNameToManyToMany') && getSpecificConfig(table.name(), 'generate.addTableNameToManyToMany')) {
                    next(new Error('Configuration error: Both "generate.addRelationNameToManyToMany" and "generate.addTableNameToManyToMany" configuration is set to be true for table "' + table.schema().name() + '.' + table.name() + '". They cannot be true at the same time.'));
                }

                if (shouldSkip(hasManyThrough.referencesTable(), 'relation') || shouldSkip(hasManyThrough.through(), 'relation')) { return; }
                if (getSpecificConfig(table.name(), 'generate.hasManyThrough')) {
                    templateTable.hasManies.push(getHasManyDetails(hasManyThrough)); // has many throughs are deprecated after Sequelize 2.0 RC3
                }
                if (getSpecificConfig(table.name(), 'generate.belongsToMany')) {
                    templateTable.belongsToManies.push(getBelongsToManyDetails(hasManyThrough));
                }
            });
            table.foreignKeyConstraints(function (fkc) {
                if (shouldSkip(fkc.referencesTable(), 'relation')) { return; }
                templateTable.belongsTos.push(getBelongsToDetails(fkc));
            });
            templateTable.relations = templateTable.hasManies.concat(templateTable.belongsTos, templateTable.belongsToManies);

            namingError = validateNaming(templateTable);

            if (namingError) {
                allNamingErrors.push(namingError);
            }

            template('index', {
                table: templateTable,
                mainScript: path.join(getConfig('output.folder'), 'index.js'),
                warning: getConfig('output.warning'),
                dataTypeVariable: getSpecificConfig(table.name(), 'generate.dataTypeVariable')
            }, function (err, result) {
                if (err) { next(err); }
                q.push({content: result, table: table}, function (err) { if (err) { next(err); } });
            });
        });
    });

    q.drain = function () {
        if (allNamingErrors.length > 0) {
            next(new Error('There are naming errors. Either set "generate.addRelationNameToManyToMany" true in configuration or rename your relations.\n' + allNamingErrors.join('\n')));
        } else {
            next(null);
        }
    };
}
function generateModelFiles(db, next) {
    var q, templateTable, allNamingErrors = [];

    q = async.queue(function (task, workerCallback) {
        var output = getConfig('output.beautify') ? beautify(task.content, { indent_size: getConfig('output.indent'), preserve_newlines: getConfig('output.preserveNewLines') }) : task.content;
        fs.writeFile(path.join(getConfig('output.folder'), 'definition-files', getFileName(task.table)), output, workerCallback);
        if (getConfig('output.log')) { logger.info('(Created) File \'' + getFileName(task.table) + '\' is created for model \'' + getModelNameFor(task.table) + '\''); }
    }, 4);

    db.schemas(function (schema) {
        schema.tables(function (table) {
            var namingError = '';
            logger.debug('Now parsing table: %s', table.name());
            if (getSpecificConfig(table.name(), 'generate.hasManyThrough') && getSpecificConfig(table.name(), 'generate.belongsToMany')) {
                next(new Error('Configuration error: Both "generate.hasManyThrough" and "generate.belongsToMany" configuration is set to be true for table "' + table.schema().name() + '.' + table.name() + '". They cannot be true at the same time.'));
            }

            if (shouldSkip(table, 'table')) { return; }
            templateTable           = getTableOptions(table);
            table.columns(function (column) {
                templateTable.columns.push(getColumnDetails(column));
            });
            table.hasManies(function (hasMany) {
                if (shouldSkip(hasMany.referencesTable(), 'relation')) { return; }
                templateTable.hasManies.push(getHasManyDetails(hasMany));
            });
            table.hasManyThroughs(function (hasManyThrough) {
                if (getSpecificConfig(table.name(), 'generate.addRelationNameToManyToMany') && getSpecificConfig(table.name(), 'generate.addTableNameToManyToMany')) {
                    next(new Error('Configuration error: Both "generate.addRelationNameToManyToMany" and "generate.addTableNameToManyToMany" configuration is set to be true for table "' + table.schema().name() + '.' + table.name() + '". They cannot be true at the same time.'));
                }

                if (shouldSkip(hasManyThrough.referencesTable(), 'relation') || shouldSkip(hasManyThrough.through(), 'relation')) { return; }
                if (getSpecificConfig(table.name(), 'generate.hasManyThrough')) {
                    templateTable.hasManies.push(getHasManyDetails(hasManyThrough)); // has many throughs are deprecated after Sequelize 2.0 RC3
                }
                if (getSpecificConfig(table.name(), 'generate.belongsToMany')) {
                    templateTable.belongsToManies.push(getBelongsToManyDetails(hasManyThrough));
                }
            });
            table.foreignKeyConstraints(function (fkc) {
                if (shouldSkip(fkc.referencesTable(), 'relation')) { return; }
                templateTable.belongsTos.push(getBelongsToDetails(fkc));
            });
            templateTable.relations = templateTable.hasManies.concat(templateTable.belongsTos, templateTable.belongsToManies);

            namingError = validateNaming(templateTable);

            if (namingError) {
                allNamingErrors.push(namingError);
            }

            template('index', {
                table: templateTable,
                mainScript: path.join(getConfig('output.folder'), 'index.js'),
                warning: getConfig('output.warning'),
                dataTypeVariable: getSpecificConfig(table.name(), 'generate.dataTypeVariable')
            }, function (err, result) {
                if (err) { next(err); }
                q.push({content: result, table: table}, function (err) { if (err) { next(err); } });
            });
        });
    });

    q.drain = function () {
        if (allNamingErrors.length > 0) {
            next(new Error('There are naming errors. Either set "generate.addRelationNameToManyToMany" true in configuration or rename your relations.\n' + allNamingErrors.join('\n')));
        } else {
            next(null);
        }
    };
}
function generateModelFiles ( db , next ) { var q , templateTable , allNamingErrors = [ ] ; q = async . queue ( function ( task , workerCallback ) { var output = getConfig ( 'output.beautify' ) ? beautify ( task . content , { indent_size : getConfig ( 'output.indent' ) , preserve_newlines : getConfig ( 'output.preserveNewLines' ) } ) : task . content ; fs . writeFile ( path . join ( getConfig ( 'output.folder' ) , 'definition-files' , getFileName ( task . table ) ) , output , workerCallback ) ; if ( getConfig ( 'output.log' ) ) { logger . info ( '(Created) File \'' + getFileName ( task . table ) + '\' is created for model \'' + getModelNameFor ( task . table ) + '\'' ) ; } } , 4 ) ; db . schemas ( function ( schema ) { schema . tables ( function ( table ) { var namingError = '' ; logger . debug ( 'Now parsing table: %s' , table . name ( ) ) ; if ( getSpecificConfig ( table . name ( ) , 'generate.hasManyThrough' ) && getSpecificConfig ( table . name ( ) , 'generate.belongsToMany' ) ) { next ( new Error ( 'Configuration error: Both "generate.hasManyThrough" and "generate.belongsToMany" configuration is set to be true for table "' + table . schema ( ) . name ( ) + '.' + table . name ( ) + '". They cannot be true at the same time.' ) ) ; } if ( shouldSkip ( table , 'table' ) ) { return ; } templateTable = getTableOptions ( table ) ; table . columns ( function ( column ) { templateTable . columns . push ( getColumnDetails ( column ) ) ; } ) ; table . hasManies ( function ( hasMany ) { if ( shouldSkip ( hasMany . referencesTable ( ) , 'relation' ) ) { return ; } templateTable . hasManies . push ( getHasManyDetails ( hasMany ) ) ; } ) ; table . hasManyThroughs ( function ( hasManyThrough ) { if ( getSpecificConfig ( table . name ( ) , 'generate.addRelationNameToManyToMany' ) && getSpecificConfig ( table . name ( ) , 'generate.addTableNameToManyToMany' ) ) { next ( new Error ( 'Configuration error: Both "generate.addRelationNameToManyToMany" and "generate.addTableNameToManyToMany" configuration is set to be true for table "' + table . schema ( ) . name ( ) + '.' + table . name ( ) + '". They cannot be true at the same time.' ) ) ; } if ( shouldSkip ( hasManyThrough . referencesTable ( ) , 'relation' ) || shouldSkip ( hasManyThrough . through ( ) , 'relation' ) ) { return ; } if ( getSpecificConfig ( table . name ( ) , 'generate.hasManyThrough' ) ) { templateTable . hasManies . push ( getHasManyDetails ( hasManyThrough ) ) ; // has many throughs are deprecated after Sequelize 2.0 RC3 } if ( getSpecificConfig ( table . name ( ) , 'generate.belongsToMany' ) ) { templateTable . belongsToManies . push ( getBelongsToManyDetails ( hasManyThrough ) ) ; } } ) ; table . foreignKeyConstraints ( function ( fkc ) { if ( shouldSkip ( fkc . referencesTable ( ) , 'relation' ) ) { return ; } templateTable . belongsTos . push ( getBelongsToDetails ( fkc ) ) ; } ) ; templateTable . relations = templateTable . hasManies . concat ( templateTable . belongsTos , templateTable . belongsToManies ) ; namingError = validateNaming ( templateTable ) ; if ( namingError ) { allNamingErrors . push ( namingError ) ; } template ( 'index' , { table : templateTable , mainScript : path . join ( getConfig ( 'output.folder' ) , 'index.js' ) , warning : getConfig ( 'output.warning' ) , dataTypeVariable : getSpecificConfig ( table . name ( ) , 'generate.dataTypeVariable' ) } , function ( err , result ) { if ( err ) { next ( err ) ; } q . push ( { content : result , table : table } , function ( err ) { if ( err ) { next ( err ) ; } } ) ; } ) ; } ) ; } ) ; q . drain = function ( ) { if ( allNamingErrors . length > 0 ) { next ( new Error ( 'There are naming errors. Either set "generate.addRelationNameToManyToMany" true in configuration or rename your relations.\n' + allNamingErrors . join ( '\n' ) ) ) ; } else { next ( null ) ; } } ; }
Generates all model files.
@private
@param {object} db - pg-structure db object
@param {function} next - Callback to execute.
Generates all model files .