Martacus
Martacus
Explore posts from servers
DTDrizzle Team
Created by Martacus on 11/12/2023 in #help
Having trouble writing my sql statement in drizzle. Want to join two variables
I am trying to execute this sql statement with drizzle
SELECT er.*, e1.name AS entity_one_name, e2.name AS entity_two_name
FROM "public"."relation" er
JOIN "public"."entity" e1 ON er."entityOneId" = e1.id
JOIN "public"."entity" e2 ON er."entityTwoId" = e2.id;
SELECT er.*, e1.name AS entity_one_name, e2.name AS entity_two_name
FROM "public"."relation" er
JOIN "public"."entity" e1 ON er."entityOneId" = e1.id
JOIN "public"."entity" e2 ON er."entityTwoId" = e2.id;
But I am having trouble translating this to code. I am currently doing something like this:
const data = await db.select().from(entityRelations).where(or(
eq(entityRelations.entityOne, id),
eq(entityRelations.entityTwo, id)
)).leftJoin(entities, or(
eq(entities.id, entityRelations.entityOne),
eq(entities.id, entityRelations.entityTwo)
));
const data = await db.select().from(entityRelations).where(or(
eq(entityRelations.entityOne, id),
eq(entityRelations.entityTwo, id)
)).leftJoin(entities, or(
eq(entities.id, entityRelations.entityOne),
eq(entities.id, entityRelations.entityTwo)
));
But it's giving me the object two times with only one entity attached. Maybe my sql knowledge isnt up to date or im missing something in drizzle. Are there some examples i could look at?
11 replies
DTDrizzle Team
Created by Martacus on 11/5/2023 in #help
Unable to read error message when inserting withdb.insert().values()
Hey there, i am using visual studio code and am developing with nuxt3. I am trying to insert an object but I am getting an error message that is very difficult to read. Am I doing something wrong? I have no idea what's wrong looking at this..
8 replies