Files
DefectingCat 5e1f58a144 Add search API
* update prisma
* Add search API in page
* add API with fetch
* Update search with global state
2022-02-08 20:40:08 +08:00

55 lines
880 B
JavaScript

import prismaClient from '@prisma/client';
const { PrismaClient } = prismaClient;
const prisma = new PrismaClient();
async function main() {
const result = await prisma.posts.findMany({
orderBy: {
title: 'asc',
},
where: {
OR: [
{
content: {
contains: 'javascript',
},
},
{
title: {
contains: 'javascript',
},
},
],
},
select: {
id: true,
title: true,
date: true,
url: true,
desc: true,
},
});
const count = await prisma.posts.count({
where: {
OR: [
{
content: {
contains: 'javascript',
},
},
{
title: {
contains: 'javascript',
},
},
],
},
});
console.log(count);
}
main().then();