Huge Letters
Explore posts from serversDTDrizzle Team
•Created by Huge Letters on 6/18/2024 in #help
Need a sanity check on my idea for cursor pagination helper
I wanna create a helper to manage cursor-based pagination with Drizzle.
To create a cursor your select query needs to contain the columns on which your data is ordered - so you need to include those columns in select.
But my concern is that that may cause collisions
say
or
So I thought what if I would hash the keys provided with the cursor config - these have to be defined only once on app start-up so hashing perf cost is minimal.
and then what I will get is something like
And then I will also provide the helper which will remove these keys from returned array so that some junk doesn't go to the client
The only downside here is that sometimes columns may be returned twice:
but I'm not sure how bad this is
sooo... I just want a sanity check really. Does that sound like an okay-ish idea?
1 replies
DTDrizzle Team
•Created by Huge Letters on 4/6/2024 in #help
Generate SQL statements with Drizzle
I wanna generate statements using Drizzle utilities - for example I have this
sql`DROP TRIGGER IF EXISTS ${sql.identifier(triggerName)}`
But how do I get the final SQL string from this?
db.run(...).getQuery()
works but feels counter-intuitive - is that the best way to do that?
In case that's important - what I wanna do is create some utils to automate trigger creation a bit - so I could generate trigger statements with Drizzle and then insert those into my migration files4 replies
TTCTheo's Typesafe Cult
•Created by Huge Letters on 3/8/2024 in #questions
onUploadComplete and onUploadError
Do I understand correctly that throwing error in
onUploadComplete
won't trigger onUploadError
? I just need to return errors as values from onUploadComplete
and check manually in onClientUploadComplete
?3 replies
DTDrizzle Team
•Created by Huge Letters on 2/3/2024 in #help
Batching statements in MySQL transactions
I'm using Drizzle with Planetscale - I have a transaction which kinda looks like this.
The thing is as far as I understand - for every step of the transaction a request is made to my Planetscale database which makes sense given I might need a result of this statement, maybe I need to know how many rows were affected. Because of this this transaction basically makes 4 separate requests to Planetscale.
Is there a way to tell Drizzle to just batch this 4 statements as a single request? Given that I don't care about the result of a statement, only if it was successful or not - I only care that these 4 statements are executed in sequence.
If that's not possible - is that a limitation of Drizzle, Planetscale or SQL in general?
21 replies
TTCTheo's Typesafe Cult
•Created by Huge Letters on 10/22/2023 in #questions
What to store on my server?
What's the usual pattern to store references to UT-files in my database? I store file keys since then using the key I can make a request to UT to get file url. Is that how most people do it? Or actually you should store urls directly? In that case I don't really understand how can I delete files w/o doing some complicated and bloated checks
7 replies
TTCTheo's Typesafe Cult
•Created by Huge Letters on 9/6/2023 in #questions
Await server onUploadComplete hook on the client.
Is there a way or a recommended pattern to run some side effect in the
onUploadComplete
hook in UT router and only once it's done resolve startUpload
promise on the client?
In my app a user can leave a review with an image attached - first client sends a request with review data and it gets saved to the database, once that resolves client starts an image upload and in the onUploadComplete
hook on the server I update the db review row with a newly created file key.
Problem is - I would like to refetch review data on the client to sync it with the server once data is successfully updated. But there doesn't seem to be a mechanism to await until onUploadComplete
resolves and so what I got is a race condition if a client's sync request will be after(good) or before(bad) hook updates my db with new file key.
Code more or less looks like this.
1 replies