()
| 104 | } |
| 105 | |
| 106 | export function db(): Db { |
| 107 | if (POOL_ENDED) { |
| 108 | throw new Error("Database already ended"); |
| 109 | } |
| 110 | if (!DB) { |
| 111 | const dbSchema = { |
| 112 | ...schema, |
| 113 | ...relations, |
| 114 | }; |
| 115 | const d = drizzle({ |
| 116 | client: pool(), |
| 117 | schema: dbSchema, |
| 118 | }); |
| 119 | DB = d; |
| 120 | return d; |
| 121 | } |
| 122 | return DB; |
| 123 | } |
| 124 | |
| 125 | export type KeysOfType<T, U> = { |
| 126 | [K in keyof T]: T[K] extends U ? K : never; |