P
Prisma4w 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
ptrxyz4w ago
any ideas anyone?
RaphaelEtim
RaphaelEtim4w 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
ptrxyz4w ago
yes! So I can simply wrap the queries in a new Prisma.sql?
RaphaelEtim
RaphaelEtim4w ago
Yes you can
ptrxyz
ptrxyz4w ago
Thanks a lot! I'll give it a try!
Want results from more Discord servers?
Add your server