<commit_before>import { AbstractDriver } from './abstractDriver'
import * as Bluebird from 'bluebird'
import * as Mysql from 'mysql'
import * as _ from 'lodash';
/**
 * MssqlDriver
 */
export class MysqlDriver extends AbstractDriver {
    FindPrimaryColumnsFromIndexes(dbModel: DatabaseModel) {
        dbModel.entities.forEach(entity => {
            let primaryIndex = entity.Indexes.find(v=>v.isPrimaryKey);
            if (!primaryIndex){
                console.error(`Table ${entity.EntityName} has no PK.`)
                return;
            }
            let pIndex=primaryIndex; //typescript error? pIndex:IndexInfo; primaryIndex:IndexInfo|undefined
            entity.Columns.forEach(col=>{
                if(pIndex.columns.some( cIndex=> cIndex.name==col.name)) {
                    col.isPrimary = true;
                    col.isSpecialColumn = true;
                }
                if (col.name == 'create_time') {
                    col.isCreateTime = true;
                    col.isSpecialColumn = true;
                } else if (col.name == 'update_time') {
                    col.isUpdateTime = true;
                    col.isSpecialColumn = true;
                } else if (col.name == 'version') {
                    col.isVersion = true;
                    col.isSpecialColumn = true;
                }
            })
        });
    }

    GetCamelCase(entityName: string) {
        entityName = _.camelCase(entityName).replace(/tbl/g,'');
        return entityName.substring(0,1).toUpperCase() + entityName.substring(1);
    }

    GetSnakeName(entityName: string) {
        entityName = entityName.replace(/tbl_/g,'');
        return entityName;
    }

    async GetAllTables(): Promise<EntityInfo[]> {
        let request = this.Connection;
        let response: { TABLE_SCHEMA: string, TABLE_NAME: string }[]
            = await request.queryAsync(`SELECT TABLE_SCHEMA,TABLE_NAME FROM information_schema.tables where TABLE_SCHEMA='${this.Config.database}'`);
        let ret: EntityInfo[] = <EntityInfo[]>[];
        response.forEach((val) => {
            let ent: EntityInfo = <EntityInfo>{};
            ent.EntityNameCamel = this.GetCamelCase(val.TABLE_NAME);
            ent.EntityNameSnake = this.GetSnakeName(val.TABLE_NAME);
            ent.EntityName = val.TABLE_NAME;
            ent.Columns = <ColumnInfo[]>[];
            ent.Indexes = <IndexInfo[]>[];
            ret.push(ent);
        })
        return ret;
    }
    async GetCoulmnsFromEntity(entities: EntityInfo[]) {
        let request = this.Connection;
        let response: { TABLE_NAME: string, COLUMN_NAME: string, COLUMN_DEFAULT: string,
             IS_NULLABLE: string, DATA_TYPE: string, CHARACTER_MAXIMUM_LENGTH: number,
            NUMERIC_PRECISION:number,NUMERIC_SCALE:number }[]
            = await request.queryAsync(`SELECT TABLE_NAME,COLUMN_NAME,COLUMN_DEFAULT,IS_NULLABLE,
   DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,NUMERIC_PRECISION,NUMERIC_SCALE 
   FROM information_schema.columns where TABLE_SCHEMA='${this.Config.database}'`);
        entities.forEach((ent) => {
            response.filter((filterVal) => {
                return filterVal.TABLE_NAME == ent.EntityName;
            }).forEach((resp) => {
                let colInfo: ColumnInfo = <ColumnInfo>{};
                colInfo.name = resp.COLUMN_NAME;
                colInfo.is_nullable = resp.IS_NULLABLE == 'YES' ? true : false;
                colInfo.default = resp.COLUMN_DEFAULT;
                colInfo.isSpecialColumn = false; 
                switch (resp.DATA_TYPE) {
                    case "int":
                        colInfo.ts_type = "number"
                        colInfo.sql_type = "int"
                        break;
                    case "tinyint":
                        colInfo.ts_type = "number"
                        colInfo.sql_type = "smallint"
                        break;
                    case "smallint":
                        colInfo.ts_type = "number"
                        colInfo.sql_type = "smallint"
                        break;
                    case "bit":
                        colInfo.ts_type = "boolean"
                        colInfo.sql_type = "boolean"
                        break;
                    case "float":
                        colInfo.ts_type = "number"
                        colInfo.sql_type = "float"
                        break;
                    case "double":
                        colInfo.ts_type = "number"
                        colInfo.sql_type = "double"
                        break;
                    case "date":
                        colInfo.ts_type = "number"
                        colInfo.sql_type = "date"
                        break;
                    case "datetime":
                        colInfo.ts_type = "Date";
                        colInfo.sql_type = "datetime"
                        break;
                    case "char":
                        colInfo.ts_type = "string"
                        colInfo.sql_type = "string"
                        break;
                    case "nchar":
                        colInfo.ts_type = "string"
                        colInfo.sql_type = "text"
                        break;
                    case "text":
                        colInfo.ts_type = "string"
                        colInfo.sql_type = "text"
                        break;
                    case "longtext":
                        colInfo.ts_type = "string"
                        colInfo.sql_type = "text"
                        break;
                    case "ntext":
                        colInfo.ts_type = "string"
                        colInfo.sql_type = "text"<commit_msg>Fixed annotation CreateDateColumn typescript type to string<commit_after>import { AbstractDriver } from './abstractDriver'
import * as Bluebird from 'bluebird'
import * as Mysql from 'mysql'
import * as _ from 'lodash';
/**
 * MssqlDriver
 */
export class MysqlDriver extends AbstractDriver {
    FindPrimaryColumnsFromIndexes(dbModel: DatabaseModel) {
        dbModel.entities.forEach(entity => {
            let primaryIndex = entity.Indexes.find(v=>v.isPrimaryKey);
            if (!primaryIndex){
                console.error(`Table ${entity.EntityName} has no PK.`)
                return;
            }
            let pIndex=primaryIndex; //typescript error? pIndex:IndexInfo; primaryIndex:IndexInfo|undefined
            entity.Columns.forEach(col=>{
                if(pIndex.columns.some( cIndex=> cIndex.name==col.name)) {
                    col.isPrimary = true;
                    col.isSpecialColumn = true;
                }
                if (col.name == 'create_time') {
                    col.isCreateTime = true;
                    col.isSpecialColumn = true;
                } else if (col.name == 'update_time') {
                    col.isUpdateTime = true;
                    col.isSpecialColumn = true;
                } else if (col.name == 'version') {
                    col.isVersion = true;
                    col.isSpecialColumn = true;
                }
            })
        });
    }

    GetCamelCase(entityName: string) {
        entityName = _.camelCase(entityName).replace(/tbl/g,'');
        return entityName.substring(0,1).toUpperCase() + entityName.substring(1);
    }

    GetSnakeName(entityName: string) {
        entityName = entityName.replace(/tbl_/g,'');
        return entityName;
    }

    async GetAllTables(): Promise<EntityInfo[]> {
        let request = this.Connection;
        let response: { TABLE_SCHEMA: string, TABLE_NAME: string }[]
            = await request.queryAsync(`SELECT TABLE_SCHEMA,TABLE_NAME FROM information_schema.tables where TABLE_SCHEMA='${this.Config.database}'`);
        let ret: EntityInfo[] = <EntityInfo[]>[];
        response.forEach((val) => {
            let ent: EntityInfo = <EntityInfo>{};
            ent.EntityNameCamel = this.GetCamelCase(val.TABLE_NAME);
            ent.EntityNameSnake = this.GetSnakeName(val.TABLE_NAME);
            ent.EntityName = val.TABLE_NAME;
            ent.Columns = <ColumnInfo[]>[];
            ent.Indexes = <IndexInfo[]>[];
            ret.push(ent);
        })
        return ret;
    }
    async GetCoulmnsFromEntity(entities: EntityInfo[]) {
        let request = this.Connection;
        let response: { TABLE_NAME: string, COLUMN_NAME: string, COLUMN_DEFAULT: string,
             IS_NULLABLE: string, DATA_TYPE: string, CHARACTER_MAXIMUM_LENGTH: number,
            NUMERIC_PRECISION:number,NUMERIC_SCALE:number }[]
            = await request.queryAsync(`SELECT TABLE_NAME,COLUMN_NAME,COLUMN_DEFAULT,IS_NULLABLE,
   DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,NUMERIC_PRECISION,NUMERIC_SCALE 
   FROM information_schema.columns where TABLE_SCHEMA='${this.Config.database}'`);
        entities.forEach((ent) => {
            response.filter((filterVal) => {
                return filterVal.TABLE_NAME == ent.EntityName;
            }).forEach((resp) => {
                let colInfo: ColumnInfo = <ColumnInfo>{};
                colInfo.name = resp.COLUMN_NAME;
                colInfo.is_nullable = resp.IS_NULLABLE == 'YES' ? true : false;
                colInfo.default = resp.COLUMN_DEFAULT;
                colInfo.isSpecialColumn = false; 
                switch (resp.DATA_TYPE) {
                    case "int":
                        colInfo.ts_type = "number"
                        colInfo.sql_type = "int"
                        break;
                    case "tinyint":
                        colInfo.ts_type = "number"
                        colInfo.sql_type = "smallint"
                        break;
                    case "smallint":
                        colInfo.ts_type = "number"
                        colInfo.sql_type = "smallint"
                        break;
                    case "bit":
                        colInfo.ts_type = "boolean"
                        colInfo.sql_type = "boolean"
                        break;
                    case "float":
                        colInfo.ts_type = "number"
                        colInfo.sql_type = "float"
                        break;
                    case "double":
                        colInfo.ts_type = "number"
                        colInfo.sql_type = "double"
                        break;
                    case "date":
                        colInfo.ts_type = "number"
                        colInfo.sql_type = "date"
                        break;
                    case "datetime":
                        colInfo.ts_type = "string";
                        colInfo.sql_type = "datetime"
                        break;
                    case "char":
                        colInfo.ts_type = "string"
                        colInfo.sql_type = "string"
                        break;
                    case "nchar":
                        colInfo.ts_type = "string"
                        colInfo.sql_type = "text"
                        break;
                    case "text":
                        colInfo.ts_type = "string"
                        colInfo.sql_type = "text"
                        break;
                    case "longtext":
                        colInfo.ts_type = "string"
                        colInfo.sql_type = "text"
                        break;
                    case "ntext":
                        colInfo.ts_type = "string"
                        colInfo.sql_type = "text"
{'fraction_non_alphanumeric': 0.09840055632823366, 'fraction_numerical': 0.000521557719054242, 'mean_word_length': 1.345565749235474, 'pattern_counts': {'":': 26, '<': 15, '<?xml version=': 0, '>': 31, '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': '2103370', 'n_tokens_mistral': 3047, 'n_tokens_neox': 2895, 'n_words': 547}