vapor
vapor
Explore posts from servers
DTDrizzle Team
Created by vapor on 9/12/2024 in #help
Alias join doesn't seem to work
I have a simple alias:
const parent = aliasedTable(contact, "parent")

let res = await db.select().from(policy).leftJoin(parent, eq(parent.id, policy.parent_id))
const parent = aliasedTable(contact, "parent")

let res = await db.select().from(policy).leftJoin(parent, eq(parent.id, policy.parent_id))
the query code works fine, but I cannot access the aliased name in the res. it is still inferring as contact , but the docs show it inferring as parent in the res.
5 replies
TtRPC
Created by vapor on 1/3/2024 in #❓-help
Advanced Permissioning In Middleware
I need to handle somewhat complicated permissioning logic, for example: User A can read (but not write) tasks from Facility B Is there a good pattern for applying this sort of logic in middlewares? Currently, I can create a verbose permission set in Context for that user, but I'm not sure how best to handle a facility-specific route, for example trying to read tasks from Facility B.
The Context will contain all of that user's permissions, but I'm not sure how to check those permissions against a route-specific ID (for example facilityID) in a middleware. I don't think I'd want to set that facilityID in context (since a lot of procedures won't have a facilityID at all) and it doesn't look like there's a way to pass dynamic values into middleware using Meta. Any thoughts?
5 replies
DTDrizzle Team
Created by vapor on 8/29/2023 in #help
Having statement to compare sql<number> and number
Sorry if a dumb question, I'm working on an aggregation query like:
const query = await db
.select({
workerUid: workerStatsDaily.workerUid,
activeInterval: sql<number>`sum(${workerStatsDaily.activeInterval})`,
})
.from(workerStatsDaily)
.where(between(workerStatsDaily.day, input.startDate, input.endDate))
.groupBy(workerStatsDaily.workerUid)
.having((resp) => resp.activeInterval > 3600)
}
const query = await db
.select({
workerUid: workerStatsDaily.workerUid,
activeInterval: sql<number>`sum(${workerStatsDaily.activeInterval})`,
})
.from(workerStatsDaily)
.where(between(workerStatsDaily.day, input.startDate, input.endDate))
.groupBy(workerStatsDaily.workerUid)
.having((resp) => resp.activeInterval > 3600)
}
I'm getting a type error in the last line: Operator '>' cannot be applied to types 'SQL<number>' and 'number'. What's the best way to handle that comparison? Or maybe a having isn't the correct method? Thanks
4 replies
DTDrizzle Team
Created by vapor on 7/10/2023 in #help
Postgres functions
Hey, I'm migrating a ton of postgres raw sql into using drizzle ORM. Is there any sort of setup for migrating sql functions? I have a couple dozen sql functions to convert. Didn't see anything in the docs but thought i'd ask
2 replies
DTDrizzle Team
Created by vapor on 6/27/2023 in #help
Invalid input for drizzle-kit pg:inspect
I'm running a command I've run a couple dozen times before, but now am getting an error saying I need a configuration file for drizzle kit. I added a basic configuration and am getting a generic error saying "invalid input." My drizzle.config.json has a basic out and schema entries, and I double checked the postgres URI is correct.
4 replies
TtRPC
Created by vapor on 6/8/2023 in #❓-help
Middleware-ish for client
Hi! I had a quick question about client-side usage: I have users with long-running sessions, and if they tokens expire the backend returns a 401. In the old codebase I'm migrating from there was a check force a token refresh if certain parameters were met, such as status === 401, route is one of x, etc. Is there a way to handle that on the @trpc/client ? something just like: for any requests, if returned status is 401, and route is one of x, force a token refresh? Thanks!
5 replies
DTDrizzle Team
Created by vapor on 6/7/2023 in #help
Tx Rollback meesage
Hey! If I throw a tx.rollback(), is there a way to specify an error message beyond "Rollback" ? I have a transaction in a try/catch block and would love to specify the failed employeeID and throw a custom error message including the employeeID whos transaction failed
3 replies
DTDrizzle Team
Created by vapor on 5/24/2023 in #help
Option filter parameters
Hi! Love using drizzle so far! Had a quick question (not a bug):
const res = await ctx.database
.select()
.from(worker)
.where(
and(
eq(worker.locationUid, input.location),
isNull(worker.deletedAt),
ilike(worker.name, "%{input.name}%")
)
)
const res = await ctx.database
.select()
.from(worker)
.where(
and(
eq(worker.locationUid, input.location),
isNull(worker.deletedAt),
ilike(worker.name, "%{input.name}%")
)
)
If I have a query like this, and input.name might be null (in which case I want to skip filtering by this), is there a short-hand for enabling that behavior? Right now I'm putting filters into an array like:
[..., input.name && ilike(worker.name, "%{input.name}%) : null].filter(v => v)
[..., input.name && ilike(worker.name, "%{input.name}%) : null].filter(v => v)
which is fine, just wondering if this is a good approach. thanks!
11 replies