MiNiMAL
Explore posts from serversFunction to release context post-batching?
In our application every customer has their own schema, therefore we need a db client per request which I was hoping to leverage with TRPC context.
Ideally, we'd be able to:
- Connect to the database in context ✅
- Set the
search_path
to match the client's JWT in context ✅
- Run our procedures using that database connection from context ✅
- Release the database connection after all batching is finished ❌
Is this not currently possible with TRPC? Right now I think I can only connect to the database using a per procedure middleware.
This works, but it requires establishing a connection/search_path for every procedure in a batch, instead of just once in context and releasing after the batch. Is there a way to accomplish this?13 replies
Dynamic input not leading to changes on the front end
I'm building a dynamic procedure to access my database via Drizzle ORM.
Ideally a developer would be able to send input parameters to the procedure and have it's output adjusted by that input.
For example, in the below, I have a table called
demotable
which has an updatedAt
column. If a developer passes in columns: { updatedAt: false }
to the procedure, then ideally the column would not get included in the result.
If I hard code the columns
parameter in the backend itself, then it works great. Is there a way to accomplish this for the full round trip?
4 replies
DTDrizzle Team
•Created by MiNiMAL on 10/14/2023 in #help
Front to back end type inference with parameters sent via request
Hey there, I've been exploring using drizzle in a TRPC environment. This is probably a pipe dream, but ideally, our developers would be able to dynamically pass a
findMany
input and have the query's results inferred all the way to the front end.
The first issue I encountered is that there needs to be a translation layer for the where
statements, as we cannot send drizzle operator functions over a request. To handle this, I built out a recursive layer for where
statements at the root and also in any nested with
and it works functionally very well (though is only strongly typed at the root layer).
Example:
The above's operators and column names all have type inference/intellisense based on the DB model.
The above turns into this on the backend:
Is this a fine approach?
Unfortunately, while I have it functionally working with nested where
statements inside of with
clauses, when I try to get the types to be inferred all the way down I end up with:
error TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.My question is - has anyone tried full front to back end type inference? Or even just how to best handle findMany params via the request?
16 replies
Best practices for implementing an offline application
Hey there! I'm building a full stack react-native app with Expo and a tRPC backend. I'd like for this app to be functional offline. Currently I'm accomplishing this via a simple optimistic update like:
This is working pretty well (it's late and I plan on extensively testing this tomorrow). I'd like to confirm what best practices, if any, have been established by the community before continuing.
2 replies