Taylor Lindores-Reeves
09/05/2022, 12:25 PMKay Khan
09/05/2022, 1:54 PMKay Khan
09/05/2022, 3:19 PMcore/
lambda/
within lambda folder.
npx prisma generate --schema ../core/prisma/schema.prisma
✔ Generated Prisma Client (4.3.1 | library) to ./../core/node_modules/@prisma/client in 162ms
You can now start using Prisma Client in your code. Reference: <https://pris.ly/d/client>
It installed within the ./../core/node_modules/@prisma/client in 162ms
how do i isntall the prisma client to the current lambda folder node_modues e,g node_modules/
Yuval Datner
09/05/2022, 3:19 PMJaskaran Yadav
09/05/2022, 5:15 PMJaskaran Yadav
09/05/2022, 5:17 PMs s
09/05/2022, 6:04 PMRexford Koomson
09/05/2022, 7:46 PMJason Marmon
09/06/2022, 3:09 AMto_tsvector('english', body) @@ to_tsquery('english', 'friend');
) , I want to set the default postgres setting default_text_search_config
globally.
I’m currently working around this via a migration which does:
ALTER SYSTEM SET default_text_search_config TO 'simple';
But another way to do this is per connection, e.g SET default_text_search_config = 'simple'
, but since this setting exists per connection I need to run it every time a connection is created. is there any reasonable way to run an $executeRaw
for each new pg connection?Jaskaran Yadav
09/06/2022, 3:19 AMKay Khan
09/06/2022, 8:54 AMfunctions: {
main: {
handler: "handler.MainHandler",
timeout: 300,
layers: {
Ref: "PrismaLambdaLayer",
},
},
},
Type '{ Ref: string; }' is not assignable to type 'AwsLambdaLayers'.
Object literal may only specify known properties, and 'Ref' does not exist in type 'AwsArn[]'.
Ørjan
09/06/2022, 9:00 AMmodel Shipment {
createdBy User? @relation("CreatedShipments", fields: [createdById], references: [id])
createdById. String?
lastUpdatedBy User? @relation("UpdatedShipments", fields: [lastUpdatedById], references: [id])
lastUpdatedById String?
}
Since you have two references to user, you will need to define different names for each of them you should also add the same names to the relations on the User side:
model User {
createdShipments Shipment[] @relation("CreatedShipments")
updatedShipments Shipment[] @relation("UpdatedShipments")
}
It is also necessary to define which field from user you want to reference by. In this case we use the ID from user and store it inside createdById and lastUpdatedById.
For question 2, createdAt will only use now() to store the date of the creation, and will not be updated later. for updatedAt you should use the @updatedAt attribute, and Prisma will automatically update the time for you:
updatedAt DateTime @updatedAt
(docs: https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#updatedat)Seb Powell
09/06/2022, 10:57 AMSeb Powell
09/06/2022, 10:58 AMMattia
09/06/2022, 11:41 AM@db.Timestamp(6)
, but prisma.table.findMany()
is auto parsed to JS Date, is any way to return string only?Kay Khan
09/06/2022, 4:00 PMKyle Oliveiro
09/06/2022, 5:26 PMprisma.Collection.findMany
, then manually retrieving a random record from there using Math.random
. this works, but my app is starting to grow and this function is now crashing in production presumably because i have too much data and the server is running out of memory trying to query everything at onceTed Joe
09/06/2022, 6:21 PMfirstName
and lastName
columns in my postgres db. How can I order by firstName + lastName
using prisma?Oscar Mejia
09/06/2022, 9:03 PMgenerator client {
provider = "prisma-client-js"
previewFeatures = ["interactiveTransactions", "referentialIntegrity"]
}
// process.env.production
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
referentialIntegrity = "prisma"
}
enum MANAGER_TYPE {
ADMIN
KITCHEN_MANAGER
}
model User {
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
email String? @unique
type MANAGER_TYPE @default(KITCHEN_MANAGER)
Restaurant Restaurant? @relation(fields: [restaurantId], references: [id])
restaurantId String?
User Order[]
}
model Restaurant {
id String @id @default(cuid())
name String
KMInventoryLastUpdatedAt DateTime?
adminInventoryLastUpdatedAt DateTime?
item Item[]
inventoryItems InventoryItem[]
user User[]
orders Order[]
}
model Item {
id String @id @default(cuid())
createdAt DateTime @default(now())
name String
par Float
unit Unit[]
amtOnHand Float?
Restaurant Restaurant @relation(fields: [restaurantId], references: [id])
restaurantId String
itemsOnOrder ItemsOnOrders[]
refInventoryItemId String?
}
model Unit {
id String @id @default(cuid())
updatedAt DateTime @updatedAt
name String
price Float
default Boolean
Item Item @relation(fields: [itemId], references: [id], onDelete: Cascade)
itemId String
itemsOnOrders ItemsOnOrders[]
refInventoryUnitId String?
}
model InventoryItem {
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
name String
par Float
inventoryUnit InventoryUnit[]
amtOnHand Float?
Restaurant Restaurant @relation(fields: [restaurantId], references: [id])
restaurantId String
}
model InventoryUnit {
id String @id @default(cuid())
updatedAt DateTime @updatedAt
name String
price Float
default Boolean
InventoryItem InventoryItem @relation(fields: [inventoryItemId], references: [id], onDelete: Cascade)
inventoryItemId String
}
model ItemsOnOrders {
Item Item @relation(fields: [itemId], references: [id], onDelete: Cascade)
itemId String
Order Order @relation(fields: [orderId], references: [id], onDelete: Cascade)
orderId Int
amtToOrder Float
Unit Unit @relation(fields: [unitId], references: [id]) // Unit used in Order
unitId String
@@id([itemId, orderId])
}
enum Status {
ACTIVE
FULLFILLED
}
model Order {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
User User @relation(fields: [userId], references: [id])
userId String
notes String
itemsOnOrder ItemsOnOrders[]
Restaurant Restaurant @relation(fields: [restaurantId], references: [id])
restaurantId String
status Status @default(ACTIVE)
}
I want it so when user deletes an Order -> related ItemsOnOrders is deleted -> Items in Order are deleted -> The Units of the those Items are deleted.
Right now, when I delete an Order -> related ItemsOnOrders is deleted, but the Items and Units remain. I also want to note that when I delete the ItemsOnOrders record manually from prisma studio, the Items remain even though I have it marked to cascade delete in the model ItemsOnOrders
Item Item @relation(fields: [itemId], references: [id], onDelete: Cascade)
Help is much appreciated 🙏Clément Guibout
09/06/2022, 10:05 PMBryan Z
09/07/2022, 5:11 AMlinks: async (context: Context) => await context.prisma.link.findMany()
in resolvers.ts
I get the error "Cannot read properties of undefined (reading 'prisma')"
when making a query in Apollo studio. However, not using context and calling links: async () => prisma.link.findMany(),
returns the data as expected.
Is there something wrong in my context.ts
file? Here are the contents and thanks for your help!
import type { NextApiRequest, NextApiResponse } from 'next'
import { PrismaClient } from '@prisma/client'
import prisma from '../src/server/db/client'
export type Context = {
prisma: PrismaClient
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export async function createContext(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
req: NextApiRequest,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
res: NextApiResponse
): Promise<Context> {
return {
prisma,
}
}
hoeJ K
09/07/2022, 5:24 AM/// schema.prisma
model RequestReaction {
id BigInt @id @default(autoincrement()) @db.BigInt
request RequestPost @relation(fields: [requestId], references: [id], onDelete: Cascade)
requestId BigInt
user User? @relation(fields: [userId], references: [id], onDelete: SetNull)
userId String?
type RequestReactionType
createdAt DateTime @default(now())
@@index([requestId, userId, type, createdAt(sort: Desc)])
@@map("requestreactions")
}
enum RequestReactionType {
LIKE
DISLIKE
}
model RequestPost {
id BigInt @id @default(autoincrement()) @db.BigInt
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User? @relation(fields: [userId], references: [id], onDelete: SetNull)
userId String?
title String @db.VarChar(255)
content String @db.LongText
category RequestCategoryType? @default(ETC)
creator Creator? @relation(fields: [creatorId], references: [id], onDelete: SetNull)
creatorId BigInt?
expires DateTime?
totalViews Int @default(0)
status RequestStatusType @default(REQUEST)
solvedUrl String?
refusalReason String?
requestApplyCreators RequestApplyCreator[]
requestPlatforms RequestPlatform[]
requestFundings RequestFunding[]
requestComments RequestComment[]
requestReactions RequestReaction[]
requestBookmarks RequestBookmark[]
requestReports RequestReport[]
requestInquirys RequestInquiry[]
@@index([userId, creatorId, status, createdAt(sort: Desc)])
@@fulltext([title, content])
@@map("requestposts")
}
// ...
//// client.ts
prisma.requestPost.findMany({
where: {
userId,
},
orderBy: [
// What should I do?
],
cursor: {
id: lastId,
},
take: 5,
skip: lastId ? 1 : 0,
include: {
requestComments: true,
requestApplyCreators: true,
requestFundings: true,
requestPlatforms: true,
requestReactions: true,
},
});
Zahra Mumtaz
09/07/2022, 8:25 AMreturn await this.prisma.permission.findFirst(({
where: { systemPermissions: { contains : permission }
} }))
Here systemPermission is an array of string. e.g: [“abc”, “Def”, “ghi”]
But it’s not working for me. Any help?Harry Lee
09/07/2022, 8:36 AMconst rawQuery: Prisma.Sql = Prisma.sql`
SELECT "balance".id,
"balance".user_id,
"balance".balance,
"balance".created_at,
"balance".updated_at
FROM "balance"
WHERE "balance".user_id = ${Number(input.userId)}
FOR UPDATE NOWAIT
`;
const balances = await _prismaService.$queryRaw<BalanceModel[]>(rawQuery);
Zahra Mumtaz
09/07/2022, 8:51 AMjanpio
binaryTargets
property of the Prisma Client generator
for.
(It is documented here: https://www.prisma.io/docs/concepts/components/prisma-schema/generators#binary-targets + https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#fields-1 + https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#binarytargets-options)
If you use binaryTargets
in your project, please let me know why you are using it, where you deploy to etc in this thread.
Thanks!Ted Joe
09/07/2022, 2:54 PMdb.$queryRaw
, I'm trying to ORDER BY
a variable,
so something like this:
`await db.$queryRaw`SELECT * FROM "User" ORDER BY ${order}``
But the order doesn't seem to have any effect. is there another way to do it?Ted Joe
09/07/2022, 3:19 PM${orderBy}
i.e. whether it's desc or asc, it throws an error...Omar
09/07/2022, 4:19 PMMay
09/07/2022, 4:23 PMENOENT: no such file or directory, open '/var/task/schema.prisma
but i am not sure why as my unit tests are passing and I can communicate with the DB via prisma.
For context, the project is bundled using Babel and infrastructure was created with AWS CDK