import { IControl, Crypto, SourceCode, ITableDefinition, ComponentControl, ControlType, ITableQueryPager, Util } from '@datahu/core' import {I18n} from '../i18n' import {BaseDataSource, BaseDataSourceOption} from '../base' import {PostgresqlHelper} from './PostgresqlHelper' export class PostgresqlDataSourceOption extends BaseDataSourceOption { static controls: Array = [] @ComponentControl({ type: ControlType.text, title: '服务器', required: true }) host: string = 'localhost' @ComponentControl({ type: ControlType.number, title: '端口', required: true }) port: number = 5432 @ComponentControl({ type: ControlType.text, title: '用户名' }) user: string = '' @ComponentControl({ type: ControlType.password, title: '密码' }) password: string = '' @ComponentControl({ type: ControlType.text, title: '默认数据库', required: true }) database: string = '' @ComponentControl({ type: ControlType.boolean, title: '使用SSL' }) ssl: boolean = false @ComponentControl({ type: ControlType.file, title: 'CA证书', show: `(data) => { return data.ssl }` }) sslCa: string = '' @ComponentControl({ type: ControlType.file, title: '客户端密钥', show: `(data) => { return data.ssl }` }) sslKey: string = '' @ComponentControl({ type: ControlType.file, title: '客户端证书', show: `(data) => { return data.ssl }` }) sslCert: string = '' @ComponentControl({ type: ControlType.boolean, title: '不验证证书', show: `(data) => { return data.ssl }` }) sslRejectUnauthorized: boolean = false } export class PostgresqlDataSource extends BaseDataSource { helper?: PostgresqlHelper constructor(language: string, config?: PostgresqlDataSourceOption) { super(language, config) this.title = 'PostgreSQL' this.description = 'Postgresql数据库' if (config) { this.helper = new PostgresqlHelper(config) } } // 数据源默认配置值 config: PostgresqlDataSourceOption = new PostgresqlDataSourceOption() icon: string = '' sourceCode: SourceCode = SourceCode.Javascript supportPager: boolean = true getTables(pager: ITableQueryPager | null): Promise { return this.helper!.getTables(pager!) } getData(tables: Array): Promise> { return this.helper!.getData(tables) } }