<commit_before>/**
 * compiler_mysql.js
 * 2016
 *
 * Process mysql to models waterline
 */
var mysqldesc = require('mysqldesc');
var s = require("underscore.string");

var to = require('../../configs/to');
var view = require('../../genviews/view');
var async = require("async");

require('../save');
require('../../configs/color');

var FK_IDENTIFIER = "id";

exports.generate = function(config, folder_models, folder_controllers, folder_views) {
  // Describe connected database
  mysqldesc(config, function(err, data) {
    if (err) {
      console.log("ERROR: ", err);
    } else {
      var Models = [],
        count = 1;

      async.forEachOf(data, function(value, table, callback) {
        if (data.hasOwnProperty(table)) {
          console.log(color("[" + (count++) + " Generating]", "blue") + " " + table + " table ...");

          var attributes_sails = [],
            view_contents = [];
          mysqldesc.keyColumnUsage(config, config.database, table, function(err, data2) {
            for (var colum in data[table]) {
              //console.log(table + "=>" + colum);
              var reference_fk = undefined;
              if (data2[colum] && data2[colum]["REFERENCED_TABLE_NAME"]) {
                reference_fk = {
                  table: data2[colum].REFERENCED_TABLE_NAME,
                  column: data2[colum].REFERENCED_COLUMN_NAME
                };
                //console.log(table + "=>" + JSON.stringify(data2[colum], null, 4));
              }
              var attributes = data[table][colum];
              //console.log(attributes);
              var result = transpile(attributes, colum, reference_fk);
              view_contents.push(result.view_content);
              attributes_sails.push(result.model_content);
            }
            //console.log("-------------");
            Models.push({
              model_name: s.camelize(table).trim(),
              content: "attributes: { " + attributes_sails + " }",
              view_content: view_contents
            });
            //console.log(table + " = " + JSON.stringify(table, null, 4));
            callback(null, table);
          });
        }
      }, function(err) {
        console.log([Models.length, "tables"].join(" "));

        //console.log(Models);
        if (folder_views !== "" && folder_views) {
          view.generate(Models, folder_views);<commit_msg>Fixing mysql table atterbiuts generation https://github.com/juliandavidmr/sails-inverse-model/issues/13<commit_after>/**
 * compiler_mysql.js
 * 2016
 *
 * Process mysql to models waterline
 */
var mysqldesc = require('mysqldesc');
var s = require("underscore.string");

var to = require('../../configs/to');
var view = require('../../genviews/view');
var async = require("async");

require('../save');
require('../../configs/color');

var FK_IDENTIFIER = "id";

exports.generate = function(config, folder_models, folder_controllers, folder_views) {
  // Describe connected database
  mysqldesc(config, function(err, data) {
    if (err) {
      console.log("ERROR: ", err);
    } else {
      var Models = [],
        count = 1;

      async.forEachOf(data, function(value, table, callback) {
        if (data.hasOwnProperty(table)) {
          console.log(color("[" + (count++) + " Generating]", "blue") + " " + table + " table ...");
          var tableCloumnsData = data[table].columns ? data[table].columns : data[table];
          var attributes_sails = [],
            view_contents = [];
          mysqldesc.keyColumnUsage(config, config.database, table, function(err, data2) {
            for (var colum in tableCloumnsData) {
              //console.log(table + "=>" + colum);
              var reference_fk = undefined;
              if (data2[colum] && data2[colum]["REFERENCED_TABLE_NAME"]) {
                reference_fk = {
                  table: data2[colum].REFERENCED_TABLE_NAME,
                  column: data2[colum].REFERENCED_COLUMN_NAME
                };
                //console.log(table + "=>" + JSON.stringify(data2[colum], null, 4));
              }
              var attributes = tableCloumnsData[colum];
              //console.log(attributes);
              var result = transpile(attributes, colum, reference_fk);
              view_contents.push(result.view_content);
              attributes_sails.push(result.model_content);
            }
            //console.log("-------------");
            Models.push({
              model_name: s.camelize(table).trim(),
              content: "attributes: { " + attributes_sails + " }",
              view_content: view_contents
            });
            //console.log(table + " = " + JSON.stringify(table, null, 4));
            callback(null, table);
          });
        }
      }, function(err) {
        console.log([Models.length, "tables"].join(" "));

        //console.log(Models);
        if (folder_views !== "" && folder_views) {
          view.generate(Models, folder_views);
{'fraction_non_alphanumeric': 0.15949929335756108, 'fraction_numerical': 0.005653139511407228, 'mean_word_length': 2.1040100250626566, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3847257', 'n_tokens_mistral': 1460, 'n_tokens_neox': 1423, 'n_words': 259}