P
Prisma3mo ago
ptrxyz

concat two Prisma.sql queries.

I have two pretty complex queries which i created manually using
const a = Prisma.sql(...)
const b = Prisma.sql(...)
const a = Prisma.sql(...)
const b = Prisma.sql(...)
In some cases and since both return the same data type, I would like to run them in one go concatenated using (QUERY1) UNION (QUERY2). So, my question is: How can I concat two Prisma.sql queries?
5 Replies
ptrxyz
ptrxyzOP3mo ago
any ideas anyone?
RaphaelEtim
RaphaelEtim3mo ago
Hi @ptrxyz Would this example work for you?
const query1 = Prisma.sql`SELECT id, name FROM "User" WHERE name = ${inputString1}`;
const query2 = Prisma.sql`SELECT id, name FROM "User" WHERE name = ${inputString2}`;

const combinedQuery = Prisma.sql`${query1} UNION ${query2}`;

const result = await prisma.$queryRaw(combinedQuery);
const query1 = Prisma.sql`SELECT id, name FROM "User" WHERE name = ${inputString1}`;
const query2 = Prisma.sql`SELECT id, name FROM "User" WHERE name = ${inputString2}`;

const combinedQuery = Prisma.sql`${query1} UNION ${query2}`;

const result = await prisma.$queryRaw(combinedQuery);
ptrxyz
ptrxyzOP3mo ago
yes! So I can simply wrap the queries in a new Prisma.sql?
RaphaelEtim
RaphaelEtim3mo ago
Yes you can
ptrxyz
ptrxyzOP3mo ago
Thanks a lot! I'll give it a try!
Want results from more Discord servers?
Add your server