我试图为房间管理系统创建一个数据库,但我对关系感到困惑,无法在互联网上找到有用的资源。您能告诉我这个prisma脚本是否有任何问题吗?因为我想在expressJs中控制它,并基于它创建一个应用程序
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
model Guest {
guestId String @id @default(uuid())
name String
phone String @unique()
address String?
nationality String
Reservation Reservation[] @relation("GuestReservation")
}
model Reservation {
reservationId Int @id @default(autoincrement())
checkIn DateTime
checkOut DateTime
Guest Guest @relation("GuestReservation", fields: [guestId], references: [guestId], onDelete: Cascade)
guestId String
visitors Int
Room Room @relation("RoomReservation", fields: [roomId], references: [roomId], onDelete: Cascade)
type ReservationType
roomId Int
Bill Bill? @relation("BillReservation")
}
enum ReservationType {
Booking
Contract
Booked
Canceled
}
model Room {
roomId Int @id @default(autoincrement())
price Float
type Type
Reservation Reservation[] @relation("RoomReservation")
}
enum Type {
Single
Double
Triple
}
model Bill {
invoiceNo String @id @default(uuid())
Reservation Reservation @relation("BillReservation", fields: [reservationId], references: [reservationId], onDelete: Cascade)
reservationId Int @unique()
roomService Float @default(0)
paymentMode Payment
Service Service[]
}
enum Payment {
Cash
Visa
}
model Service {
serviceId String @id @default(uuid())
type ServiceType
name String
price Float
Bill Bill @relation(fields: [billInvoiceNo], references: [invoiceNo], onDelete: Cascade)
billInvoiceNo String
}
enum ServiceType {
Bar
Laundry
}
我试着为每个实体做一个crud,但我最终得到了关系错误,比如foregin key之类的东西,这意味着我的关系有问题。
1条答案
按热度按时间zsohkypk1#
您的模式是有效的,尽管我建议在为表定义id时保持一致性。有些表的id是字符串类型,有些是数字类型。
下面是为模型创建实体的查询示例。
以下是查询响应: