user
07/20/2022, 9:53 AMEric Kreis
07/20/2022, 5:19 PMBen Ezard
07/21/2022, 12:48 AMprisma db push
works for MongoDB, but is there a way to prevent it from making breaking changes? (e.g. deleting fields, changing the type of fields, etc)
Given that Prisma MIgrate doesn't currently support MongoDB, I'm trying to figure out a good way of replicating the way that migrations work for relational DBsIshan Chhabra
07/21/2022, 6:26 AM{include: true}
a relation in prisma only when that field is asked in GraphQL query?
Say I have a Book table and an Author table. Book and Author are related.
I have a GQL Query
books {
name
author {
name
}
}
This resolves with const books = await prisma.book.findMany({include: {author: true}})
. What if I did not ask for the author? Although Graphql wont send it to client, I would like to avoid that unnecessary join on orm level.
I can use the info param of resolver function to see if that field was asked and conditionally use include in prisma but that is not scalable and kills the dx.
I thought if resolver chains could help. But am not sure how to go about it. Any help is much appreciated. Thank you!konsta
07/21/2022, 8:02 AMconst { field } = params
const { priority, status } = query
const groups = await db.issue.groupBy({
where: {
priority: {
in: priority,
},
status: {
in: status,
},
},
by: [field],
_count: true,
orderBy: {
[field]: 'desc',
},
})
return groups
returns
[
{
"_count": 338,
"status": "open"
},
{
"_count": 312,
"status": "in review"
},
{
"_count": 359,
"status": "in progress"
},
{
"_count": 314,
"status": "done"
},
{
"_count": 366,
"status": "canceled"
},
{
"_count": 329,
"status": null
}
]
let's say to something generic like "status" -> "group"?shahrukh ahmed
07/21/2022, 11:56 AMBenjamin FROLICHER
07/21/2022, 2:01 PMAnt Somers
07/21/2022, 4:37 PMcompanyId
of @@id([jobId, productId, companyId])
/// Intermediary between Job and Product
model Freight {
tonnage Float?
amount Int?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
job Job @relation(fields: [jobId], references: [id], onDelete: Cascade)
jobId String
product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
productId String
reciever Company? @relation(fields: [companyId], references: [id], onDelete: Cascade)
companyId String
pieces Piece[]
@@id([jobId, productId, companyId])
}
model Piece {
id String @id @default(cuid())
number Int
time DateTime @default(now())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
freight Freight @relation(fields: [freightJobId, freightProductId, freightCompanyId], references: [jobId, productId, companyId], onDelete: Cascade)
freightJobId String
freightProductId String
freightCompanyId String
damages PieceDamage[]
}
Michael Jay
07/21/2022, 5:10 PMXUncheckedWithoutYInput
is coming from, where X and Y are models, Y hasMany X?
What does "Unchecked" mean here? I see there's a XOR here:
XOR<Enumberable<XWithoutYInput>, Enumerable<XUncheckedWithoutYInput>>
Is the "Unchecked" version some sort of default, because when I explore the client file, it lands me on the Unchecked flavor.
I would assume maybe unchecked doesn't do type-checking, but it seems like the type definitions are exactly the same.Vinicius Carvalho
07/21/2022, 10:10 PMSELECT date(extract_created_at)
FROM payment_gateway_extracts
WHERE client_id = ${clientId}
GROUP BY date(extract_created_at)
ORDER BY date(extract_created_at) DESC
OFFSET ${skip}
LIMIT ${take}
``;`Vivek Poddar
07/22/2022, 7:41 AMVivek Poddar
07/22/2022, 7:42 AMexport async function getProducts({
filters,
page,
limit,
orderBy = { Name: "asc" },
searchTerm = "",
}: {
filters: string[];
page: number;
limit: number;
orderBy?: Record<string, string>;
searchTerm: string;
}): Promise<
Prisma.ProductGetPayload<{
include: { Category: true };
}>[]
> {
const { skip, take } = getItemsPaginated({ page, limit });
const prismaDBFilters = filters.map((filter) => ({
Name: { equals: filter },
}));
if (prismaDBFilters.length) {
return await prisma.product.findMany({
orderBy,
skip,
take,
where: {
Name: {
contains: searchTerm,
},
Category: {
OR: prismaDBFilters,
},
},
include: {
Category: true,
},
});
} else {
return await prisma.product.findMany({
orderBy,
skip,
take,
where: {
Name: {
contains: searchTerm,
},
},
include: {
Category: true,
},
});
}
}
Steven Kuck
07/22/2022, 4:34 PMBen Liger
07/22/2022, 5:10 PMFelipe Paz
07/22/2022, 6:23 PMtype UserIntensitySetting {
id: UUID! @id
category: WorkoutCategory!
historicalIntensitySettings: [HistoricalIntensitySetting!]! @relation(onDelete: CASCADE)
user: User!
createdAt: DateTime! @createdAt
}
So, I can do this
... await context.prisma.userIntensitySetting({ id: 'asdf-basdf-waaa-234' });
The problem is I'd like to do this query
... await context.prisma.userIntensitySetting({ category: 'strength' });
But I got an error saying this field is not in the schema. My question is: how could I do this query and use other fields beside the id field?Felipe Beiger
07/22/2022, 7:02 PMshahrukh ahmed
07/23/2022, 12:15 PMVivek Poddar
07/23/2022, 1:42 PMThe column `(not available)` does not exist in the current database.
Vivek Poddar
07/23/2022, 1:42 PMtheory Georgiou
07/23/2022, 6:39 PMtheory Georgiou
07/23/2022, 6:40 PMtheory Georgiou
07/23/2022, 6:40 PMtheory Georgiou
07/23/2022, 6:41 PMAustin
07/24/2022, 11:45 AMJannik Köster
07/24/2022, 7:20 PMType error: Property 'category' does not exist on type 'PrismaClient<PrismaClientOptions, never, RejectOnNotFound | RejectPerOperation | undefined>'.
Jannik Köster
07/24/2022, 7:20 PMJannik Köster
07/24/2022, 7:21 PMLloyd Richards
07/24/2022, 8:00 PMconst after = prisma.deviceEvent
.findMany({
where: {
device_id: device_id || undefined,
timestamp: {
gte: args.start_date || undefined,
lt: args.end_date || undefined,
},
},
})
const before = prisma.deviceEvent
.findFirst({
where: {
device_id: device_id || undefined,
timestamp: {
lte: args.start_date || undefined,
},
},
})
return [before, ...after];
but this doesnt feel very elegant and was hoping to find some before
or after
param i could use in prisma. Any suggestions?Adrian
07/25/2022, 12:26 PMAdrian
07/25/2022, 12:27 PM