@@ -5,14 +5,22 @@ import type { SupportedSQLDatabaseDialect } from "../translators/sql-translator.
5
5
import type { QueryDescription } from "../query-builder.ts" ;
6
6
import type { Values } from "../data-types.ts" ;
7
7
8
- export interface PostgresOptions extends ConnectorOptions {
8
+ interface PostgresOptionsWithConfig extends ConnectorOptions {
9
9
database : string ;
10
10
host : string ;
11
11
username : string ;
12
12
password : string ;
13
13
port ?: number ;
14
14
}
15
15
16
+ interface PostgresOptionsWithURI extends ConnectorOptions {
17
+ uri : string ;
18
+ }
19
+
20
+ export type PostgresOptions =
21
+ | PostgresOptionsWithConfig
22
+ | PostgresOptionsWithURI ;
23
+
16
24
export class PostgresConnector implements Connector {
17
25
_dialect : SupportedSQLDatabaseDialect = "postgres" ;
18
26
@@ -24,13 +32,17 @@ export class PostgresConnector implements Connector {
24
32
/** Create a PostgreSQL connection. */
25
33
constructor ( options : PostgresOptions ) {
26
34
this . _options = options ;
27
- this . _client = new PostgresClient ( {
28
- hostname : options . host ,
29
- user : options . username ,
30
- password : options . password ,
31
- database : options . database ,
32
- port : options . port ?? 5432 ,
33
- } ) ;
35
+ if ( "uri" in options ) {
36
+ this . _client = new PostgresClient ( options . uri ) ;
37
+ } else {
38
+ this . _client = new PostgresClient ( {
39
+ hostname : options . host ,
40
+ user : options . username ,
41
+ password : options . password ,
42
+ database : options . database ,
43
+ port : options . port ?? 5432 ,
44
+ } ) ;
45
+ }
34
46
this . _translator = new SQLTranslator ( this . _dialect ) ;
35
47
}
36
48
0 commit comments