事务和全文检索
事务
- 代码
ts
const [posts, totalPosts] = await prisma.$transaction([
prisma.emp.findMany({ where: { job: { contains: "开发" } } }),
prisma.emp.count(),
]);
console.log(posts);
console.log(totalPosts);
全文检索
添加全文索引
ts
generator client {
provider = "prisma-client-js"
}
model Blog {
id Int @unique
content String
title String
@@fulltext([content])
@@fulltext([content, title])
}
查询
ts
const result = await prisma.blogs.findMany({
where: {
content: {
search: "cat",
},
},
});
区分大小写
prisma 区分大小写依据的是表的建表规则,你要是建表的时候选择了排序规则支持区分大小写的.它就支持,否则就不支持
- 原生
使用 BINARY 关键字
ts
SELECT * FROM emp WHERE tags like BINARY '%OPY' ;