For a blog website I am currently making I need to retrieve the recent articles from the database to show them on the main page of the blog. I do not want to retrieve the content of all 10 last articles but rather the beginning of them.
In Postgres, I would find all the articles, sort them by a created_at field, and SELECT the content with SELECT left(content, 15) to get the 15 first characters of the content of my article.
How can I achieve this with Prisma?
I tried
return prisma.article.findMany({
orderBy: {
createdAt: 'desc',
},
select: {
createdAt: true,
id: true,
title: true,
updatedAt: true,
content: 'left(content, 15)' as any
},
});
But it tells me that it is expecting a boolean value instead of string.
Thanks for your help.