joao.santos
11/10/2021, 6:57 AMmodel Users {
id Int @id @default(autoincrement())
email String @unique
name String @db.VarChar(255)
conversations Conversations[]
messages Messages[]
}
model Conversations {
id Int @id @default(autoincrement())
name String @db.VarChar(255)
messages Messages[]
users Users[]
}
model Messages {
id Int @id @default(autoincrement())
message String @db.Text
userId Int
user Users @relation(_fields_: [userId], _references_: [id])
conversationId Int
conversation Conversations @relation(_fields_: [conversationId], _references_: [id])
}
SEED:
wait prisma.users.create({
data: {
email: '<mailto:user1@user.com|user1@user.com>',
name: 'User 1',
conversations: {
create: {
name: 'Conversation 1',
messages: {
create: {
message: 'Message 1',
userId: 1,
},
},
},
},
},
})
await prisma.users.create({
data: {
email: '<mailto:user2@user.com|user2@user.com>',
name: 'User 1',
conversations: {
connectOrCreate: {
where: { id: 1 },
create: {
name: 'Conversation 1',
messages: {
create: {
message: 'Message 2',
userId: 2,
},
},
},
},
},
},
})
manuel
11/10/2021, 9:52 AMmanuel
11/10/2021, 9:53 AMmanuel
11/10/2021, 9:53 AMmanuel
11/10/2021, 9:54 AMmanuel
11/10/2021, 9:54 AMLars Ivar Igesund
11/10/2021, 9:57 AMJames
11/10/2021, 10:43 AMStephen Osei-Bonsu
11/10/2021, 11:53 AMStephen Osei-Bonsu
11/10/2021, 11:55 AMuser
11/10/2021, 1:11 PMJaye
11/10/2021, 2:16 PMawait prisma.thing.findMany({
take: perPage,
orderBy: {
createdAt: "desc",
},
skip: cursor ? 1 : undefined,
cursor: {
createdAt: cursor,
},
}),
...but prisma doesn't like this because createdAt
isn't a unique field
alternatively, i could use id
as the cursor like in the example, but i am using `cuid`s:
model Thing {
id String @id @default(cuid())
// other stuff...
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
what's the best approach?n
11/10/2021, 2:27 PMdeleteMany()
including relationships, like you have a User
which has many Address
and I want to delete the user and all of their addresses? or do you have to cascade delete each in a transaction? 🤷Yazid Daoudi
11/10/2021, 3:51 PMNoel Martin Llevares
11/10/2021, 4:00 PMschema.prisma
still required at runtime? Can I exclude the prisma
directory?Raif Harik
11/10/2021, 6:01 PMtype FullBattery = Prisma.PromiseReturnType<typeof batteryRepository.getFullBatteryById>;
Problem is my batteryRepository takes PrismaClient and returns a map of functions as a good repo should. So I don't know how to get the dang getFullBatteryById function out so I can do the typeof on it.Raif Harik
11/10/2021, 6:02 PMSaimon Moore
11/10/2021, 6:31 PMJános Háber
11/10/2021, 10:56 PMLooks like you've forgot to provide experimental metadata API polyfill. Please read the installation instruction for more details.
János Háber
11/10/2021, 10:58 PMJános Háber
11/10/2021, 11:03 PMLooks like you've forgot to provide experimental metadata API polyfill. Please read the installation instruction for more details.
Error: Looks like you've forgot to provide experimental metadata API polyfill. Please read the installation instruction for more details.
at Object.ensureReflectMetadataExists (D:\Work\blickpunkt\v3\node_modules\type-graphql\dist\metadata\utils.js:42:15)
at new MetadataStorage (D:\Work\blickpunkt\v3\node_modules\type-graphql\dist\metadata\metadata-storage.js:27:17)
at Object.getMetadataStorage (D:\Work\blickpunkt\v3\node_modules\type-graphql\dist\metadata\getMetadataStorage.js:6:87)
at Object.registerEnumType (D:\Work\blickpunkt\v3\node_modules\type-graphql\dist\decorators\enums.js:6:26)
at Object.<anonymous> (D:\Work\blickpunkt\v3\node_modules\@generated\type-graphql\enums\SortOrder.js:29:13)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
János Háber
11/11/2021, 12:25 AMimport 'reflect-metadata';
Kelly Copley
11/11/2021, 1:07 AM@default
for an enum list field?Valerii Petryniak
11/11/2021, 2:45 AMMatt Young
11/11/2021, 5:29 AMMatt Young
11/11/2021, 5:30 AMMatt Young
11/11/2021, 5:31 AMMatt Young
11/11/2021, 5:31 AMMatt Young
11/11/2021, 5:31 AMMatt Young
11/11/2021, 5:53 AMsearchBy = ${JSON.stringify(searchBy)}
);
const results = await this.prisma.person.findMany(searchBy); (edited)