import _ from "lodash" ; import { addTicks , DialectOptions , FKRow , makeCondition } from "./dialect-options" ; export const mysqlOptions = { name : 'mysql' , hasSchema : false , param { String } tableName param { String } schemaName return { String } getForeignKeysQuery : ( tableName , schemaName ) => { return `SELECT K.CONSTRAINT_NAME as constraint_name
      , K.CONSTRAINT_SCHEMA as source_schema
      , K.TABLE_NAME as source_table
      , K.COLUMN_NAME as source_column
      , K.REFERENCED_TABLE_SCHEMA AS target_schema
      , K.REFERENCED_TABLE_NAME AS target_table
      , K.REFERENCED_COLUMN_NAME AS target_column
      , C.EXTRA AS extra
      , C.COLUMN_KEY AS column_key
      FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS K
      LEFT JOIN INFORMATION_SCHEMA.COLUMNS AS C
        ON C.TABLE_NAME = K.TABLE_NAME AND C.COLUMN_NAME = K.COLUMN_NAME AND C.TABLE_SCHEMA = K.CONSTRAINT_SCHEMA
      WHERE K.TABLE_NAME = ${ addTicks ( tableName ) }
            ${ makeCondition ( 'C.TABLE_SCHEMA' , schemaName ) }` ; } , param { String } tableName param { String } schemaName return { String } countTriggerQuery : ( tableName , schemaName ) => { return `SELECT COUNT(0) AS trigger_count
              FROM INFORMATION_SCHEMA.TRIGGERS AS t
             WHERE t.EVENT_OBJECT_TABLE = ${ addTicks ( tableName ) }
                  ${ makeCondition ( "t.EVENT_OBJECT_SCHEMA" , schemaName ) }` ; } , param { Object } record return { Bool } isForeignKey : ( record ) => { return _ . isObject ( record ) && _ . has ( record , 'extra' ) && record . extra !== 'auto_increment' ; } , param { Object } record return { Bool } isUnique : ( record , records ) => { if ( ! _ . isObject ( record ) || ! _ . has ( record , 'column_key' ) ) { return false ; } return records . some ( row => row . constraint_name === record . constraint_name && ( row . column_key . toUpperCase ( ) === 'UNI' ) ) ; } , param { Object } record return { Bool } isPrimaryKey : ( record ) => { return _ . isObject ( record ) && _ . has ( record , 'constraint_name' ) && record . constraint_name === 'PRIMARY' ; } , param { Object } record return { Bool } isSerialKey : ( record ) => { return _ . isObject ( record ) && _ . has ( record , 'extra' ) && record . extra === 'auto_increment' ; } , showViewsQuery : ( dbName ? ) => { return `select TABLE_NAME as table_name from information_schema.tables where table_type = 'VIEW' and table_schema = '${ dbName }'` ; } } ;