File tree Expand file tree Collapse file tree 2 files changed +3
-36
lines changed
Expand file tree Collapse file tree 2 files changed +3
-36
lines changed Original file line number Diff line number Diff line change @@ -17,47 +17,13 @@ if (import.meta.main) {
1717}
1818```
1919
20- Where each component is defined as a lifecycle component, in one of two ways:
21-
22- ``` ts
23- import { type LifecycleComponent } from ' @antman/lifecycle' ;
24- import { Pool } from ' pg'
25-
26- type Db = LifecycleComponent & { pool: Pool };
27-
28- const { DB_USER, DB_HOST, DB_PASSWORD, DB_PORT } = Deno .env .toObject ();
29-
30- export const db: Db = {
31- name: ' db' ,
32- status: ' pending' ,
33- pool: new Pool ({
34- user: DB_USER ,
35- password: DB_HOST ,
36- host: DB_PASSWORD ,
37- port: DB_PORT ,
38- }),
39- async start() {
40- // check database connected successfully
41- await db .pool .query (' SELECT 1' );
42- db .status = ' running' ;
43- },
44- async close() {
45- await db .pool .end ();
46- db .status = ' pending'
47- }
48- }
49- ```
50-
51- or
20+ Where each component is defined as a lifecycle component:
5221
5322``` ts
5423class DatabasePool implements LifecycleComponent {
55- readonly name: ' db' ;
56- status: LifecycleComponent [' status' ];
5724 pool: Pool ;
5825 constructor () {
5926 this .name = ' db' ;
60- this .status = ' pending' ;
6127 this .pool = new Pool ({
6228 user: DB_USER ,
6329 password: DB_HOST ,
@@ -73,6 +39,7 @@ class DatabasePool implements LifecycleComponent {
7339 await this .pool .end ();
7440 this .status = ' pending'
7541 }
42+ checkHealth: undefined ; // Optionally, can implement a health check for a component.
7643}
7744export const db = new DatabasePool ();
7845```
Original file line number Diff line number Diff line change 11{
22 "name" : " @antman/lifecycle" ,
3- "version" : " 0.2.0 " ,
3+ "version" : " 0.2.1 " ,
44 "exports" : " ./mod.ts" ,
55 "tasks" : {
66 "dev" : " deno test --watch"
You can’t perform that action at this time.
0 commit comments