Mike Willbanks
02/01/2022, 3:56 PMSébastien ELET
02/01/2022, 4:03 PMuser
02/01/2022, 4:23 PMLeonard
02/01/2022, 4:55 PMSumit
02/01/2022, 6:02 PMSumit
02/01/2022, 6:03 PMn
02/01/2022, 7:08 PMLevi Mason
02/01/2022, 11:45 PMfemzy
02/02/2022, 1:56 AMPaul ANDRIANTEFY
02/02/2022, 8:54 AMMarvin
02/02/2022, 1:41 PMAdam Boulila
02/02/2022, 2:07 PMcode: 'P5006' Unknown Server Error
, I can make requests directly to the DB using Prisma and it works, just the data Proxy that does not
I have even created a new project and i still get the same problem with data proxyTopi Pihko
02/02/2022, 2:32 PMthis.prisma.resource.findMany({
include: {
department: true,
cell: true,
},
})
).filter(
(resource) =>
resource.department.factoryId == factoryId || resource.cell.factoryId == factoryId,
);
Glaucia Lemos
02/02/2022, 2:56 PMpzaenger
02/02/2022, 4:43 PMMike Willbanks
02/02/2022, 6:19 PMmatic
02/02/2022, 7:22 PMPrismaClient
instance that we export as client
variable from a shared file.
Any tips?Jon
02/02/2022, 7:23 PMUsers
per Post
OR get all of the upvotes and downvotes per User
how would I construct the schema? I've tried a bunch of permutations but can't figure out how to do the relations:
model Post {
id Int @id @default(autoincrement())
upvotes User[]
downvotes User[]
}
model User {
id Int @id @default(autoincrement())
upvotes Post[]
downvotes Post[]
}
femzy
02/02/2022, 7:44 PMmodel User {
id Int @id @default(autoincrement())
name String
email String @unique
password String
createdAt DateTime @default(now())
products Cart[]
@@map("users")
}
model Product {
id Int @id @default(autoincrement())
name String @unique
description String
price Int
stock Int
sku String
createdAt DateTime @default(now())
Category Category? @relation(fields: [categoryId], references: [id])
categoryId Int
users Cart[]
@@map("products")
}
model Category {
id Int @id @default(autoincrement())
name String @unique
products Product[]
createdAt DateTime @default(now())
@@map("categories")
}
model Cart {
id Int @id @default(autoincrement())
user User @relation(fields: [userId], references: [id])
userId Int
product Product @relation(fields: [productId], references: [id])
productId Int
quantity Int
}
I made the Cart table a join table due to the User and Product having a Many-to-Many relationship
My Routes
router.get("/", async (req, res) => {
try {
const cart = await prisma.cart.findMany({
include: { product: true },
});
res.status(200).json(cart);
} catch (error) {
res.status(500).json(error);
}
});
// Fetch a user's cart
router.get("/:userId", async (req, res) => {
try {
const cart = await prisma.cart.findOne({
where: { userId: req.params.userId },
include: { product: true },
});
res.status(200).json(cart);
} catch (error) {
res.status(500).json(error);
}
});
<http://router.post|router.post>("/", async (req, res) => {
try {
const cart = await prisma.cart.create({
data: req.body,
});
res.status(200).json(cart);
} catch (error) {
res.status(500).json(error);
}
});
module.exports = router;
My route to fetch a user's cart is not working, please what could be the problem and any advice to make the app better would be appreciatedChris
02/02/2022, 8:02 PMmodel Series {
id Int @id @default(autoincrement())
name String
deck String?
description String?
year String
publisher String
count Int
externalId String @unique
issues Issue[]
}
model Issue {
id Int @id @default(autoincrement())
series Series @relation(fields: [seriesId], references: [id])
seriesId Int
name String
externalId String @unique
}
Code running within a BullMQ worker:
const operations = issues.map(issue => {
const { id: issueExternalId, name } = issue
return prisma.series.update({
where: {
id: seriesId
},
data: {
issues: {
create: {
name,
externalId: issueExternalId
}
}
}
})
})
const [_, total] = await prisma.$transaction(operations)
For some reason the transaction just appears to hang. I've enabled logging/debug and it's like it doesn't even attempt to run the query. Been banging my head against it for a few hours. Any ideas?Luan Rodrigues
02/02/2022, 8:46 PMTyler Bell
02/02/2022, 11:43 PMCory McAboy
02/03/2022, 4:38 AMCory McAboy
02/03/2022, 4:39 AMMischa
02/03/2022, 11:02 AMRaw query failed. Code: `42P18`. Message: `db error: ERROR: could not determine data type of parameter $1`
user
02/03/2022, 12:30 PMIbad Shaikh
02/03/2022, 2:22 PMprisma.special_password.findFirst()
invocation:\n\n\n Failed to validate the query: Field does not exist on enclosing type.
at `Query.findFirstspecial_password`"`
• Even the prisma studio is showing the record of this table.
I have also updated prisma from "3.2.1" to "3.9.1" but it still fails. I also cleaned my npm cache but still the same error.
Also used prisma db push and prisma db pull commands but its says The database is already synced.
Prisma Query:
await prisma.special_password.findFirst({
where: {
password: req.body.password,
},
})
• And If I try to call .delete( ) method it throws:
`nUnknown arg password
in where.password for type special_passwordWhereUniqueInput. Available args:\n\ntype special_passwordWhereUniqueInput {\n id?: Int\n}\n\n\n at Object.validate`
It means the query is not considering password as the field of this model. But inside vscode, the password field is provided as a hint which means that this field is supported but when the query is ran, it throws error.Jonathan Marbutt
02/03/2022, 3:18 PMEntityCommon
where I would keep some common fields like UpdatedDate
Name
and a few others. This allowed me to do global searching and other things in the app. So my question is how to best accomplish this in prisma, I know I will just have to manually create the model
in the schema and link every table to it as a 1:1 relationship.
Where I start to run in my question, is generating the data in the EntityCommon
table, other ORMs handle this pretty well, but I would prefer to do it at the database level anyways. Would I be better off creating a trigger for each table to maintain the EntityCommon
and should I keep those triggers in something for the migrations? Or should I rely on the $on
events in prisma?Murty Munukutla Satyanarayana
02/03/2022, 3:55 PMNick B
02/03/2022, 6:47 PM