Vladi Stevanovic
Yaakov
10/25/2021, 8:33 PMmodel Post {
id Int @id @default(autoincrement())
title String
categories CategoriesOnPosts[]
}
model Category {
id Int @id @default(autoincrement())
name String
posts CategoriesOnPosts[]
}
model CategoriesOnPosts {
post Post @relation(fields: [postId], references: [id])
postId Int // relation scalar field (used in the `@relation` attribute above)
category Category @relation(fields: [categoryId], references: [id])
categoryId Int // relation scalar field (used in the `@relation` attribute above)
assignedAt DateTime @default(now())
assignedBy String
@@id([postId, categoryId])
}
Suppose I want to do the following:
await prisma.post.update({
where: {
title: 'Foo'
},
data: {
categories: {
category: {
name: 'Updated category name'
}
}
}
});
All I get is `"error": "Unknown arg categories
in where.categories for type PostWhereUniqueInput. Did you mean set
?\n"`
Is there any way for this to be accomplished?Ethan Joffe
10/25/2021, 9:05 PMmel
10/25/2021, 10:07 PMJames Schull
10/25/2021, 11:08 PMWill
10/26/2021, 3:36 AMWill
10/26/2021, 3:37 AMChris Packett
10/26/2021, 4:17 AMasync create(data: Prisma.AutoCreateConfigurationCreateInput) {
return await prismaClient.autoCreateConfiguration.create({
data,
});
}
The problem with the above code is that the method signature has a direct dependency on “prisma” which seems like an anti-pattern since the whole point of repositories are to abstract away the data access implementation details.
Anyone have any good patterns they use here?Prince
10/26/2021, 5:22 AMDaniell
10/26/2021, 7:46 AMTimed out fetching a new connection from the connection pool. (More info: <http://pris.ly/d/connection-pool>, Current connection limit: 3)
Octal pixel
10/26/2021, 8:17 AMOctal pixel
10/26/2021, 8:18 AMterion
10/26/2021, 10:23 AMLuis Kuper
10/26/2021, 1:19 PMdistinct
& cursor-pagination
.
TLDR: How can i specify that distinct is applied before the cursor pagination steps (cursorId, skip, take) and not afterwards.
Example:
Having the following Model:
model Comments {
id String @id @default(uuid())
author User? @relation(fields: [authorId], references: [id])
authorId String?
cursorId String @unique
text String
}
and having that model filled with the following data:
{
authorId: "user1",
cursorId: "0001",
text: "text1",
},
{
authorId: "user2",
cursorId: "0002",
text: "text2",
},
{
authorId: "user3",
cursorId: "0003",
text: "text3",
},
{
authorId: "user4",
cursorId: "0004",
text: "text4",
},
{
authorId: "user1", // sidenote: this is the 2nd comment linked to user1
cursorId: "0005",
text: "text5",
}
The objective is to fetch the comments in a cursor-paginated way and recieving items that are distinct on the field authorId.
Considering 3 items per page, leads to the following query for the 2nd page:
const res = await prismaClient.blogPost.findMany({
distinct: ["authorId"],
orderBy: { cursorId: "asc" },
cursor: { cursorId: "0003" },
skip: 1,
take: 3,
});
This leads to the following res where the 2nd item is fetched although unfortunately in the first cursor-pagination fetch a item with that authorId "user1" has been fetched already before.
{
authorId: "user4",
cursorId: "0004",
text: "text4",
}
{
authorId: "user1",
cursorId: "0005",
text: "text5",
}
What i would like to have on that 2nd fetch is just the object with cursorId "0004".
I assume this could be solved by the possibility of distinct being applied before the cursor pagination. Is there the possibility to do so?
Thanks in advice.Yilmaz Ugurlu
10/26/2021, 2:51 PMQuery createOneActivity is required to return data, but found no record(s).
I just created a model and trying to create a record and receiving this error..
This is my model
model Activity {
createdAt DateTime @default(now()) @map(name: "created_at") @db.Timestamptz(0)
actionUserId String @map(name: "action_user_id") @db.Uuid
affectedUserId String @map(name: "affected_user_id") @db.Uuid
event String @db.VarChar(64)
entity Json
@@id([createdAt, actionUserId, affectedUserId, event])
@@index(fields: [affectedUserId, createdAt], name: "actvt_fltr_idx")
@@index(fields: [affectedUserId, createdAt, event], name: "actvt_fltr_evt_idx")
@@map(name: "activity")
}
and this is the code that I’m using
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
const handler = async () => {
const data = await prisma.activity.create({
data: {
event: 'test',
actionUserId: '85a42af9-bb28-47b3-9ef2-699858c8bbea',
affectedUserId: '85a42af9-bb28-47b3-9ef2-699858c8bbea',
entity: { key: 'value' },
},
});
console.log(data);
};
handler();
James Schull
10/26/2021, 4:43 PMLuke Morris
10/26/2021, 5:08 PMdb.User.Database.Some()
A user has many alerts. I've queried them with db.User.Alert.Some()
An alert has one notification. I've tried querying it with db.Alert.Notification.Some()
, but Some
isn't available here. If it's a "has one" relationship, should I be using another function instead?
users, err := prisma.User.FindMany(
db.User.Alert.Some(
db.Alert.Notification.Some(),
),
db.User.Database.Some(),
).Exec(ctx)
Chris Tsongas
10/26/2021, 5:29 PMreferentialIntegrity = "prisma"
how does Prisma Client actually enforce referential integrity? I'm guessing it must make queries to validate operations before running them?Michael Hall
10/26/2021, 6:13 PMmodel User {
id String @id
avatar String
username String
discriminator String
games Game[]
}
model Game {
id Int @id @default(autoincrement())
players User[]
team1 String[]
team2 String[]
result Int?
createdAt DateTime @default(now()) @db.Timestamp(6)
}
Michael Hall
10/26/2021, 6:14 PMconst playerQueue = queue.map((user) => ({
id: user.id,
username: user.username,
discriminator: user.discriminator,
avatar: user.avatarURL()!
}));
const test = await this.container.prisma.game.create({
data: {
players: {
create: playerQueue
},
team1: playerQueue.splice(0, 2).map((usr) => usr.id),
team2: playerQueue.splice(2, 5).map((usr) => usr.id)
}
});
Jaye
10/26/2021, 6:17 PMresponses.map(r => {
if (emailSchema.isValidSync(creatorEmail))
await db.user.upsert({
where: {
email: r.creatorEmail,
},
update: {},
create: {
email: r.creatorEmail,
},
})
if (emailSchema.isValidSync(approverEmail))
await db.user.upsert({
where: {
email: r.approverEmail,
},
update: {},
create: {
email: r.approverEmail,
},
})
})
the user model has a unique constraint on the email column:
model User {
id String @id @default(cuid())
email String? @unique
// etc...
}
i intermittently get `Unique constraint failed on the fields: (email
)` errors 😞
is this a race condition? if so, how can i fix it?Elie Steinbock
10/26/2021, 6:29 PMOption::unwrap()
on a None
value in query-engine/core/src/query_document/parser.rs25087`
I see there’s one mention of it on GH issues and nothing beyond that. hard to reproduceElie Steinbock
10/26/2021, 6:30 PMAmit
10/26/2021, 7:46 PM@me/db1
and @me/db2
from every other package (@me/*
).
This is Typescript so generating to src
or the root of the package is not ideal, generating straight into dist
will cause compilation to potentially fail, or make tsserver
unhappy.
Creating the packages in another repo, outside of the monorepo is kinda losing the entire point of monorepo.
Did anyone solve something similar to that?Florian Bress
10/26/2021, 7:56 PMEzequiel Pereira
10/26/2021, 10:18 PMTyler Matteo
10/27/2021, 12:45 AM@Unsupported
and queryRaw()
. My question is has there been any open discussion as to what the Prisma Client API could look like for spatial features? I think it could be extremely powerful to have equivalents of PostGIS functions like ST_Contains
and ST_Intersects
in the Prisma client for doing spatial joins.David Petrov
10/27/2021, 2:21 AMDavid Petrov
10/27/2021, 2:24 AMawait this.prisma.userClassrooms.delete({
where: {
user_id: user.id,
classroom_id: classroomId,
},
});
Dia TM
10/27/2021, 8:12 AM"prisma": {
"seed": "ts-node libs/prisma/src/lib/seed.ts",
"schema": "./libs/prisma/src/lib/schema.prisma"
`}`the syds don't work(
"seed": "node --loader ts-node/esm libs/prisma/src/lib/seed.ts",
works like this)🚲