1
1
import Config , { ConfigProvider , ResourceInfo } from '@kapeta/sdk-config' ;
2
- const RESOURCE_TYPE = 'kapeta/resource-type-postgresql' ;
3
- const PORT_TYPE = 'postgres' ;
2
+ import { createDBURI } from "./utils" ;
4
3
5
4
interface PrismaClient {
6
5
$connect ( ) : Promise < void > ;
@@ -11,8 +10,6 @@ interface PrismaClient {
11
10
export abstract class PostgresDB < T extends PrismaClient > {
12
11
private readonly _resourceName : string ;
13
12
private _ready : boolean = false ;
14
- private _postgresInfo ?: ResourceInfo ;
15
- private _dbName ?: string ;
16
13
private _prisma ?: T ;
17
14
constructor ( resourceName :string ) {
18
15
this . _resourceName = resourceName ;
@@ -24,22 +21,7 @@ export abstract class PostgresDB<T extends PrismaClient> {
24
21
abstract createClient ( opts : any ) : T ;
25
22
26
23
async init ( provider : ConfigProvider ) {
27
- this . _postgresInfo = await provider . getResourceInfo ( RESOURCE_TYPE , PORT_TYPE , this . _resourceName ) ;
28
- this . _dbName =
29
- this . _postgresInfo . options && this . _postgresInfo . options . dbName
30
- ? this . _postgresInfo . options . dbName
31
- : this . _resourceName ;
32
-
33
- let credentials = '' ;
34
- if ( this . _postgresInfo ?. credentials ?. username ) {
35
- credentials += this . _postgresInfo . credentials . username ;
36
-
37
- if ( this . _postgresInfo . credentials . password ) {
38
- credentials += ':' + this . _postgresInfo . credentials . password ;
39
- }
40
- }
41
-
42
- const url = `postgresql://${ credentials } @${ this . _postgresInfo . host } :${ this . _postgresInfo . port } /${ this . _dbName } ` ;
24
+ const url = createDBURI ( provider , this . _resourceName ) ;
43
25
console . log ( 'Connecting to postgres database: %s' , url ) ;
44
26
45
27
this . _prisma = this . createClient ( {
0 commit comments