word
word
Explore posts from servers
TTCTheo's Typesafe Cult
Created by word on 7/11/2023 in #questions
Check if unique key exists before create
I'm using react-hook-form with zod validation, and I want to check if a unique key exists on the onBlur field event. I can't put it inside Zod validation nor can I rely on the server to respond with this error after submission, because planet-scale never knows what column caused the error. My workaround was to create a trpc route to check if the key exists, call a it's refetch every onBlur event and conditionally use setError to invalidate the field. But this approach is cumbersome and doesn't seem like a good solution. What could I do instead?
4 replies
TTCTheo's Typesafe Cult
Created by word on 1/19/2023 in #questions
What to use to generate pdfs?
I've been searching for a couple of days and yet I'm not sure about which lib to use. jsPDF seems like a good option, it does what I need and has types. Any suggestions?
1 replies
TTCTheo's Typesafe Cult
Created by word on 12/4/2022 in #questions
Strange Prisma error when trying to seed -- meta { column_name 'for' }
I'm trying to seed the following table.
model Contract {
id String @id @default(cuid())
dueDay Int? @map("due_date") @db.TinyInt()
initialDate DateTime @map("initial_date")
endingDate DateTime? @map("ending_date")
rent Decimal @db.Decimal(7, 2)
bail Decimal @db.Decimal(7, 2)
duration Int @default(12) @db.TinyInt()
interest Decimal @default(1.00) @db.Decimal(4, 2)
arrears Decimal @default(10.00) @db.Decimal(4, 2)
witnesses Witness[]
tenant Tenant @relation(fields: [tenantId], references: [id])
tenantId String @map("tenant_id")
house House @relation(fields: [houseId], references: [id])
houseId String @map("house_id")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

@@unique([houseId, tenantId, initialDate])
@@index([houseId])
@@index([tenantId])
}
model Contract {
id String @id @default(cuid())
dueDay Int? @map("due_date") @db.TinyInt()
initialDate DateTime @map("initial_date")
endingDate DateTime? @map("ending_date")
rent Decimal @db.Decimal(7, 2)
bail Decimal @db.Decimal(7, 2)
duration Int @default(12) @db.TinyInt()
interest Decimal @default(1.00) @db.Decimal(4, 2)
arrears Decimal @default(10.00) @db.Decimal(4, 2)
witnesses Witness[]
tenant Tenant @relation(fields: [tenantId], references: [id])
tenantId String @map("tenant_id")
house House @relation(fields: [houseId], references: [id])
houseId String @map("house_id")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

@@unique([houseId, tenantId, initialDate])
@@index([houseId])
@@index([tenantId])
}
I'm using planet scale as db host and prisma is in relationMode prisma. I have no errors whatsoever when I seed the tables it's related with. I also have no errors when manually creating rows in it in prisma studio. If I try to create row with prisma.model.create, I get no erros, but also no row. But if assign the create return value to a variable, then it gives me this error:
PrismaClientKnownRequestError:
Invalid `prisma.contract.create()` invocation in
/home/fabricio/code/side-projects/t3-manager/prisma/seed.ts:108:38
105 // await prisma.pixKey.createMany({ data: generateFakePixKeysData(tenants), skipDuplicates: true });
...
→ 108 const test = await prisma.contract.create(
The provided value for the column is too long for the column's type. Column: for
...
manager/node_modules/@prisma/client/runtime/index.js:35926:16) {
code: 'P2000',
clientVersion: '4.7.1',
meta: { column_name: 'for' },
batchRequestIdx: undefined
}
PrismaClientKnownRequestError:
Invalid `prisma.contract.create()` invocation in
/home/fabricio/code/side-projects/t3-manager/prisma/seed.ts:108:38
105 // await prisma.pixKey.createMany({ data: generateFakePixKeysData(tenants), skipDuplicates: true });
...
→ 108 const test = await prisma.contract.create(
The provided value for the column is too long for the column's type. Column: for
...
manager/node_modules/@prisma/client/runtime/index.js:35926:16) {
code: 'P2000',
clientVersion: '4.7.1',
meta: { column_name: 'for' },
batchRequestIdx: undefined
}
There is no such column ( for ) in any table. What could it be?
6 replies