<commit_before>/****************************
 *
 * Loads and exposes schema from database
 */

/// <reference path="../typings/index.d.ts"/>

import util = require('./util');

import sequelize = require('sequelize');
var Sequelize : sequelize.SequelizeStatic = require("sequelize");
import fs = require('fs');
import _ = require('lodash');
import ChangeCase = require('change-case');

const DEFAULT_CASE_TYPE = 'pascalCase';
var naming : any;

export class Schema {

    public static idSuffix : string = "id"; // NOTE: Must be LOWER case

    public references : Reference[] = [];
    public xrefs : Xref[] = [];
    public associations : Association[] = [];
    public calculatedFields : Array<Field> = [];
    public views : Table[] = [];
    public idFields : Field[] = [];
    public idFieldLookup : util.Dictionary<boolean> = {};

    public useModelFactory : boolean = false;

    constructor(public tables : Array<Table>) {

    }

    public static fieldTypeTranslations : util.Dictionary<string> = {

        tinyint : "boolean",

        smallint : "number",
        int : "number",
        integer : "number",
        mediumint : "number",
        bigint : "number",
        year : "number",
        float : "number",
        double : "number",
        decimal : "number",
        "double precision" : "number",
        real : "number",
        numeric : "number",

        timestamp : "Date",
        date : "Date",
        datetime : "Date",

        tinyblob : "Buffer",
        mediumblob : "Buffer",
        longblob : "Buffer",
        blob : "Buffer",
        binary : "Buffer",
        varbinary : "Buffer",
        bit : "Buffer",
        bytea : "Buffer",

        char : "string",
        character : "string",
        varchar : "string",
        tinytext : "string",
        mediumtext : "string",
        longtext : "string",
        text : "string",
        "enum" : "string",
        "set" : "string",
        time : "string",
        geometry : "string",
        "character varying" : "string",
        "USER-DEFINED" : "string"
    };

    public static fieldTypeSequelize : util.Dictionary<string> = {

        tinyint : 'Sequelize.BOOLEAN',
        smallint : 'Sequelize.INTEGER',
        int : 'Sequelize.INTEGER',
        integer : 'Sequelize.INTEGER',
        mediumint : 'Sequelize.INTEGER',
        bigint : 'Sequelize.INTEGER',
        year : 'Sequelize.INTEGER',

        float : 'Sequelize.DECIMAL',
        double : 'Sequelize.DECIMAL',<commit_msg>added (non standard) boolean for sqlite<commit_after>/****************************
 *
 * Loads and exposes schema from database
 */

/// <reference path="../typings/index.d.ts"/>

import util = require('./util');

import sequelize = require('sequelize');
var Sequelize : sequelize.SequelizeStatic = require("sequelize");
import fs = require('fs');
import _ = require('lodash');
import ChangeCase = require('change-case');

const DEFAULT_CASE_TYPE = 'pascalCase';
var naming : any;

export class Schema {

    public static idSuffix : string = "id"; // NOTE: Must be LOWER case

    public references : Reference[] = [];
    public xrefs : Xref[] = [];
    public associations : Association[] = [];
    public calculatedFields : Array<Field> = [];
    public views : Table[] = [];
    public idFields : Field[] = [];
    public idFieldLookup : util.Dictionary<boolean> = {};

    public useModelFactory : boolean = false;

    constructor(public tables : Array<Table>) {

    }

    public static fieldTypeTranslations : util.Dictionary<string> = {

        tinyint : "boolean",
        
        boolean : "boolean",

        smallint : "number",
        int : "number",
        integer : "number",
        mediumint : "number",
        bigint : "number",
        year : "number",
        float : "number",
        double : "number",
        decimal : "number",
        "double precision" : "number",
        real : "number",
        numeric : "number",

        timestamp : "Date",
        date : "Date",
        datetime : "Date",

        tinyblob : "Buffer",
        mediumblob : "Buffer",
        longblob : "Buffer",
        blob : "Buffer",
        binary : "Buffer",
        varbinary : "Buffer",
        bit : "Buffer",
        bytea : "Buffer",

        char : "string",
        character : "string",
        varchar : "string",
        tinytext : "string",
        mediumtext : "string",
        longtext : "string",
        text : "string",
        "enum" : "string",
        "set" : "string",
        time : "string",
        geometry : "string",
        "character varying" : "string",
        "USER-DEFINED" : "string"
    };

    public static fieldTypeSequelize : util.Dictionary<string> = {

        tinyint : 'Sequelize.BOOLEAN',
        
        boolean : 'Sequelize.BOOLEAN',
        
        smallint : 'Sequelize.INTEGER',
        int : 'Sequelize.INTEGER',
        integer : 'Sequelize.INTEGER',
        mediumint : 'Sequelize.INTEGER',
        bigint : 'Sequelize.INTEGER',
        year : 'Sequelize.INTEGER',

        float : 'Sequelize.DECIMAL',
        double : 'Sequelize.DECIMAL',
{'fraction_non_alphanumeric': 0.1528350009809692, 'fraction_numerical': 0.0, 'mean_word_length': 2.2805662805662807, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, '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': '1299216', 'n_tokens_mistral': 1473, 'n_tokens_neox': 1434, 'n_words': 360}