Initial commit: Supermarket scraper MVP
This commit is contained in:
24
src/config/database.ts
Normal file
24
src/config/database.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import "dotenv/config";
|
||||
import { PrismaPg } from '@prisma/adapter-pg';
|
||||
import { PrismaClient } from '../../generated/prisma/client.js';
|
||||
|
||||
const connectionString = `${process.env.DATABASE_URL}`;
|
||||
|
||||
const adapter = new PrismaPg({ connectionString });
|
||||
export const prisma = new PrismaClient({ adapter });
|
||||
|
||||
export async function connectDatabase() {
|
||||
try {
|
||||
await prisma.$connect();
|
||||
console.log('✅ Подключение к базе данных установлено');
|
||||
} catch (error) {
|
||||
console.error('❌ Ошибка подключения к базе данных:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function disconnectDatabase() {
|
||||
await prisma.$disconnect();
|
||||
console.log('✅ Отключение от базы данных');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user