prisma-client-go icon indicating copy to clipboard operation
prisma-client-go copied to clipboard

Is there a Count() function?

Open Newcore-mobile opened this issue 3 years ago • 5 comments

I saw the official doc: https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client/crud#count have count() definition. But not found in the prisma-client-go.

Newcore-mobile avatar Sep 03 '20 07:09 Newcore-mobile

Unfortunately the go client does not support that yet, you'll have to use a raw query instead until we add this feature to the go client.

steebchen avatar Sep 03 '20 08:09 steebchen

All right, thank you 💯

Newcore-mobile avatar Sep 04 '20 06:09 Newcore-mobile

One thing I'd love to see is a count of relations.

	posts, err := d.db.Post.
		FindMany(filters...).
		With(
			db.Post.Author.Fetch(),
			db.Post.Tags.Fetch(),
			db.Post.Category.Fetch(),
			db.Post.Comments.Fetch().Count(), // Outputs a count of items in the Posts[] relation
		).
		Take(max).
		OrderBy(db.Post.CreatedAt.Order(db.Direction(sort))).
		Exec(ctx)

	// posts.CommentsCount or something would now contain a the number of comments linked with each post

Southclaws avatar Oct 30 '21 19:10 Southclaws

That's a good point. I'll bump this internally.

steebchen avatar Nov 01 '21 11:11 steebchen