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.
2 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
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