Piotrek
Piotrek
Explore posts from servers
DTDrizzle Team
Created by Piotrek on 8/10/2023 in #help
Nested joins / where on relation
Hey guys! I have a question regarding filtering a query. Basically, I need to filter the query by order relation - order.date is the field I want to filter by. However, I've noticed that filtering by relations is not yet supported. How do I write the query with joins? I can't figure out how to created nested joins (subOrders -> order and subOrders -> product -> kitchens -> kitchen etc.) This is my query:
const suborders = await db.query.subOrders.findMany({
where: and(isNull(subOrders.kitchenId)),
columns: {
id: true,
quantity: true,
},
with: {
order: true,
product: {
columns: {
id: true,
performancePoints: true,
prepTime: true,
},
with: {
kitchens: {
with: {
kitchen: {
columns: {
id: true,
performancePoints: true,
},
},
},
},
kitchenDependentProperties: {
columns: {
kitchenId: true,
productionPrice: true,
purchasePrice: true,
},
},
},
},
},
});
const suborders = await db.query.subOrders.findMany({
where: and(isNull(subOrders.kitchenId)),
columns: {
id: true,
quantity: true,
},
with: {
order: true,
product: {
columns: {
id: true,
performancePoints: true,
prepTime: true,
},
with: {
kitchens: {
with: {
kitchen: {
columns: {
id: true,
performancePoints: true,
},
},
},
},
kitchenDependentProperties: {
columns: {
kitchenId: true,
productionPrice: true,
purchasePrice: true,
},
},
},
},
},
});
79 replies
TTCTheo's Typesafe Cult
Created by Piotrek on 6/28/2023 in #questions
Prisma extensions and i18n
Hello! I have an issue with creating an extension that would append a computed field based on relations. I read in the docs that adding anything besides scalars to the needs field is impossible, so I wanted to take another approach and append relations using 1 extension. Next, I would use them in a second extension. However, they still don't show up in the needs field. How do i utilise the relations to create an extension appending a computed field? What I want to is basically: take the metadata with model's name based on the locale (from the metadatas relation) and append that name as a computed field. Here's my code snippet that doesn't work:
export const prisma = (locale: Locale) =>
new PrismaClient({
log:
process.env.NODE_ENV === "development"
? ["query", "error", "warn"]
: ["error"],
})
.$extends({
name: "i18n-queries",
query: {
allergen: {
findMany: async ({ query, args }) => {
return await query({
...args,
include: {
metadatas: {
select: { name: true, description: true, locale: true },
},
},
});
},
// the same for other methods
},
},
})
.$extends({
name: "i18n-fields",
result: {
allergen: {
name: {
needs: { metadatas: true }, // this doesn't work
compute: (allergen) => {
return ""; // compute the value
},
},
},
},
});
export const prisma = (locale: Locale) =>
new PrismaClient({
log:
process.env.NODE_ENV === "development"
? ["query", "error", "warn"]
: ["error"],
})
.$extends({
name: "i18n-queries",
query: {
allergen: {
findMany: async ({ query, args }) => {
return await query({
...args,
include: {
metadatas: {
select: { name: true, description: true, locale: true },
},
},
});
},
// the same for other methods
},
},
})
.$extends({
name: "i18n-fields",
result: {
allergen: {
name: {
needs: { metadatas: true }, // this doesn't work
compute: (allergen) => {
return ""; // compute the value
},
},
},
},
});
1 replies
TTCTheo's Typesafe Cult
Created by Piotrek on 6/22/2023 in #questions
`bcrypt` fails on installation with `node_modules`
Installation with existing node_modules directory fails with Cannot find module '../lib/main' Hello 🙂 I'm encountering an issue with the bcrypt package. I have a turborepo/monorepo with an api package and other apps. The package depends on bcrypt. Every time I want to add a new dependency to any app/package I have to remove the root node_modules folder and only then can I install it - reinstallation / adding a new package causes the error below:
> pnpm install <anything>

...

node_modules/bcrypt: Running install script, failed in 43ms
node_modules/bcrypt install$ node-pre-gyp install --fallback-to-build
node:internal/modules/cjs/loader:1078
throw err;
^
Error: Cannot find module '../lib/main'
Require stack:
- /Users/peter/Developer/dinnery/node_modules/bcrypt/node_modules/.bin/node-pre-gyp
| ...
Node.js v18.16.0
└─ Failed in 44ms at /Users/peter/Developer/dinnery/node_modules/bcrypt
> pnpm install <anything>

...

node_modules/bcrypt: Running install script, failed in 43ms
node_modules/bcrypt install$ node-pre-gyp install --fallback-to-build
node:internal/modules/cjs/loader:1078
throw err;
^
Error: Cannot find module '../lib/main'
Require stack:
- /Users/peter/Developer/dinnery/node_modules/bcrypt/node_modules/.bin/node-pre-gyp
| ...
Node.js v18.16.0
└─ Failed in 44ms at /Users/peter/Developer/dinnery/node_modules/bcrypt
Indeed, the lib/main file does not exist.
1 replies
TTCTheo's Typesafe Cult
Created by Piotrek on 4/10/2023 in #questions
Prettier issue with multiline code blocks
Hey! I'm trying to use Nextra and prettier in VS Ccde. However, I cannot create code blocks. The issue is, whenever I create one, prettier automatically puts everything in one line making the code block broken (see in the video). Am I missing something in my config file? I have it set to default for now. Thanks 🙂
1 replies
TTCTheo's Typesafe Cult
Created by Piotrek on 3/10/2023 in #questions
CLI and web UI communication
Hello guys! I'd like to build a tool (Rust / TS) that will serve NextJS / Vite + React website and then receive events and data from that website: you click something on the served website and the CLI receives the event. Is that possible with some package? Where can I find information about some kind of approach that would allow me to do it? Thanks!
3 replies
TTCTheo's Typesafe Cult
Created by Piotrek on 10/21/2022 in #questions
Using Rust with Turborepo project
Hey guys! I'm building a relatively big monorepo app. It contains NextJS app, Expo app and other parts of create-t3-turbo. However, I need to build a microservice (I'd love to have it in Rust). It's just going to be a algorithm for my backend. Is there a relatively convinent way of adding a cargo project to Turborepo? If not, is adding cargo build && cargo run to package.json dev script going to work? Or should I just create a separate project outside of the monorepo (Turborepo). Thanks!
7 replies
TTCTheo's Typesafe Cult
Created by Piotrek on 10/9/2022 in #questions
CSS Question - black or white text color based on background
6 replies
TTCTheo's Typesafe Cult
Created by Piotrek on 10/2/2022 in #questions
Case sensitive search in MySQL with Prisma
Hey guys, how can you implement case-sensitive search in MySQL adapter for Prisma? I see that they disabked mode property where you could set sensitivity in something like Postgres. Is there any way you can do case-sensitive search? Thanks!
1 replies
TTCTheo's Typesafe Cult
Created by Piotrek on 9/26/2022 in #questions
File storage in T3
Yes, I know about S3 & presigned POST URLs! Hi, I have a question about file upload in T3 stack. What could you recommend for free (afaik S3 does not offer free tier over 12 months) to handle file upload? The thing is, I will definitely not use more than 100MB. I need the file upload because I'll need to assign images to specific entities in my app from my admin panel and I'll probably be doing this once a day (that's why I'm not using static assets). I'll need maybe up to 50 images at once. Besides the pricing, S3 will be too much for that simple use case (just admin panel -> update few images a day). What is the best (and free) serverless solution?
20 replies
TTCTheo's Typesafe Cult
Created by Piotrek on 9/23/2022 in #questions
Prisma enums in React Native app (create-t3-turbo)
Hi guys, I'm using create-t3-turbo monorepo with NextJS and React Native apps & Prisma. I do have a problem with the generated types tho, as Prisma needs node to run afaik. I have a file in @acme/db package called types.ts that exports my enums:
export {
Voivodeship,
Weekday,
Locale,
Role,
// ...
} from "@prisma/client";
export {
Voivodeship,
Weekday,
Locale,
Role,
// ...
} from "@prisma/client";
In NextJS app it works fine, but in React Native I'm getting this error: Error: Unable to resolve module .prisma/client/index-browser from <MY-USER-PATH>/app/node_modules/@prisma/client/index-browser.js Is there any way that I can use Prisma generated enums in my React Native app, or should I rewrite them? Thanks!
5 replies