mcgrealife
Explore posts from serversDTDrizzle Team
•Created by mcgrealife on 6/15/2023 in #help
Generic update component using table schema – how to type the table argument?
SOLVED: by inspecting the query builder methods, and typing the args to match
This has the unexpected benefit of moving the complexity (and flexibility!) to the caller. For example, instead of defining only one keyName, the function now accepts "values", and can update any number of values!
Also thanks to @ngregrichardson https://discord.com/channels/1043890932593987624/1105287645363441704/1105287645363441704
4 replies
DTDrizzle Team
•Created by Noahh on 5/9/2023 in #help
Typing columns based on Table
@ngregrichardson nice! do you have ane example using the
paginatedQuery
? I am having trouble passing a value that satisfies TTable type.4 replies
DTDrizzle Team
•Created by mcgrealife on 6/15/2023 in #help
Generic update component using table schema – how to type the table argument?
If I change
.update(args.model)
to .update(schema.users)
the .set() method does not error?
4 replies
DTDrizzle Team
•Created by mcgrealife on 6/15/2023 in #help
Generic update component using table schema – how to type the table argument?
AnyMySqlTable
didn't work as expected
Removing the checkbox for simplicity.
I'm getting a little closer like this:
Error:
4 replies
DTDrizzle Team
•Created by Shubham-Sinha on 6/3/2023 in #help
How to type results that includes relations ?
if you invoke findMany() inside a function, you can infer the ReturnType of the function https://discord.com/channels/1043890932593987624/1112458428070236229/1112519441561956352
3 replies
DTDrizzle Team
•Created by BREAD on 5/31/2023 in #help
Performance questions
@BREAD have you considered edge runtimes? In my case, the cold start time of lambdas node runtime is where most of the overhead occurs. In edge runtimes though, the cold start is milliseconds. From there, Most multiple round trips to the database are near-negligible difference on total duration. As long as the edge runtime region is limited to be near the PlanetScale MySql server (both in US-east in my case)
40 replies
DTDrizzle Team
•Created by foreach2845 on 6/1/2023 in #help
How to get InferModel to work with Relation model?
@foreach
I'm not sure if there is a specific helper to InferModel with types from relations (that looks like a clean syntax you propose though ^), but in case you are attempting to infer the type of a relation query, it's possible to wrap the query in a function and Infer the ReturnType of that https://discord.com/channels/1043890932593987624/1112458428070236229/1112519441561956352
2 replies
DTDrizzle Team
•Created by Dbeg on 5/28/2023 in #help
Infer type for relational query
Ah I see. I answered a different question. Confirmed that my relation queries definitely infer their own return types (without manual type annotation)!
I answered from the context of nextjs api files. Where the
export
type keyword can only be used in the outer scope. So I wrap the db query in a function defined in the outer scope, invoke that function from the inner scope, but export it's return type in the outer scope.
Thanks Cayter12 replies
DTDrizzle Team
•Created by mcgrealife on 5/28/2023 in #help
`$with` example in docs error "unsupported: with expression in select statement"
Ah yes, I see now that error is from PlanetScale, not drizzle.
I should have searched first https://github.com/planetscale/discussion/discussions/270
Thanks to both 🙌
6 replies
DTDrizzle Team
•Created by mcgrealife on 5/28/2023 in #help
`$with` example in docs error "unsupported: with expression in select statement"
I am using mysql via planetscale (sorry i'll mention next time)
Note: the nearly identical subquery (without the $with) in the docs right below the $with section does work.
https://orm.drizzle.team/docs/crud#select-from-subquery
6 replies
DTDrizzle Team
•Created by Dbeg on 5/28/2023 in #help
Infer type for relational query
Ah yes, I should have mentioned this too!
Your Awaited implementation is actually cleaner than mine!, but same idea to unwrap the promise, yes!
I have been using NonNullable anytime I use the type – it is much better to use it directly in the custom type definition! Thanks for the tip @Dbeg 👍
12 replies
DTDrizzle Team
•Created by Dbeg on 5/28/2023 in #help
Infer type for relational query
@Dbeg I have achieved this by moving the query inside of a function, then using typescript's ReturnType helper.
I am using this pattern in nextjs api routes
12 replies
DTDrizzle Team
•Created by mcgrealife on 5/27/2023 in #help
Relation query `extras` needs access to `with`
Maybe this is what the docs are mentioning:
As of now aggregations are not supported in extras, please use core queries for thathttps://orm.drizzle.team/docs/rqb#include-custom-fields which is no problem, because I am discovering the
sql
operator really is magic! 👍2 replies
DTDrizzle Team
•Created by mcgrealife on 5/27/2023 in #help
Optional filter param, coalesce to true?
Thanks to both! Being able to use javascript inside a query builder is delightful. 🙌
8 replies
DTDrizzle Team
•Created by raaden on 5/21/2023 in #help
Missing 'with' clause additional operators (where, limit, offset, etc)
I have a query that uses
where
within a with
2 replies
DTDrizzle Team
•Created by mcgrealife on 5/26/2023 in #help
Relational query, Planetscale throws: `ResourceExhausted desc = Out of sort memory`
EDIT: Wow, I had a rogue json column storing a massive value on each row. I deleted that and now it's working perfectly 🙌
9 replies
DTDrizzle Team
•Created by mcgrealife on 5/26/2023 in #help
Relational query, Planetscale throws: `ResourceExhausted desc = Out of sort memory`
for now, I will just do multiple select() queries (non relational), since they do not have memory issues
9 replies
DTDrizzle Team
•Created by mcgrealife on 5/26/2023 in #help
Relational query, Planetscale throws: `ResourceExhausted desc = Out of sort memory`
In my schema, if I comment out my other 76 properties columns (without db push), the query succeeds! (even as a findMany).
Here is the drizzle logged raw sql:
But if I comment the columns back in, and execute the same raw sql query that only uses the required columns, it fails with the same error:
Because the drizzle query generated from the db.execute(sql``) query does contain the other 76 (many json) columns again
So maybe the issue is a combination of:
- drizzle query is over-selecting
- my table has many json column types (even though the actual data stored in the json is much less than 1.6Mib total)
9 replies
DTDrizzle Team
•Created by mcgrealife on 5/26/2023 in #help
Relational query, Planetscale throws: `ResourceExhausted desc = Out of sort memory`
EDIT: https://stackoverflow.com/questions/29575835/error-1038-out-of-sort-memory-consider-increasing-sort-buffer-size
Some mysql users report this error when using large json columns.
So maybe it is related to by ~30 json columns.
My json columns are only storing small array of strings.
But maybe the drizzle query could be optimized to only select the columns necessary for the relation lookup query? (or maybe sql requires it)
9 replies
DTDrizzle Team
•Created by mcgrealife on 5/26/2023 in #help
Relational query, Planetscale throws: `ResourceExhausted desc = Out of sort memory`
Here are my relations definitions
9 replies