Ben-xD
Ben-xD
Explore posts from servers
DTDrizzle Team
Created by Ben-xD on 7/29/2024 in #help
How to convert filters (e.g. eq(), ne(), lte(), like()) into SQL string, for use in sql.raw()
I'm trying to use LEFT JOIN LATERAL, but I have a lot of filters already created with drizzle. I would like to use them in my SQL:
const query = sql.raw(`SELECT user.id, message.received_at FROM user LEFT JOIN LATERAL (SELECT message.user_id, message.received_at FROM message WHERE message.user_id = user.id ORDER BY message.received_at LIMIT 1) message on user.id=message.user_id`);
// TODO use other filters too: `AND ${filtersExceptTime?.getSQL()}` doesn't work

const result = await db.execute(query);
const query = sql.raw(`SELECT user.id, message.received_at FROM user LEFT JOIN LATERAL (SELECT message.user_id, message.received_at FROM message WHERE message.user_id = user.id ORDER BY message.received_at LIMIT 1) message on user.id=message.user_id`);
// TODO use other filters too: `AND ${filtersExceptTime?.getSQL()}` doesn't work

const result = await db.execute(query);
5 replies