27 lines
727 B
TypeScript
27 lines
727 B
TypeScript
import { Module } from '@nestjs/common';
|
|
import { ConfigService } from '@nestjs/config';
|
|
import { drizzle } from 'drizzle-orm/node-postgres';
|
|
import pkg from 'pg';
|
|
import * as schema from './schema';
|
|
import { PG_CONNECTION } from './schema';
|
|
const { Pool } = pkg;
|
|
@Module({
|
|
providers: [
|
|
{
|
|
provide: PG_CONNECTION,
|
|
inject: [ConfigService],
|
|
useFactory: async (configService: ConfigService) => {
|
|
const connectionString = configService.get<string>('DATABASE_URL');
|
|
const pool = new Pool({
|
|
connectionString,
|
|
// ssl: true,
|
|
});
|
|
|
|
return drizzle(pool, { schema, logger: true });
|
|
},
|
|
},
|
|
],
|
|
exports: [PG_CONNECTION],
|
|
})
|
|
export class DrizzleModule {}
|