import {IControl, IDataSource, SourceCode, ITableDefinition} from '@datahu/core'
import {I18n} from '../i18n'
import getControls from './MysqlControls'
import {IMysqlConfig, MysqlHelper} from './MysqlHelper'
export class MysqlDataSource implements IDataSource {
language: string = 'zh-cn'
helper: MysqlHelper
constructor(language: string, config?: object) {
this.language = language
var i18n = I18n.get(this.language)
if (config) this.config = config as IMysqlConfig
this.helper = new MysqlHelper(this.config)
// 数据源配置界面的配置控件
this.controls = getControls(i18n)
this.title = i18n.mysql_title
this.description = i18n.mysql_description
}
getControls(): IControl[] {
return this.controls
}
controls: IControl[] = []
// 数据源默认配置值
config = {
title: '',
host: 'localhost',
port: 3306,
user: 'root',
password: '',
database: '',
charset: '',
ssl: false,
sslCa: '',
sslKey: '',
sslCert: '',
sslRejectUnauthorized: false
} as IMysqlConfig
icon: string =
''
title: string = ''
description: string = ''
sourceCode: SourceCode = SourceCode.Javascript
getTables(): Promise> {
return this.helper.getTables()
}
getData(tables: Array): Promise> {
return this.helper.getData(tables)
}
}