feat(csms): add deployment script and database schema for user authentication
This commit is contained in:
24
apps/csms/src/lib/db.ts
Normal file
24
apps/csms/src/lib/db.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { drizzle } from 'drizzle-orm/node-postgres'
|
||||
import { Pool } from 'pg'
|
||||
import * as schema from '@/db/schema.js'
|
||||
|
||||
let pgPoolInstance: Pool | null = null
|
||||
let drizzleInstance: ReturnType<typeof drizzle> | null = null
|
||||
|
||||
export const useDrizzle = () => {
|
||||
if (!pgPoolInstance || !drizzleInstance) {
|
||||
pgPoolInstance = new Pool({
|
||||
connectionString: process.env.DATABASE_CONNECTION_STRING,
|
||||
})
|
||||
drizzleInstance = drizzle({ client: pgPoolInstance, schema })
|
||||
}
|
||||
return drizzleInstance
|
||||
}
|
||||
|
||||
export const closeDrizzle = () => {
|
||||
if (pgPoolInstance) {
|
||||
pgPoolInstance.end()
|
||||
pgPoolInstance = null
|
||||
drizzleInstance = null
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user