Issue
in strapi v3 you could make a raw sql query the following way:
const data = await strapi.db.connection.raw(`SELECT * from table`);
However, in strapi v4 with typescript enabled, the same line gives the following error:
Property 'connection' does not exist on type 'Database'.
I've searched the documentation but I could not find how to make a custom sql query in strapi 4 with typescript enabled
Solution
you can do that exactly the same:
//@ts-ignore
let { rows } = await strapi.db.connection.raw(
`select id from posts where published_at IS NOT null order by random() limit ${count};`
);
sadly the strapi.db.connection
does yet not support types, for some reason cannot find this issue, but this prop is Knex
prop i'm not entirely sure but you an somehow cast it to Knex
Answered By - antokhio
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.