andrew
andrew
Explore posts from servers
TtRPC
Created by andrew on 12/5/2024 in #❓-help
Skew protection Vercel TRPC
Was wondering if I can enable vercel skew protection for trpc. According to docs, adding the dpl query should enable it.
const query =
process.env.VERCEL_SKEW_PROTECTION_ENABLED === '1'
? `?dpl=${process.env.VERCEL_DEPLOYMENT_ID}`
: '';

const res = await fetch(`/get${query}`);
const query =
process.env.VERCEL_SKEW_PROTECTION_ENABLED === '1'
? `?dpl=${process.env.VERCEL_DEPLOYMENT_ID}`
: '';

const res = await fetch(`/get${query}`);
on trpc I am using the unstable_httpBatchStreamLink
const [trpcClient] = useState(() =>
api.createClient({
links: [
loggerLink({
enabled: (op) =>
env.NODE_ENV === 'development' ||
(op.direction === 'down' && op.result instanceof Error),
}),
unstable_httpBatchStreamLink({
transformer: SuperJSON,
url: `${getBaseUrl()}/new-api/trpc`,
headers() {
const headers = new Headers();
headers.set('x-trpc-source', 'nextjs-react');
return headers;
},
}),
],
}),
);
const [trpcClient] = useState(() =>
api.createClient({
links: [
loggerLink({
enabled: (op) =>
env.NODE_ENV === 'development' ||
(op.direction === 'down' && op.result instanceof Error),
}),
unstable_httpBatchStreamLink({
transformer: SuperJSON,
url: `${getBaseUrl()}/new-api/trpc`,
headers() {
const headers = new Headers();
headers.set('x-trpc-source', 'nextjs-react');
return headers;
},
}),
],
}),
);
2 replies
DTDrizzle Team
Created by andrew on 11/17/2023 in #help
How to filter null values from json_arrayagg
Hey sry if this is a stupid question, I am still kinda new to more complex sql queries. The problem here is that pictures returns an array of objects that have all properties null. As far as I know this is a correct behaviour for the left join. I just wanted to know how I could filter the null values in a good way.
ctx.db
.select({
...getTableColumns(organizers),
ratings: {
rating: sql<number>`AVG(value)`,
reviews: sql<number>`COUNT(value)`,
},
pictures: sql<
(typeof files.$inferSelect)[]
>`JSON_ARRAYAGG(JSON_OBJECT("id", ${files}.id, "name", ${files}.name, "url", ${files.url}))`.as(
"pictures",
),
})
.from(organizers)
.leftJoin(files, eq(organizers.id, files.entityId))
.leftJoin(ratings, eq(organizers.id, ratings.organizerId))
.groupBy(organizers.id);
ctx.db
.select({
...getTableColumns(organizers),
ratings: {
rating: sql<number>`AVG(value)`,
reviews: sql<number>`COUNT(value)`,
},
pictures: sql<
(typeof files.$inferSelect)[]
>`JSON_ARRAYAGG(JSON_OBJECT("id", ${files}.id, "name", ${files}.name, "url", ${files.url}))`.as(
"pictures",
),
})
.from(organizers)
.leftJoin(files, eq(organizers.id, files.entityId))
.leftJoin(ratings, eq(organizers.id, ratings.organizerId))
.groupBy(organizers.id);
6 replies