db connect
This commit is contained in:
31
lib/cloudinary.ts
Normal file
31
lib/cloudinary.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { v2 as cloudinary } from 'cloudinary';
|
||||
|
||||
cloudinary.config({
|
||||
cloud_name: process.env.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME,
|
||||
api_key: process.env.NEXT_PUBLIC_CLOUDINARY_API_KEY,
|
||||
api_secret: process.env.NEXT_PUBLIC_CLOUDINARY_API_SECRET,
|
||||
});
|
||||
|
||||
/**
|
||||
* Uploads a buffer to Cloudinary into a specified project subfolder.
|
||||
* @param buffer - Image buffer
|
||||
* @param projectSlug - The slug of the project to create a subfolder for
|
||||
*/
|
||||
export async function uploadBuffer(buffer: Buffer, projectSlug: string): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const uploadStream = cloudinary.uploader.upload_stream(
|
||||
{
|
||||
folder: `aycanur-projects/${projectSlug}`,
|
||||
use_filename: true,
|
||||
unique_filename: true
|
||||
},
|
||||
(error, result) => {
|
||||
if (result) resolve(result.secure_url);
|
||||
else reject(error);
|
||||
}
|
||||
);
|
||||
uploadStream.end(buffer);
|
||||
});
|
||||
}
|
||||
|
||||
export default cloudinary;
|
||||
20
lib/prisma.ts
Normal file
20
lib/prisma.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { Pool } from 'pg';
|
||||
import { PrismaPg } from '@prisma/adapter-pg';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
const globalForPrisma = global as unknown as { prisma: PrismaClient };
|
||||
|
||||
// Robustly get connection string with fallback
|
||||
const connectionString = process.env.DATABASE_URL || "postgres://postgres:P9cIY8Ji1iSXOCRs9q6WbOo5xeXCdzyQjYoQ511Zmq1RY8WHLU9YKBGyjDpJ02sa@65.109.236.58:6482/postgres";
|
||||
|
||||
const pool = new Pool({ connectionString });
|
||||
const adapter = new PrismaPg(pool);
|
||||
|
||||
export const prisma =
|
||||
globalForPrisma.prisma ||
|
||||
new PrismaClient({
|
||||
adapter,
|
||||
log: ['query'],
|
||||
});
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma;
|
||||
Reference in New Issue
Block a user