Manish
06/01/2021, 12:02 PMconst usersWithCount = await prisma.user.findMany({
select: {
_count: {
select: { posts: true },
},
},
})
Is it possible to get the count of posts based on a filter such as posts where status:'published'
?
Thanks!Michael
06/01/2021, 1:21 PMprisma generate
I'm able to generate models / resolvers using npx prisma generate
and all is working as expected. I've created a custom resolver and added it to the resolvers array in buildSchema:
@Resolver((of) => Auction)
export default class AuctionResolver {
@FieldResolver((returns) => Number, { nullable: true })
async totalBids(
@Root() auction: Auction,
@Ctx() { prisma }: Context
): Promise<number> {
const totalBids = await prisma.bid.aggregate({
_count: {
id: true,
},
where: {
auctionId: auction.id,
},
});
return totalBids._count.id;
}
}
The field shows up in graphql playground, but it's not in the generated model class; so when using the model types, I'm getting warnings for totalBids
Property 'totalBids' does not exist on type 'Auction'.ts(2339)
RemiO
06/01/2021, 3:31 PMDick Fickling
06/01/2021, 4:01 PMjdkdev
06/01/2021, 4:07 PMconst prisma = new PrismaClient()
once?
and then reference it throughout the api?Tharshan
06/01/2021, 5:17 PM/home/tharshan/Projects/uservitals/node_modules/@prisma/client/runtime/index.js:34784
throw new import_engine_core.PrismaClientUnknownRequestError(message, this.prisma._clientVersion);
^
PrismaClientUnknownRequestError2 [PrismaClientUnknownRequestError]:
Invalid `prisma.user.findUnique()` invocation:
Can't perform request, as the Engine has already been stopped
at cb (/home/tharshan/Projects/uservitals/node_modules/@prisma/client/runtime/index.js:34784:17)
at processTicksAndRejections (node:internal/process/task_queues:94:5)
at async searchContact (/home/tharshan/Projects/uservitals/api/db/seed.js:54:18)
at async /home/tharshan/Projects/uservitals/api/db/seed.js:840:23 {
clientVersion: '2.21.2'
}
Tharshan
06/01/2021, 5:17 PMVicky
06/01/2021, 5:23 PMnexusjs
For one date field, I am using type as Prisma db.date, now date in getting saved in correct format in db
But I wanted to know to fetch that field do I need to use nexusjs
custom date type? or it's not required?Logan
06/01/2021, 9:42 PMresult = *await* client*.*prisma*.*invites*.groupBy*({
by: ["inviterId"],
_count: {
inviterId: *true*,
},
orderBy: {
_count: {
inviterId: 'desc',
},
where: {
serverId: message*.*guildID,
valid: *true*,
},
},
});
Hi, I'm not sure if someone could help me. But I'm currently trying to order this by highest to lowest numbers. But im getting an error which im not sure how to get by.
Type '{ _count: { inviterId: string; }; where: { serverId: string | undefined; valid: true; }; }' is not assignable to type 'Enumerable<invitesOrderByInput> | undefined'.
Object literal may only specify known properties, and '_count' does not exist in type 'Enumerable<invitesOrderByInput>'
Manish
06/02/2021, 5:30 AMconst user = await prisma.user.findFirst({
where: { username: username },
include: {
posts: {
include: {
likedBy:true,
}
},
}
})
I’m getting a user with a specific user name, and I’m also getting the posts for the user. And for each post, I’m getting likedBy (which is a relation).
This works perfectly.
However, instead of getting the array of likedBy, if I want to get the count of liked by, I do the following:
const user = await prisma.user.findFirst({
where: { username: username },
include: {
posts: {
include: {
_count: {
select: {
likedBy:true
}
}
}
},
}
})
This query fails with error: PANIC in query-engine.
Can you help me with it?
Note that I’m able to use _count
on likedBy
if i’m just getting posts.Arun Kumar
06/02/2021, 6:24 AMPooja agrawal
06/02/2021, 7:24 AMBhavesh Goyal
06/02/2021, 9:26 AMNishant Salhotra
06/02/2021, 11:21 AMBEGIN
...COMMIT
). What will happen if one of the queries within that transaction fail?
2. What will happen to the queries executed before a failure during the migration. From what I've observed, the queries executed before the failed query aren't rolled back. But just wanted to check what would be the best practices around making sure that each migration is a transaction?
3. When is applied_steps_count
incremented in _prisma_migrations
table?Mikastark
06/02/2021, 12:07 PMHardik G
06/02/2021, 12:08 PMHardik G
06/02/2021, 12:08 PMAhmar Suhail
06/02/2021, 12:28 PMRemiO
06/02/2021, 12:33 PMUrmo R
06/02/2021, 12:58 PMmodel Account {
Id BigInt @unique @default(autoincrement()) @db.BigInt
Email String @unique
Password String
Roles Role[]
RoleIds BigInt[] @unique @db.BigInt
}
model Role {
Id BigInt @unique @default(autoincrement()) @db.BigInt
Name String
Enum String
Account Account? @relation(fields: [Id], references: [RoleIds])
}
anyone know how to implement RoleIds reference correctly?
Sun Strike
06/02/2021, 1:05 PMDev__
06/02/2021, 2:44 PMdraft:
typeof draft !== 'undefined'
? {
equals: draft // either true or false
}
: undefined
the value draft
is either a true
or a false
. when the value is true
it filters correctly and only shows me records with draft value set to true
, but with false
it shows me all records including the ones with true
instead of only record with the draft value set to false
. How could I fix thisAlexandr Bordun
06/02/2021, 3:37 PMDecimal
type -> string
)
what would be a suggestion on how to work with Prisma types in such cases? (so we can’t use the same types on “workers” methods)
I saw some {X}OutputType
definitions, but not for the entities directlyjdkdev
06/02/2021, 4:02 PMТоше
06/02/2021, 4:06 PMNima
06/02/2021, 5:22 PMNima
06/02/2021, 5:23 PMJean Suero
06/02/2021, 5:58 PMsorenbs