d1ge
d1ge
DTDrizzle Team
Created by d1ge on 9/23/2023 in #help
drizzle-kit generate:pg - generates incorrect reference to table in another schema?
Yeah, thats what i will do for now. And with some automated checks/rules in my migrate.ts file, i guess its to overcome! Appreciate your guidance very much 🙂
9 replies
DTDrizzle Team
Created by d1ge on 9/23/2023 in #help
drizzle-kit generate:pg - generates incorrect reference to table in another schema?
I looked at that one as well, but tought that this part:
However, you can use schemas in PostgreSQL on the ORM level without any issues and with drizzle-kit, without naming tables the same across schemas.
However, you can use schemas in PostgreSQL on the ORM level without any issues and with drizzle-kit, without naming tables the same across schemas.
Meant that all would be "ok ish" as long as i dont name tables the same. I guess this is not true when referencing tables in other schemas then? Postgres throws up when trying to migrate that file, cause i guess its looking for the users table, in its default search_path?
9 replies
DTDrizzle Team
Created by Jim on 9/23/2023 in #help
Help understanding relations
Try:
const query = await db.query.users.findFirst({
where: eq(users.username, "johnsmith"),
with: {
pagebuilder: true,
},
}).toSQL()

console.log(query);
const query = await db.query.users.findFirst({
where: eq(users.username, "johnsmith"),
with: {
pagebuilder: true,
},
}).toSQL()

console.log(query);
To see what its doing behind the scenes 🙂 Might explain it all!
3 replies
DTDrizzle Team
Created by srigi on 5/30/2023 in #help
Many-to-Many where in far table
Something like this?:
const items = await db.select()
.from(psychologists)
.innerJoin(psychologistsToSpecials, and(
eq(psychologists.id, psychologistsToSpecials.psychologistId),
input.specialId ? eq(psychologistsToSpecials.specialId, input.specialId) : undefined,
))
.orderBy(asc(psychologists.id))
.limit(input.limit + 1)
.where(whereParams)
const items = await db.select()
.from(psychologists)
.innerJoin(psychologistsToSpecials, and(
eq(psychologists.id, psychologistsToSpecials.psychologistId),
input.specialId ? eq(psychologistsToSpecials.specialId, input.specialId) : undefined,
))
.orderBy(asc(psychologists.id))
.limit(input.limit + 1)
.where(whereParams)
8 replies
DTDrizzle Team
Created by srigi on 5/30/2023 in #help
Many-to-Many where in far table
So how would i do this using the query builder?
SELECT
p.id,
p.name,
p.clinic_name,
p.address,
p.zip_code,
p.city,
p.picture,
p.email,
p.website,
p.description,
p.phone,
p.tags,
p.subsidies,
p.municipality_id,
p.region_id,
p.active
FROM
psychologists p
JOIN
psychologists_to_audiences pta ON p.id = pta.psychologist_id
WHERE
pta.audience_id = 'YOUR_AUDIENCE_ID';
SELECT
p.id,
p.name,
p.clinic_name,
p.address,
p.zip_code,
p.city,
p.picture,
p.email,
p.website,
p.description,
p.phone,
p.tags,
p.subsidies,
p.municipality_id,
p.region_id,
p.active
FROM
psychologists p
JOIN
psychologists_to_audiences pta ON p.id = pta.psychologist_id
WHERE
pta.audience_id = 'YOUR_AUDIENCE_ID';
8 replies
DTDrizzle Team
Created by srigi on 5/30/2023 in #help
Many-to-Many where in far table
So docs is incorrect then, or is it only supported for one-to-many? https://orm.drizzle.team/docs/rqb#select-filters
8 replies
DTDrizzle Team
Created by srigi on 5/30/2023 in #help
Many-to-Many where in far table
did you figure out what was wrong? Just hit the same wall ish.
8 replies