所以我想在我的网站上实现搜索功能。在mysql中,我们有*
通配符用于0或更多的字符匹配。但似乎我们没有任何postgress sql,我已经检查了prisma文档,但我什么也没找到。我也尝试了&>
和&<
,但它不起作用。
这是我的密码。
import { PrismaClient } from "@prisma/client"
export default async function handler(req, res) {
const prisma = new PrismaClient()
var searchWords = req.query.search.split(" ")
searchWords = searchWords.map(word => {
// return `wildcard${word}wildcard`
return `${word}`
})
const query = searchWords.join(" | ")
console.log(query)
const data = await prisma.diary.findMany(
{
where: {
body: {
search: query
}, title: {
search: query
}
},
orderBy: {
timecreated: 'desc'
},
take: 10
}
)
data.map(x => {
x.timecreated = x.timecreated.toString()
x.lastedited = x.lastedited.toString()
return x
})
await prisma.$disconnect()
res.status(200).json(data)
}
1条答案
按热度按时间vecaoik11#
使用后缀
:*
: