noob help: INSERT with JOIN SQL to Drizzle

Frontend developer dabbling with SQL for the first time in years. With the help of ChatGPT I have the following query which works as intended. How do I construct with Drizzle such that I can supply my values using the .values() method?
INSERT INTO billing (team_id, credit_change, credits, type)
SELECT teams.id, billing.credit_change, teams.credits + billing.credit_change, 'runtime'
FROM teams
JOIN (
VALUES
(1, 100),
(2, 200),
(3, 150)
) AS billing(team_id, credit_change)
ON teams.id = billing.team_id;
INSERT INTO billing (team_id, credit_change, credits, type)
SELECT teams.id, billing.credit_change, teams.credits + billing.credit_change, 'runtime'
FROM teams
JOIN (
VALUES
(1, 100),
(2, 200),
(3, 150)
) AS billing(team_id, credit_change)
ON teams.id = billing.team_id;
AS
Andrii Sherman349d ago
L
Luca349d ago
Thanks, what's a temporary workaround that I can employ in the meantime? Is it possible to use the sql`` operator somehow?
AS
Andrii Sherman349d ago
yes you can use it
D
DivMode232d ago
Looking to do something similiar, were you able to get it working @Luca?
Want results from more Discord servers?
Add your server
More Posts
OrderBy with dynamic queries dont work``` ....orderBy(sql`${products.xyz} ${order}`) ``` ``` error: syntax error at or near "$2" ``` ordeIs there a way to limit update to just 1 document?I know there will be multiple documents matching this where query, but I only want to update 1 of thHow to get InferModel to work with Relation model?Is there a way to get the infer type for a relation model? eg: type User = InferModel<typeof users,MySQL column type: "Generated"?Does drizzle support defining generated columns? https://planetscale.com/courses/mysql-for-developeAnyone else having a weird issue with drizzle-kit push:mysql?I spun up a new project using Planetscale and I got a bizarre __vtschema error (see: https://github.Performance questionsI'm using Drizzle ORM with Planetscale DatabaseJS driver and my application has spots where I want tCan drizzle generate an initial schema from an existing db?I have a db that wasn't built using drizzle, but I'm interesting in moving over to it. Do I need toPrepared StementsI was looking into using AWS RDS Proxy with Prisma and ran into this https://www.prisma.io/docs/guiReact Native SupportHi all New to drizzle ORM, does it support React Native? Thanksupdate multiple rowsHow can I update values in multiple rows at once?Running `drizzle-kit introspect:pg` returns "client password must be a string"I'm attempting to move from objection.js+knex.js over to Drizzle and I'm running `drizzle-kit introsnoob help : transaction not acid``` return await this.drizzle.db.transaction(async (trx) => { const u = await trx .seExplicit inferred types```ts async loginWithGoogle(user: NonNullable<Request['user']>) { const existingUser = await thiMany-to-Many where in far tableI'm trying to `findMany()` Pokemon(s) by a type name ``` pokemons pokemonsToType