Huge Letters
Huge Letters
Explore posts from servers
HHono
Created by Huge Letters on 6/22/2024 in #help
How to resolve relative routes
No description
10 replies
DTDrizzle 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
{
name: posts.authorName // this is the data I want to return
name: posts.name // this was provided by my cursor helper
}
{
name: posts.authorName // this is the data I want to return
name: posts.name // this was provided by my cursor helper
}
or
{
postedAt: sql`posts.postedAt`.mapWith(formatDate)
postedAt: posts.postedAt // this will result in unexpected data format returned
}
{
postedAt: sql`posts.postedAt`.mapWith(formatDate)
postedAt: posts.postedAt // this will result in unexpected data format returned
}
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
{
name: posts.authorName // this is the data I want to return
dsaffhewqf: posts.name // this was provided by my cursor helper
}
{
name: posts.authorName // this is the data I want to return
dsaffhewqf: posts.name // this was provided by my cursor helper
}
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:
{
name: posts.name // this is the data I want to return
dsaffhewqf: posts.name // this was provided by my cursor helper
}
{
name: posts.name // this is the data I want to return
dsaffhewqf: posts.name // this was provided by my cursor helper
}
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 files
4 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.
await tx.delete(review).where(eq(review.userId, session.user.id));
await tx.delete(session).where(eq(session.userId, session.user.id));
await tx.delete(account).where(eq(account.userId, session.user.id));
await tx.delete(user).where(eq(user.id, session.user.id));
await tx.delete(review).where(eq(review.userId, session.user.id));
await tx.delete(session).where(eq(session.userId, session.user.id));
await tx.delete(account).where(eq(account.userId, session.user.id));
await tx.delete(user).where(eq(user.id, session.user.id));
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.
// client
await postReview(review);
await uploadImage(image);
sync(); // <- I would like this to run only after updateReview on the server finishes

// server - UT router
.middleware(...)
.onUploadComplete(async ({ file, metadata: { data } }) => {
await updateReview(data, file);
}),
// client
await postReview(review);
await uploadImage(image);
sync(); // <- I would like this to run only after updateReview on the server finishes

// server - UT router
.middleware(...)
.onUploadComplete(async ({ file, metadata: { data } }) => {
await updateReview(data, file);
}),
1 replies