@@ -15,9 +15,8 @@ import { ConnectionOptions, TLSSocket, connect as tls, createSecureContext } fro
15
15
16
16
import {
17
17
DataHandler ,
18
- Result as _Result ,
19
- ResultIterator as _ResultIterator ,
20
- ResultRow as _ResultRow ,
18
+ ResultIterator ,
19
+ ResultRecord ,
21
20
makeResult
22
21
} from './result' ;
23
22
@@ -37,19 +36,11 @@ import {
37
36
import {
38
37
DataFormat ,
39
38
DataType ,
40
- Row ,
41
- Value ,
42
39
ValueTypeReader
43
40
} from './types' ;
44
41
45
42
import { md5 } from './utils' ;
46
43
47
- export type Result = _Result < Value > ;
48
-
49
- export type ResultIterator = _ResultIterator < Value > ;
50
-
51
- export type ResultRow = _ResultRow < Value > ;
52
-
53
44
export type Connect = Error | null ;
54
45
55
46
export type End = void ;
@@ -67,7 +58,7 @@ export interface ClientNotice extends DatabaseError {
67
58
68
59
export interface DataTypeError {
69
60
dataType : DataType ,
70
- value : Value
61
+ value : any
71
62
}
72
63
73
64
export enum SSLMode {
@@ -100,14 +91,14 @@ export interface Notification {
100
91
payload ?: string
101
92
}
102
93
103
- export interface PreparedStatement {
94
+ export interface PreparedStatement < T = ResultRecord > {
104
95
close : ( portal ?: string ) => Promise < void > ;
105
96
execute : (
106
- values ?: Value [ ] ,
97
+ values ?: any [ ] ,
107
98
portal ?: string ,
108
99
format ?: DataFormat | DataFormat [ ] ,
109
100
streams ?: Record < string , Writable > ,
110
- ) => ResultIterator
101
+ ) => ResultIterator < T >
111
102
}
112
103
113
104
type Callback < T > = ( data : T ) => void ;
@@ -127,7 +118,7 @@ type Event = (
127
118
type CloseHandler = ( ) => void ;
128
119
129
120
interface RowDataHandler {
130
- callback : DataHandler < Row > ,
121
+ callback : DataHandler < any [ ] > ,
131
122
streams : Record < string , Writable > ,
132
123
}
133
124
@@ -154,7 +145,7 @@ interface Bind {
154
145
name : string ;
155
146
format : DataFormat | DataFormat [ ]
156
147
portal : string ;
157
- values : Value [ ] ,
148
+ values : any [ ] ,
158
149
close : boolean
159
150
}
160
151
@@ -188,7 +179,7 @@ export class Client {
188
179
private expect = 5 ;
189
180
private stream = new Socket ( ) ;
190
181
private mustDrain = false ;
191
- private activeRow : Array < Value > | null = null ;
182
+ private activeRow : Array < any > | null = null ;
192
183
193
184
private bindQueue = new Queue < RowDataHandlerInfo | null > ( ) ;
194
185
private closeHandlerQueue = new Queue < CloseHandler | null > ( ) ;
@@ -513,18 +504,18 @@ export class Client {
513
504
}
514
505
}
515
506
516
- prepare (
507
+ prepare < T = ResultRecord > (
517
508
text : string ,
518
509
name ?: string ,
519
- types ?: DataType [ ] ) : Promise < PreparedStatement > {
510
+ types ?: DataType [ ] ) : Promise < PreparedStatement < T > > {
520
511
521
512
const providedNameOrGenerated = name || (
522
513
( this . config . preparedStatementPrefix ||
523
514
defaults . preparedStatementPrefix ) + (
524
515
this . nextPreparedStatementId ++
525
516
) ) ;
526
517
527
- return new Promise < PreparedStatement > (
518
+ return new Promise < PreparedStatement < T > > (
528
519
( resolve , reject ) => {
529
520
const errorHandler : ErrorHandler = ( error ) => reject ( error ) ;
530
521
this . errorHandlerQueue . push ( errorHandler ) ;
@@ -551,12 +542,12 @@ export class Client {
551
542
) ;
552
543
} ,
553
544
execute : (
554
- values ?: Value [ ] ,
545
+ values ?: any [ ] ,
555
546
portal ?: string ,
556
547
format ?: DataFormat | DataFormat [ ] ,
557
548
streams ?: Record < string , Writable > ,
558
549
) => {
559
- const result = makeResult < Value > ( ) ;
550
+ const result = makeResult < T > ( ) ;
560
551
result . nameHandler ( description . names ) ;
561
552
const info = {
562
553
handler : {
@@ -587,13 +578,13 @@ export class Client {
587
578
} ) ;
588
579
}
589
580
590
- query (
581
+ query < T = ResultRecord > (
591
582
text : string ,
592
- values ?: Value [ ] ,
583
+ values ?: any [ ] ,
593
584
types ?: DataType [ ] ,
594
585
format ?: DataFormat | DataFormat [ ] ,
595
586
streams ?: Record < string , Writable > ) :
596
- ResultIterator {
587
+ ResultIterator < T > {
597
588
const query =
598
589
( typeof text === 'string' ) ?
599
590
new Query (
@@ -604,7 +595,7 @@ export class Client {
604
595
streams : streams ,
605
596
} ) :
606
597
text ;
607
- return this . execute ( query ) ;
598
+ return this . execute < T > ( query ) ;
608
599
}
609
600
610
601
private bindAndExecute (
@@ -642,7 +633,7 @@ export class Client {
642
633
this . send ( ) ;
643
634
}
644
635
645
- execute ( query : Query ) : ResultIterator {
636
+ execute < T = ResultRecord > ( query : Query ) : ResultIterator < T > {
646
637
if ( this . closed && ! this . connecting ) {
647
638
throw new Error ( 'Connection is closed.' ) ;
648
639
}
@@ -654,7 +645,7 @@ export class Client {
654
645
const types = options ? options . types : undefined ;
655
646
const streams = options ? options . streams : undefined ;
656
647
const portal = ( options ? options . portal : undefined ) || '' ;
657
- const result = makeResult < Value > ( ) ;
648
+ const result = makeResult < T > ( ) ;
658
649
659
650
const descriptionHandler = ( description : RowDescription ) => {
660
651
result . nameHandler ( description . names ) ;
@@ -877,7 +868,7 @@ export class Client {
877
868
878
869
if ( row === null ) {
879
870
const count = buffer . readInt16BE ( start ) ;
880
- row = new Array < Value > ( count ) ;
871
+ row = new Array < any > ( count ) ;
881
872
}
882
873
883
874
const startRowData = start + 2 ;
0 commit comments