import { join } from 'path'; import { createFile } from '../utils/file'; import { GetMysqlTableSql, getMysqlTableSql, MysqlColumn } from './mysql'; import { GetOssTableSql, getOssTableSql } from './oss'; export interface GenerateTableSql { tableName: string; tableComment: string; primaryKey: string; columns: MysqlColumn[]; } export function generateTableSql(conf: GenerateTableSql[]): void { const inputPath = ''; const outputPath = '/Users/liuyuchuan/Desktop/tdd-project/output'; const endpoint = 'oss-cn-beijing-internal.aliyuncs.com'; const accessId = 'LTAI4FwyYCrpLESasUbwDrkm'; const accessKey = '4mgL7PO1tcSer21GnrKfC15UBktheb'; const urlPrefix = 'oss://project-tdd'; const databaseName = 'gghb'; const ossDirName = 'tdd-gghb'; const ossStrs: string[] = []; const mysqlStrs: string[] = []; conf.forEach((item) => { const { tableName, columns, tableComment, primaryKey, } = item; const ossConf: GetOssTableSql = { databaseName, tableName: `oss_table_origin_${tableName}`, endpoint, url: `${urlPrefix}/${join(ossDirName, `${tableName}.csv`)}`, accessId, accessKey, columns: columns.map((col) => ({ name: col.name, type: col.type, })), }; const mysqlConf: GetMysqlTableSql = { databaseName, tableName: `origin_${tableName}`, tableComment, primaryKey, columns, }; ossStrs.push(`-- 表名 ${tableName}`); mysqlStrs.push(`-- 表名 ${tableName}`); ossStrs.push(getOssTableSql(ossConf)); mysqlStrs.push(getMysqlTableSql(mysqlConf)); ossStrs.push(''); mysqlStrs.push(''); }); createFile(join(outputPath, 'oss.sql'), ossStrs); createFile(join(outputPath, 'mysql.sql'), mysqlStrs); }