在strapi v3中,您可以通过以下方式进行原始sql查询:
const data = await strapi.db.connection.raw(`SELECT * from table`);
但是,在启用类型记录的strapi v4中,同一行会出现以下错误:
Property 'connection' does not exist on type 'Database'.
我已经搜索了文档,但找不到如何在启用类型记录的情况下在strapi 4中创建自定义sql查询。
发布于 2022-11-30 12:02:23
你也可以这样做:
//@ts-ignore
let { rows } = await strapi.db.connection.raw(
`select id from posts where published_at IS NOT null order by random() limit ${count};`
);
遗憾的是,strapi.db.connection
还不支持类型,因为某种原因找不到这个问题,但是这个道具是Knex
道具--我不完全确定,但你不知怎么把它投给了Knex
https://stackoverflow.com/questions/74617222
复制相似问题