mirror of
https://github.com/DefectingCat/DefectingCat.github.io
synced 2025-07-16 17:21:37 +00:00
* update prisma * Add search API in page * add API with fetch * Update search with global state
55 lines
880 B
JavaScript
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();
|