azn4lifee
azn4lifee
DTDrizzle Team
Created by azn4lifee on 8/8/2023 in #help
How can I declare a relationship with a SELECT statement?
I have 2 tables, iot_device and iot_device_status, where the status table saves all current and historical statuses of each device. I like to join the tables together as so:
SELECT i.id, i.name, data.lost, data.created_at FROM iot_device i
INNER JOIN LATERAL (
SELECT * FROM iot_device_status s
WHERE s.device = i.id
ORDER BY created_at DESC LIMIT 1
) AS data
ON true
ORDER BY i.id, data.created_at DESC;
SELECT i.id, i.name, data.lost, data.created_at FROM iot_device i
INNER JOIN LATERAL (
SELECT * FROM iot_device_status s
WHERE s.device = i.id
ORDER BY created_at DESC LIMIT 1
) AS data
ON true
ORDER BY i.id, data.created_at DESC;
I noticed relations only take in a pgTable. How can I make it so that it takes the result of the given SQL statement instead?
8 replies
DTDrizzle Team
Created by azn4lifee on 8/8/2023 in #help
How can I derive the database type with schemas without instantiating it?
In our data service layer, we are looking to require a drizzle db parameter for our functions to accommodate multitenancy. However, we still want this parameter to be typed with our schemas. How can I achieve that?
1 replies
DTDrizzle Team
Created by azn4lifee on 8/3/2023 in #help
How can I reference the RelationalQueryBuilder and RelationalQuery types?
These types are currently not exported from the library AFAIK. I would like to reference these types to build a generic query builder for our internal use. How can I get to them?
1 replies