@@ -403,6 +403,13 @@ export class Client {
403
403
} ) ;
404
404
}
405
405
406
+ /** Connect to the database.
407
+ *
408
+ * @remarks
409
+ * Don't forget to close the connection using {@link end} before exiting.
410
+ *
411
+ * @returns The connection encryption status.
412
+ */
406
413
connect ( ) : Promise < boolean > {
407
414
if ( this . connecting ) {
408
415
throw new Error ( 'Already connecting' ) ;
@@ -446,6 +453,9 @@ export class Client {
446
453
return p ;
447
454
}
448
455
456
+ /** End the database connection.
457
+ *
458
+ */
449
459
end ( ) {
450
460
if ( this . ending ) {
451
461
throw new Error ( 'Already ending' ) ;
@@ -514,13 +524,13 @@ export class Client {
514
524
}
515
525
}
516
526
517
- prepare < T = ResultRecord > (
518
- text : Query | string ,
519
- name ?: string ,
520
- types ?: DataType [ ] ) : Promise < PreparedStatement < T > > {
521
-
527
+ /** Prepare a statement for later execution.
528
+ *
529
+ * @returns A prepared statement object.
530
+ */
531
+ prepare < T = ResultRecord > ( text : Query | string ) : Promise < PreparedStatement < T > > {
522
532
const query = typeof text === 'string' ? { text} : text ;
523
- const providedNameOrGenerated = name || (
533
+ const providedNameOrGenerated = query . name || (
524
534
( this . config . preparedStatementPrefix ||
525
535
defaults . preparedStatementPrefix ) + (
526
536
this . nextPreparedStatementId ++
@@ -530,7 +540,7 @@ export class Client {
530
540
( resolve , reject ) => {
531
541
const errorHandler : ErrorHandler = ( error ) => reject ( error ) ;
532
542
this . errorHandlerQueue . push ( errorHandler ) ;
533
- this . writer . parse ( providedNameOrGenerated , query . text , types || query . types || [ ] ) ;
543
+ this . writer . parse ( providedNameOrGenerated , query . text , query . types || [ ] ) ;
534
544
this . writer . describe ( providedNameOrGenerated , 'S' ) ;
535
545
this . preFlightQueue . push ( {
536
546
descriptionHandler : ( description : RowDescription ) => {
@@ -598,28 +608,18 @@ export class Client {
598
608
* @param text - The query string, or pass a {@link Query}
599
609
* object which provides more control (including streaming values into a socket).
600
610
* @param values - The query parameters, corresponding to $1, $2, etc.
601
- * @param types - Allows making the database native type explicit for some or all
602
- * columns.
603
- * @param format - Whether column data should be transferred using text or binary mode.
604
- * @param streams - A mapping from column name to a socket, e.g. an open file.
605
611
* @returns A promise for the query results.
606
612
*/
607
- query < T = ResultRecord > (
608
- text : Query | string ,
609
- values ?: any [ ] ,
610
- types ?: DataType [ ] ,
611
- format ?: DataFormat | DataFormat [ ] ,
612
- streams ?: Record < string , Writable > ) :
613
- ResultIterator < T > {
613
+ query < T = ResultRecord > ( text : Query | string , values ?: any [ ] ) : ResultIterator < T > {
614
614
const query = typeof text === 'string' ? { text} : text ;
615
615
616
616
if ( this . closed && ! this . connecting ) {
617
617
throw new Error ( 'Connection is closed.' ) ;
618
618
}
619
619
620
- format = format || query ?. format ;
621
- types = types || query ?. types ;
622
- streams = streams || query ?. streams ;
620
+ const format = query ?. format ;
621
+ const types = query ?. types ;
622
+ const streams = query ?. streams ;
623
623
const portal = query ?. portal || '' ;
624
624
const result = makeResult < T > ( query ?. transform ) ;
625
625
0 commit comments