@@ -2,8 +2,8 @@ import { Client } from "pg";
22import { Resource } from "sst" ;
33import { handleCreate } from "./lib/create" ;
44import { handleDestroy } from "./lib/destroy" ;
5- import { type Event , eventSchema , type Response } from "./lib/types" ;
6- import { names } from "./lib/util" ;
5+ import { Action , type Event , eventSchema , type Response } from "./lib/types" ;
6+ import { DB_PORT , names } from "./lib/util" ;
77
88export async function handler ( event : Event ) : Promise < Response > {
99 eventSchema . parse ( event ) ;
@@ -12,13 +12,18 @@ export async function handler(event: Event): Promise<Response> {
1212 const host = Resource . DatabaseHost . value ;
1313 const password = Resource . DatabasePassword . value ;
1414
15- const client = new Client ( { host, port : 5432 , user : "postgres" , password } ) ;
15+ const client = new Client ( {
16+ host,
17+ port : DB_PORT ,
18+ user : "postgres" ,
19+ password,
20+ } ) ;
1621 await client . connect ( ) ;
1722
1823 try {
19- if ( event . action === "create" ) {
24+ if ( event . action === Action . Deploy ) {
2025 return await handleCreate ( client , host , database , username ) ;
21- } else if ( event . action === "destroy" ) {
26+ } else if ( event . action === Action . Remove ) {
2227 return await handleDestroy ( client , database , username ) ;
2328 }
2429 return {
0 commit comments