-
-
Save dagogodboss/7f29366db36d6c58792e714099ffba1e to your computer and use it in GitHub Desktop.
Revisions
-
thecodeboss created this gist
Jul 22, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ import { PrismaClient } from '@prisma/client'; import type { User } from '@prisma/client'; import { createPool, sql } from 'slonik'; export const buildBaseConnectionURL = (config) => { return ( 'postgresql://' + config.DB_USER + ':' + config.DB_PASS + '@' + config.DB_HOST + ':' + config.DB_PORT + '/' + config.DB_NAME ); }; export const buildPrismaDatabaseURL = (config) => { return buildBaseConnectionURL(config) + '?schema=' + config.DB_SCHEMA; }; export const buildSlonikConnectionURL = (config) => { return buildBaseConnectionURL(config) + '?options=-csearch_path=%3d' + config.DB_SCHEMA; } // Prisma Client const prisma = new PrismaClient({ datasources: { db: { url: buildPrismaDatabaseURL(config) } }, }); // Slonik Client const db = createPool(buildSlonikConnectionURL(config)); // Example Prisma query: const users = await prisma.user.findMany(); // Example Slonik query: const users = await db.any<User>(sql`SELECT * FROM "User"`);