bob
01/17/2022, 1:04 AMbob
01/17/2022, 1:12 AMbob
01/17/2022, 1:13 AMbob
01/17/2022, 1:18 AMgenerator client {
provider = "prisma-client-js"
previewFeatures = ["dataProxy", "referentialIntegrity"]
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
referentialIntegrity = "prisma"
}
kailoon
01/17/2022, 4:45 AMgenerator client {
provider = "prisma-client-js"
previewFeatures = ["referentialIntegrity"]
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
referentialIntegrity = "prisma"
}
// user has many restaurants
model User {
id String @id @unique @default(cuid())
name String
restaurants Restaurant[]
orders Order[]
}
// restaurant has many sections, items
model Restaurant {
id String @id @unique @default(cuid())
name String
userId String
User User @relation(fields: [userId], references: [id])
sections Section[]
items Item[]
itemOptions ItemOption[]
itemOptionValues ItemOptionValue[]
itemVariants ItemVariant[]
itemVariantValues ItemVariantValue[]
orders Order[]
address Address?
}
model Section {
id String @id @unique @default(cuid())
name String
restaurantId String?
Restaurant Restaurant? @relation(fields: [restaurantId], references: [id])
items Item[]
}
model Item {
id String @id @unique @default(cuid())
name String
price Decimal
restaurantId String?
sectionId String?
Restaurant Restaurant? @relation(fields: [restaurantId], references: [id])
Section Section? @relation(fields: [sectionId], references: [id])
itemOptions ItemOption[]
itemVariants ItemVariant[]
}
// multiple choices eg: extra cheese, extra sauce etc.
model ItemOption {
id String @id @unique @default(cuid())
name String
restaurantId String?
itemId String?
Restaurant Restaurant? @relation(fields: [restaurantId], references: [id])
Item Item? @relation(fields: [itemId], references: [id])
}
model ItemOptionValue {
id String @id @unique @default(cuid())
name String
price Decimal
restaurantId String?
Restaurant Restaurant? @relation(fields: [restaurantId], references: [id])
}
// sizes, flavor and toppings etc
model ItemVariant {
id String @id @unique @default(cuid())
name String
restaurantId String?
itemId String?
Restaurant Restaurant? @relation(fields: [restaurantId], references: [id])
Item Item? @relation(fields: [itemId], references: [id])
}
model ItemVariantValue {
id String @id @unique @default(cuid())
name String
price Decimal
restaurantId String?
Restaurant Restaurant? @relation(fields: [restaurantId], references: [id])
}
model Order {
id String @id @unique @default(cuid())
name String
total Decimal
userId String?
restaurantId String?
orderItems OrderItem[]
User User? @relation(fields: [userId], references: [id])
Restaurant Restaurant? @relation(fields: [restaurantId], references: [id])
}
model OrderItem {
id String @id @unique @default(cuid())
name String
quantity Int
price Decimal
orderId String?
Order Order? @relation(fields: [orderId], references: [id])
}
model Address {
id String @id @unique @default(cuid())
name String
latitudes Decimal @db.Decimal(8, 6)
longitudes Decimal @db.Decimal(9, 6)
restaurantId String @unique
Restaurant Restaurant @relation(fields: [restaurantId], references: [id])
}
Am I doing it correctly? I wanted to be able to list the orders, number of an item being ordered for the owner as a stats/report. Also, an order summary for the customer to refer to as a receipt. Thanks for your help!koenie-06
01/17/2022, 8:26 AMReuben Porter
01/17/2022, 9:28 AMcreateMany
as the skipDuplicates
flag is a useful feature for me, plus createMany
is more performant than a loop with multiple single create
.
My issue is that createMany
does not return the created values, and I need those values to perform another action - e.g. a notification email. I have found this thread, but nothing in there really helps my case https://github.com/prisma/prisma/issues/8131. I thought about using a loop and storing the promises in an array, then waiting for them all to be settled etc, however I haven't been able to get this to work and Prisma/TS isn't happy.
Any suggestions greatly appreciated!Deepak Guptha S
01/17/2022, 10:48 AMSELECT * FROM employee_profile WHERE month(date_of_birth) = 12 AND year(date_of_birth) = 1990
I searched for the Prisma docs, but I couldn't find the equivalent Prisma functions to use the SQL functions like
month()
, year()
Is there any solution ?Claudiu Constantin Cojocaru
01/17/2022, 12:05 PMbob
01/17/2022, 12:32 PMkoenie-06
01/17/2022, 1:07 PMMischa
01/17/2022, 1:30 PMcreated < NOW() - INTERVAL '1 day'
?Eudes TenĂłrio
01/17/2022, 4:04 PMkoenie-06
01/17/2022, 7:18 PMkoenie-06
01/17/2022, 7:19 PMNathaniel Babalola
01/17/2022, 7:21 PMDateTime @db.Time()
Should I pass in a JavaScript date object or just a time string. Will the db.Time() format it for me if I were to pass in a date object?Bailey McKay
01/18/2022, 3:10 AMJakub Figlak
01/18/2022, 7:54 AMclubs
, competitions (leagues)
and seasons
tables in my database. I'm also using a table called competition_participations
to keep track of in which league was the club participating during particular season. I'm kinda struggling with modeling competitions (leagues) data. My problem is that there are leagues that are divided into groups and the club is participating in that particular group, but there are also top-level leagues that are not divided into any groups. Let's talk about Bundesliga here, as Prisma's headquarters is in Berlin đ Here is an example:
1. Bayern participates in Bundesliga
, no groups
2. Heidenheim participates in 2. Bundesliga
, no groups
3. FC Kaiserslautern participates in 3. Liga
, no groups
4. VfB Oldenburg participates in Regionalliga North
- top level competition is Regionalliga
, group is North
5. Alemannia Aachen participates in Regionalliga West
- top level competition is Regionalliga
, group is West
How would you model that? I was thinking of something like
model Division {
id String @id @default(cuid())
name String
level. Int // 1, 2, 3, etc..
isJunior Boolean @default(false)
isWomen Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
// Relation fields
country Country @relation(fields: [countryId], references: [id])
countryId String
league League[]
}
model League {
id String @id @default(cuid())
name String
// Relation fields
division Division @relation(fields: [divisionId], references: [id])
divisionId String
}
But it seems a little bit dirty to have to create Bundesliga
as a division and as a league. Do you have any recommendations?Reuben Porter
01/18/2022, 8:35 AMpublication
 and publicationStatus
.
A publication will looking something like:
{
"id": "ckyil950d00027v2str5ljo7h",
"url_slug": "ckyil950e00037v2s4mqxvaho",
"type": "PEER_REVIEW",
"title": "Intersting review",
"content": "Content is optional at this stage",
"doi": "1093/ajae/aaq063",
"createdBy": "test-user-1",
"createdAt": "2022-01-17T11:12:50.845Z",
"updatedAt": "2022-01-17T11:12:50.847Z",
"publicationStatus": [
{
"status": "LIVE",
"createdAt": "2022-01-19T11:12:50.846Z",
"id": "ckyil950e00047v2sx4urbfte"
},
{
"status": "DRAFT",
"createdAt": "2022-01-17T11:12:50.846Z",
"id": "ckyil950e00047v2sx4urbfth"
}
],
"user": {
"id": "test-user-1",
"firstName": "Test",
"lastName": "User 1"
}
}
Where publication
 has a 1 to many relationship with publicationStatus
.
What I need to do is a find
 query where it only returns a publication
 if the latest publicationStatus
 for that publication
, has a status
 of LIVE
.
The closest I could come to is this psuedo code (does not work, but demonstrates a picture of what I am trying to do):
await prisma.publication.findFirst({
where: {
id,
publicationStatus: {
where: {
status: 'LIVE'
},
take: 1,
orderBy: {
createdAt: 'desc'
}
},
}
});
Jonas
01/18/2022, 9:49 AMJonas
01/18/2022, 10:39 AMNathaniel Babalola
01/18/2022, 11:23 AMPrismaClientKnownRequestError:
Invalid prisma.restaurant.create() invocation:
Failed to validate the query: Unable to match input value to any allowed input type for the field. Parse errors: [Query parsing/validation error at
Yet my data is being created in the database and it still returns this error. Any help is greatly appreciated.Jonas
01/18/2022, 1:35 PMHenri Kuper
01/18/2022, 1:58 PMuser
with the attribute follower
. A user has 10k followers. Prisma studio would then request the data of all 10k followers as soon as this specific user is requested.
Even if you unselect certain attributes in Prisma studio, they are still requested.
1. does anyone else has this kind of trouble and already found a solution/workaround?
2. why does prisma studio use include to show the number of relations instead of _count? This would probably speed up the whole process by a lot, I guess.Kasir Barati
01/18/2022, 2:04 PM$ npx prisma migrate dev
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "nest_base", schema "public" at "localhost:5432"
Already in sync, no schema change or pending migration was found.
Error: ENOENT: no such file or directory, copyfile '/path/to/node_modules/@prisma/index.d.ts' -> '/path/to/node_modules/@prisma/client/index.d.ts'
Rafael Carneiro
01/18/2022, 2:12 PMRafael Carneiro
01/18/2022, 2:13 PMkoenie-06
01/18/2022, 4:31 PMawait prisma.tickets.delete({
where: {
channelId: interaction.channelId,
guildId: interaction.guildId
}
});
And my error is
Type '{ channelId: any; guildId: any; }' is not assignable to type 'ticketsWhereUniqueInput'.
Object literal may only specify known properties, and 'channelId' does not exist in type 'ticketsWhereUniqueInput'.
Harry Cheslaw
01/18/2022, 5:05 PMBenny Kachanovsky
01/18/2022, 6:02 PM