@@ -5,28 +5,34 @@ import { z } from 'zod'
5
5
import { defineDatabaseDriver } from '~/lib/db/defineDatabaseDriver'
6
6
7
7
export const postgresDriver = defineDatabaseDriver ( {
8
- envSchema : z . object ( {
9
- DB_POSTGRES_DATABASE : z . string ( ) ,
10
- DB_POSTGRES_HOST : z . string ( ) ,
11
- DB_POSTGRES_USER : z . string ( ) ,
12
- DB_POSTGRES_PASSWORD : z . string ( ) ,
13
- DB_POSTGRES_PORT : z . coerce . number ( ) . int ( ) ,
14
- } ) ,
15
- async setup ( {
16
- DB_POSTGRES_DATABASE ,
17
- DB_POSTGRES_HOST ,
18
- DB_POSTGRES_PASSWORD ,
19
- DB_POSTGRES_PORT ,
20
- DB_POSTGRES_USER ,
21
- } ) {
22
- const pool = new pg . Pool ( {
23
- database : DB_POSTGRES_DATABASE ,
24
- host : DB_POSTGRES_HOST ,
25
- password : DB_POSTGRES_PASSWORD ,
26
- port : DB_POSTGRES_PORT ,
27
- user : DB_POSTGRES_USER ,
28
- max : 10 ,
8
+ envSchema : z
9
+ . object ( {
10
+ DB_POSTGRES_DATABASE : z . string ( ) ,
11
+ DB_POSTGRES_HOST : z . string ( ) ,
12
+ DB_POSTGRES_USER : z . string ( ) ,
13
+ DB_POSTGRES_PASSWORD : z . string ( ) ,
14
+ DB_POSTGRES_PORT : z . coerce . number ( ) . int ( ) ,
29
15
} )
16
+ . or (
17
+ z . object ( {
18
+ DB_POSTGRES_URL : z . string ( ) ,
19
+ } ) ,
20
+ ) ,
21
+ async setup ( options ) {
22
+ const pool = new pg . Pool (
23
+ 'DB_POSTGRES_URL' in options
24
+ ? {
25
+ connectionString : options . DB_POSTGRES_URL ,
26
+ }
27
+ : {
28
+ database : options . DB_POSTGRES_DATABASE ,
29
+ host : options . DB_POSTGRES_HOST ,
30
+ password : options . DB_POSTGRES_PASSWORD ,
31
+ port : options . DB_POSTGRES_PORT ,
32
+ user : options . DB_POSTGRES_USER ,
33
+ max : 10 ,
34
+ } ,
35
+ )
30
36
await pool . connect ( )
31
37
return new PostgresDialect ( {
32
38
pool,
0 commit comments