Ramazan
Ramazan
Explore posts from servers
TtRPC
Created by Ramazan on 11/20/2023 in #❓-help
`useSuspenseQuery` still runs a fetch on SSR even when setting `ssr: false` in the api config
Beside double-fetching, this causes issues during rendering if you have auth on your routes as the SSR server doesn't seem to pass through the cookies to the tRPC route. Using Next.js 14.0.3 with the pages directory. Repro here: https://github.com/relsunkaev/trpc-ssr-suspense-repro
3 replies
DTDrizzle Team
Created by Ramazan on 9/20/2023 in #help
Prepend raw fields with table/subquery name in rendered SQL
Currently, it doesn't seem like raw fields in a select statement hold any information on the table/subquery they're used in. This results in subsequent usage of these fields elsewhere rendering to SQL as "field_name" instead of "alias"."field_name". This actually causes issues when you have overlapping field names in sql in your joins. Example:
const sq = db
.select({
date: sql<string>`${balances.createdAt}::date`.as("date"),
amount: balances.amount,
})
.from(balances)
.as("sq");

const result = await db
.select({
date: transactions.date,
amount: transactions.amount,
balance: balances.amount,
})
.from(transactions)
.innerJoin(sq, eq(sq.date, transactions.date));
const sq = db
.select({
date: sql<string>`${balances.createdAt}::date`.as("date"),
amount: balances.amount,
})
.from(balances)
.as("sq");

const result = await db
.select({
date: transactions.date,
amount: transactions.amount,
balance: balances.amount,
})
.from(transactions)
.innerJoin(sq, eq(sq.date, transactions.date));
will result in an error
error: column reference "date" is ambiguous
error: column reference "date" is ambiguous
with the following workaround
const result = await db
.select({
date: transactions.date,
amount: transactions.amount,
balance: balances.amount,
})
.from(transactions)
.innerJoin(sq, eq(sql`"sq".${sq.date}`, sql`"transactions".${transactions.date}`));
const result = await db
.select({
date: transactions.date,
amount: transactions.amount,
balance: balances.amount,
})
.from(transactions)
.innerJoin(sq, eq(sql`"sq".${sq.date}`, sql`"transactions".${transactions.date}`));
This behavior persists through subsequent subqueries where
const sq = db
.select({
date: sql<string>`${balances.createdAt}::date`.as("date"),
amount: balances.amount,
})
.from(balances)
.as("sq");

const sq2 = db
.select({
date: transactions.date,
balanceDate: balances.date,
amount: transactions.amount,
balance: balances.amount,
})
.from(transactions)
.innerJoin(sq, eq(sql`"sq".${sq.date}`, sql`"transactions".${transactions.date}`))
.as("sq2");

const result = await db.select({
balanceDate: sq2.balanceDate,
anotherDate: someTable.date // also using sql`...`.as("date")
}).from(sq2).innerJoin(someTable, ...);
const sq = db
.select({
date: sql<string>`${balances.createdAt}::date`.as("date"),
amount: balances.amount,
})
.from(balances)
.as("sq");

const sq2 = db
.select({
date: transactions.date,
balanceDate: balances.date,
amount: transactions.amount,
balance: balances.amount,
})
.from(transactions)
.innerJoin(sq, eq(sql`"sq".${sq.date}`, sql`"transactions".${transactions.date}`))
.as("sq2");

const result = await db.select({
balanceDate: sq2.balanceDate,
anotherDate: someTable.date // also using sql`...`.as("date")
}).from(sq2).innerJoin(someTable, ...);
will result in a similar error due to the ambiguity between someTable.date and sq2.balanceDate.
6 replies
TtRPC
Created by Ramazan on 8/28/2023 in #❓-help
Server-side error tracing with Datadog
Hey, has anyone had any luck setting up tracing with tRPC? Specifically with dd-trace-js. We’re using Datadog and because tRPC handles all errors internally, the tracer doesn’t actually get access to the stack trace. Likewise, it stops creating spans before hitting the tRPC route and only resumes if any library underneath is instrumented.
5 replies
DTDrizzle Team
Created by Ramazan on 8/7/2023 in #help
Cast columns in relations
A great feature of drizzle's relational queries is that they don't actually require a foreign key, which provides a great amount of flexibility in querying your data. However, it doesn't seem like there is currently a way to cast the fields so that their types match. Something along the lines of
export const actionRelations = relations(actions, ({ many, one }) => ({
user: one(users, {
fields: [sql<string>`${actions.ownerId}::uuid`.as("ownerId")],
references: [users.id],
})
service: one(services, {
fields: [actions.ownerId],
references: [sql<string>`${services.id}::text`.as("id")]
}
}));
export const actionRelations = relations(actions, ({ many, one }) => ({
user: one(users, {
fields: [sql<string>`${actions.ownerId}::uuid`.as("ownerId")],
references: [users.id],
})
service: one(services, {
fields: [actions.ownerId],
references: [sql<string>`${services.id}::text`.as("id")]
}
}));
where an action's ownerId is text so that it can refer to multiple different owner types regardless of their primary key type.
2 replies
DTDrizzle Team
Created by Ramazan on 7/19/2023 in #help
Update existing schema when introspecting db
Is it possible to update an existing schema using introspection? Currently, drizzle-kit just wipes any changes I make to the schema (relations, renaming, etc.).
7 replies
DTDrizzle Team
Created by Ramazan on 5/31/2023 in #help
Prepared Stements
I was looking into using AWS RDS Proxy with Prisma and ran into this https://www.prisma.io/docs/guides/deployment/deployment-guides/caveats-when-deploying-to-aws-platforms#aws-rds-proxy I was wondering does DrizzleORM use prepared statements for everything like Prisma does? Would I run into the same issue if I switched to Drizzle?
2 replies
TTCTheo's Typesafe Cult
Created by Ramazan on 2/21/2023 in #questions
Aurora Serverless V2?
I’m currently looking into using this for a Postgres db and Prisma. Does anyone have experience with this? Would you recommend it? I’ve heard a lot of bad things about V1, but also heard V2 is way better.
1 replies
TTCTheo's Typesafe Cult
Created by Ramazan on 2/7/2023 in #questions
Saving filter state to query params
Does anyone have any experience using Geschichte with nextjs? I need to save the filter state to query params but it seems kind of overkill plus throws an erroneous type error. Should I just use Zustand and write my own simple persistence store? https://github.com/BowlingX/geschichte
1 replies
TTCTheo's Typesafe Cult
Created by Ramazan on 2/1/2023 in #questions
`getServerSideProps` fails silently and returns 404
I’m currently tinkering with something and noticed that when an exception is thrown in getServerSideProps, the page just returns a 404 with nothing logged in either console. Is there a way to make it not fail silently and log the error? (I’ve tried putting it in a try catch block)
5 replies