Sillvva
DTDrizzle Team
•Created by Deen24ID on 5/18/2025 in #help
Issues from a WITH clause (CTE).
Updated the above query
8 replies
DTDrizzle Team
•Created by Deen24ID on 5/18/2025 in #help
Issues from a WITH clause (CTE).
Oh, add .as() to the max function.
max(schema.price.lastUpdatedAt).as("lastUpdatedAt")
To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:
If you don’t provide an alias, the field type will become DrizzleTypeError and you won’t be able to reference it in other queries. If you ignore the type error and still try to use the field, you will get a runtime error, since there’s no way to reference that field without an alias.
8 replies
DTDrizzle Team
•Created by Deen24ID on 5/18/2025 in #help
Issues from a WITH clause (CTE).
@Deen24ID pinging for notification
8 replies
DTDrizzle Team
•Created by salzar on 5/13/2025 in #help
Seems like the schema generic is missing - did you forget to add it to your DB type?
I think the config file is primarily for migrations. You still need to pass it to the
drizzle()
init for runtime code.8 replies
DTDrizzle Team
•Created by Little Cutie Penguin 🐧 on 5/12/2025 in #help
How to infer connection type in TypeScript?
If you have the RQBv2 beta installed, it would look like this:
3 replies
DTDrizzle Team
•Created by Little Cutie Penguin 🐧 on 5/12/2025 in #help
How to infer connection type in TypeScript?
I think this is what you're looking for. I use postgres, so I'm not 100% on this.
With this, the type you're looking for is
Database | Transaction
3 replies
DTDrizzle Team
•Created by Mike on 5/8/2025 in #help
How do I make Drizzle infer the correct return type when dynamically adding a custom select field
In Cursor, I right clicked on the select method and opened its reference. SelectedFields is the select method's parameter type.
6 replies
DTDrizzle Team
•Created by Aditya Kirad on 5/8/2025 in #help
getting the returning data after inserting record as string | undefined instead of string
I believe it also rolls back if an error is thrown. That's all the rollback function does internally.
19 replies
DTDrizzle Team
•Created by Aditya Kirad on 5/8/2025 in #help
getting the returning data after inserting record as string | undefined instead of string
On this line, you should
throw
. tx.rollback()
throws internally, but I guess TS doesn't realize that. Adding throw
adds the type narrowing you're looking for. Otherwise, TS assumes the code is allowed to continue. And since userId hasn't been defined in the undefined case, it can still be undefined.
19 replies
DTDrizzle Team
•Created by Aditya Kirad on 5/8/2025 in #help
getting the returning data after inserting record as string | undefined instead of string
I prefer having that property on in all my projects, because it catches potential runtime errors that TS wouldn't otherwise catch.
Example with it off:
https://www.typescriptlang.org/play/#code/MYewdgzgLgBGCuBbARgUwE4QFxyW9A2gLowC8MxA3AFDWiSxhm4oYQEAMRNA9DzAJgA9APxA
Example with it on:
https://www.typescriptlang.org/play/?noUncheckedIndexedAccess=true#code/MYewdgzgLgBGCuBbARgUwE4QFxyW9A2gLowC8MxA3AFDWiSxhm4oYQEAMRNA9DzAJgA9APxA
19 replies
DTDrizzle Team
•Created by Aditya Kirad on 5/8/2025 in #help
getting the returning data after inserting record as string | undefined instead of string
I see. In your postgres app, do you have
"noUncheckedIndexedAccess": true,
in your tsconfig? That causes the behavior I described.19 replies
DTDrizzle Team
•Created by Aditya Kirad on 5/8/2025 in #help
getting the returning data after inserting record as string | undefined instead of string
@Aditya Kirad ping for notification
19 replies
DTDrizzle Team
•Created by Mike on 5/8/2025 in #help
How do I make Drizzle infer the correct return type when dynamically adding a custom select field
Ping for notification
6 replies
DTDrizzle Team
•Created by Mike on 5/8/2025 in #help
How do I make Drizzle infer the correct return type when dynamically adding a custom select field
I think the following changes fix the return type. See the 4 comments:
6 replies
DTDrizzle Team
•Created by Aditya Kirad on 5/8/2025 in #help
getting the returning data after inserting record as string | undefined instead of string
TypeScript can't assume an array has a first value.
The same is true regardless of how you try to access it.
This is different from a tuple type.
If the second insert query relies on the first, then you should wrap it in an if statement.
19 replies
DTDrizzle Team
•Created by T. on 5/5/2025 in #help
Referencing Column at runtime
Here's how I'd do it:
2 replies
DTDrizzle Team
•Created by ArChak on 7/5/2024 in #help
How to check user input is a valid column before appending condition?

4 replies
DTDrizzle Team
•Created by ArChak on 7/5/2024 in #help
How to check user input is a valid column before appending condition?
Can you show the how you defined the columnFilters variable?
4 replies
DTDrizzle Team
•Created by magicspon on 7/4/2024 in #help
How to query many to many? Are the docs out of date?
Alternatively
7 replies