11import pg from "pg" ;
2- import Base from "./Base" ;
2+ import Base , { ConfigSchemaType } from "./Base" ;
33import Util from "../Util" ;
44import { zipObject } from "lodash" ;
55
@@ -50,13 +50,13 @@ import { zipObject } from "lodash";
5050export default class Postgres extends Base {
5151 currentClient : any ;
5252
53- static get key ( ) {
53+ static get key ( ) : string {
5454 return "postgres" ;
5555 }
56- static get label ( ) {
56+ static get label ( ) : string {
5757 return "PostgreSQL" ;
5858 }
59- static get configSchema ( ) {
59+ static get configSchema ( ) : ConfigSchemaType {
6060 return [
6161 { name : "host" , label : "Host" , type : "string" , placeholder : "localhost" } ,
6262 { name : "port" , label : "Port" , type : "number" , placeholder : 5432 } ,
@@ -72,27 +72,27 @@ export default class Postgres extends Base {
7272 ] ;
7373 }
7474
75- async execute ( query , options : any = { } ) {
75+ async execute ( query : string , options : any = { } ) : Promise < any > {
7676 try {
7777 return await this . _execute ( query ) ;
7878 } catch ( err ) {
7979 throw this . _errorWithLine ( err , query , options . startLine || 1 ) ;
8080 }
8181 }
8282
83- cancel ( ) {
83+ cancel ( ) : Promise < void > {
8484 const pid = this . currentClient && this . currentClient . processID ;
8585 if ( ! pid ) return Promise . resolve ( ) ;
8686
8787 return new Postgres ( this . config ) . _execute ( `select pg_cancel_backend(${ pid } )` ) ;
8888 }
8989
90- async connectionTest ( ) {
90+ async connectionTest ( ) : Promise < any > {
9191 await this . _execute ( "select 1" ) ;
9292 return true ;
9393 }
9494
95- async fetchTables ( ) {
95+ async fetchTables ( ) : Promise < { name : string ; type : string ; schema ?: string } [ ] > {
9696 const query = Util . stripHeredoc ( `
9797 select table_schema as schema, table_name as name, table_type as type
9898 from information_schema.tables
@@ -104,7 +104,13 @@ export default class Postgres extends Base {
104104 return rows . map ( row => zipObject ( fields , row ) ) ;
105105 }
106106
107- async fetchTableSummary ( { schema, name } ) {
107+ async fetchTableSummary ( {
108+ schema,
109+ name
110+ } : {
111+ schema : string ;
112+ name : string ;
113+ } ) : Promise < { name : string ; defs : { fields : string [ ] ; rows : ( string | null ) [ ] [ ] } ; schema ?: string } > {
108114 const query = Util . stripHeredoc ( `
109115 select
110116 pg_attribute.attname as name,
@@ -130,7 +136,7 @@ export default class Postgres extends Base {
130136 return { schema, name, defs } ;
131137 }
132138
133- descriptionTable ( ) {
139+ descriptionTable ( ) : string {
134140 return Util . stripHeredoc ( `
135141 |host|${ this . config . host } |
136142 |port|${ this . config . port } |
0 commit comments