@@ -2,29 +2,7 @@ import { ident, literal } from 'pg-format'
2
2
import PostgresMetaTables from './PostgresMetaTables'
3
3
import { DEFAULT_SYSTEM_SCHEMAS } from './constants'
4
4
import { columnsSql } from './sql'
5
- import { PostgresMetaResult , PostgresColumn } from './types'
6
-
7
- interface ColumnCreationRequest {
8
- table_id : number
9
- name : string
10
- type : string
11
- default_value ?: any
12
- default_value_format ?: 'expression' | 'literal'
13
- is_identity ?: boolean
14
- identity_generation ?: 'BY DEFAULT' | 'ALWAYS'
15
- is_nullable ?: boolean
16
- is_primary_key ?: boolean
17
- is_unique ?: boolean
18
- comment ?: string
19
- check ?: string
20
- }
21
-
22
- interface ColumnBatchInfoRequest {
23
- ids ?: string [ ]
24
- names ?: string [ ]
25
- table ?: string
26
- schema ?: string
27
- }
5
+ import { PostgresMetaResult , PostgresColumn , PostgresColumnCreate } from './types'
28
6
29
7
export default class PostgresMetaColumns {
30
8
query : ( sql : string ) => Promise < PostgresMetaResult < any > >
@@ -97,12 +75,27 @@ export default class PostgresMetaColumns {
97
75
return { data : null , error : { message : 'Invalid parameters on column retrieve' } }
98
76
}
99
77
78
+ async batchRetrieve ( { ids } : { ids : string [ ] } ) : Promise < PostgresMetaResult < PostgresColumn [ ] > >
79
+ async batchRetrieve ( {
80
+ names,
81
+ table,
82
+ schema,
83
+ } : {
84
+ names : string [ ]
85
+ table : string
86
+ schema : string
87
+ } ) : Promise < PostgresMetaResult < PostgresColumn [ ] > >
100
88
async batchRetrieve ( {
101
89
ids,
102
90
names,
103
91
table,
104
92
schema = 'public' ,
105
- } : ColumnBatchInfoRequest ) : Promise < PostgresMetaResult < PostgresColumn [ ] > > {
93
+ } : {
94
+ ids ?: string [ ]
95
+ names ?: string [ ]
96
+ table ?: string
97
+ schema ?: string
98
+ } ) : Promise < PostgresMetaResult < PostgresColumn [ ] > > {
106
99
if ( ids && ids . length > 0 ) {
107
100
const regexp = / ^ ( \d + ) \. ( \d + ) $ /
108
101
const filteringClauses = ids
@@ -145,7 +138,7 @@ export default class PostgresMetaColumns {
145
138
}
146
139
}
147
140
148
- async create ( col : ColumnCreationRequest ) : Promise < PostgresMetaResult < PostgresColumn > > {
141
+ async create ( col : PostgresColumnCreate ) : Promise < PostgresMetaResult < PostgresColumn > > {
149
142
const { data, error } = await this . batchCreate ( [ col ] )
150
143
if ( data ) {
151
144
return { data : data [ 0 ] , error : null }
@@ -155,7 +148,7 @@ export default class PostgresMetaColumns {
155
148
return { data : null , error : { message : 'Invalid params' } }
156
149
}
157
150
158
- async batchCreate ( cols : ColumnCreationRequest [ ] ) : Promise < PostgresMetaResult < PostgresColumn [ ] > > {
151
+ async batchCreate ( cols : PostgresColumnCreate [ ] ) : Promise < PostgresMetaResult < PostgresColumn [ ] > > {
159
152
if ( cols . length < 1 ) {
160
153
throw new Error ( 'no columns provided for creation' )
161
154
}
@@ -199,7 +192,7 @@ COMMIT;
199
192
is_unique = false ,
200
193
comment,
201
194
check,
202
- } : ColumnCreationRequest ,
195
+ } : PostgresColumnCreate ,
203
196
schema : string ,
204
197
table : string
205
198
) {
0 commit comments