santi
santi
Explore posts from servers
PPrisma
Created by santi on 12/21/2024 in #help-and-questions
Supabase/Prisma DB Issues
Hi all, We've noticed a few different issues with our postgres instance via Prisma (hosted in Supabase). We're having a hard-time identifying what's missing in order to fix these errors. Ideally, something is misconfigured / with your help, we can fix these issues. Database health wise, utilization on average seems healthy (but has spiked some days). We use Primsa as our ORM / many of these errors are in Prisma-speak Here are some of the errors we've seen: - Error in connector: error querying the database: unexpected message from server - Can't reach database server at ... - Timed out fetching a new connection from the connection pool. More info: http://pris.ly/d/connection-pool (Current connection pool timeout: 30, connection limit: 1) - Transaction API error: Transaction already closed: A batch query cannot be executed on an expired transaction. The timeout for this transaction was 5000 ms, however 6357 ms passed since the start... - Server has closed the connection. - X does not exist -> this one has many forms, sometimes tables/relations relation "Product" does not exist, sometimes extensions type "hstore" does not exist". In each case we've seen, the extension/relation does in fact exist/wasn't modified It's possible that some of these errors are unrelated - but in general it's caused a lot of flakiness / we'd like a more reliable database. Things we're looking into: - Increasing the connection_limit from 1 to 5 in our DB_URL (postgres://postgres.<project_id>:***@aws-0-us-east-1.pooler.supabase.com:6543/postgres?pgbouncer=true&connection_limit=1&pool_timeout=30) Beyond this, we're unsure what we need to do to get our database healthy again.
2 replies
TtRPC
Created by santi on 12/1/2024 in #❓-help
Use TRPCClientError.cause in frontend
Hi all, My TRPC route can sometimes fail. Say the error is CartValidationError In the frontend, I want to be able to do:
try {
await trpcProxyClient.user.cart.addCoupon.mutate({ ...payload, cartOwner })
} except (error) {
if (error instanceof CartValidationError) {
// do thing
} else {
// do other thing
}
}
try {
await trpcProxyClient.user.cart.addCoupon.mutate({ ...payload, cartOwner })
} except (error) {
if (error instanceof CartValidationError) {
// do thing
} else {
// do other thing
}
}
The problem is that the error is of type TRPCClientError. In the backend, I can see that the error.cause is what has the real error (CartValidationError) Is there a way for me to make the backend return the error in it's original type so I can use instanceOf? If not, can I use error.cause in the frontend? (doesn't seem possible yet)
2 replies
TtRPC
Created by santi on 10/24/2024 in #❓-help
Sentry Profiling for TRPC
Has anyone been able to set up Sentry Profiling for TRPC? For example, being able to see how long each API route takes to resolve? We want to identify which TRPC routes are the slowest / least performant
2 replies
PPrisma
Created by santi on 10/2/2024 in #help-and-questions
Unexpected message from server
Hi all, we see this error pretty randomly
error in connector: error querying the database: unexpected message from server
I try to replicate with the same query, but the error persists. Is this the kind of error wherein it makes sense to implement some kind of retry logic?
3 replies
PPrisma
Created by santi on 7/18/2024 in #help-and-questions
unexpected message from server
Hi all, we see this error pretty randomly
error in connector: error querying the database: unexpected message from server
I try to replicate with the same query, but the error persists. Is this the kind of error wherein it makes sense to implement some kind of retry logic?
3 replies
PPrisma
Created by santi on 5/9/2024 in #help-and-questions
Which is more efficient: Promise.all([findUnique() * 3]) or prisma.$transaction([findUnique() * 3])?
With prisma, is it more efficient to do
await Promise.all([
prisma.product.findMany()
prisma.order.findMany()
prisma.catalog.findFirst()
])
await Promise.all([
prisma.product.findMany()
prisma.order.findMany()
prisma.catalog.findFirst()
])
OR
await prisma.$transaction([
prisma.product.findMany()
prisma.order.findMany()
prisma.catalog.findFirst()
])
await prisma.$transaction([
prisma.product.findMany()
prisma.order.findMany()
prisma.catalog.findFirst()
])
Maybe transaction is slower because of transactional integrity? Or is there another command / alternative to $transaction that allows me to make just one trip to the database, rather than many? Ideally this is about optimizing efficiency/time/being better than Promise.all, and not about transactional integrity
1 replies
TtRPC
Created by santi on 4/12/2024 in #❓-help
Is it possible to get the procedure name / id in middleware?
I want to create a caching middleware that in some routes, stores a cache key that contains the route id (example: catalog.product.findMany) and the input (example: { categories: shirts }). It's not clear to me if this is possible.
8 replies
TtRPC
Created by santi on 4/8/2024 in #❓-help
Create client that is used in every request, without re-creating client
Hi all, Consider the following
export const createContextInner = async ({
req,
res,
}: {
req?: Context['req']
res?: Context['res']
}): Promise<Context> => {
const app = await NestFactory.createApplicationContext(AppModule)
return {
app,
prisma,
req,
res,
supabaseServerClient: null,
user: null,
}
}
export const createContextInner = async ({
req,
res,
}: {
req?: Context['req']
res?: Context['res']
}): Promise<Context> => {
const app = await NestFactory.createApplicationContext(AppModule)
return {
app,
prisma,
req,
res,
supabaseServerClient: null,
user: null,
}
}
This is annoying in local development because it needs to create the nest app for every request. The same thing with the prisma client. We'd like to create this once and use in every request. Is this possible?
6 replies
DDeno
Created by santi on 2/26/2024 in #help
Deno Jupyter Notebook - monorepo support
Hi all! We have a typescript-based monorepo that uses Turbo/Pnpm/etc Our primary reason for coming across Deno is that it seems to be the best supported way to use Typescript in a Jupyter notebook. We'd like set up a notebooks/ subfolder in the apps/* folder of the project and do queries there I haven't been able to set this up (maybe due to inexperience with Deno). For example, both of the following commands fail:
// Importing from a package in node_modules
import { PrismaClient } from '@prisma/client';
// Importing from a monorepo package
import { soemthing } from '@myapp/api';
// Importing from a package in node_modules
import { PrismaClient } from '@prisma/client';
// Importing from a monorepo package
import { soemthing } from '@myapp/api';
I've tried both in the root of the project and in the notebooks/* sub-folder
5 replies
TtRPC
Created by santi on 4/27/2023 in #❓-help
Bug where 2 requests are fired at once. TRPC batches them. Can I cancel the 2nd via ProcedureOption?
Hey all. I have a bug where my app fires two identical requests at the same time. This happens do to some weird upstream auth listener logic. Ideally TRPC can help me mitigate this. I want to configure ProcedureOption such that it doesn't batch, but rather only lets the first request to go through. Is this possible?
const updatedCartItems = await trpcClient.user.cart.replaceCartOnAuthLoaded.mutate(
{
anonymousCartItems,
},
{
onlyOneAtATime: true,
},
)
const updatedCartItems = await trpcClient.user.cart.replaceCartOnAuthLoaded.mutate(
{
anonymousCartItems,
},
{
onlyOneAtATime: true,
},
)
4 replies
TtRPC
Created by santi on 4/4/2023 in #❓-help
How can I access ctx from inside of a procedure?
const appRouter = t.router({
helloTab: t.procedure.input(z.object({ url: z.string().url() })).mutation(async ({ input, ctx }) => {
//@ts-ignore
const tab = ctx.sender.tab
console.log(tab)
}),
});
const appRouter = t.router({
helloTab: t.procedure.input(z.object({ url: z.string().url() })).mutation(async ({ input, ctx }) => {
//@ts-ignore
const tab = ctx.sender.tab
console.log(tab)
}),
});
is something like this possible? Not working for me
2 replies
TtRPC
Created by santi on 4/4/2023 in #❓-help
Async User Call in `createContext` (context.ts) or in `isAuthed` (in trpc.ts)
4 replies
TtRPC
Created by santi on 3/27/2023 in #❓-help
Use TRPC function inside of a TRPC function
Hi all! We have a trpc query called getProduct. I want to use this getProduct query inside of another query (getCart query). Is this possible / simple as a single trpc request rather than multiple?
3 replies
TtRPC
Created by santi on 3/23/2023 in #❓-help
createProxySSGHelpers type error
8 replies