diff --git a/adminforth/documentation/docs/tutorial/03-Customization/11-dataApi.md b/adminforth/documentation/docs/tutorial/03-Customization/11-dataApi.md index d7a370f6..3ed6c92f 100644 --- a/adminforth/documentation/docs/tutorial/03-Customization/11-dataApi.md +++ b/adminforth/documentation/docs/tutorial/03-Customization/11-dataApi.md @@ -123,6 +123,39 @@ const users = await admin.resource('adminuser').list( ); ``` +## Using a raw SQL in queries. + +Rarely you might want to add ciondition for some exotic SQL but still want to keep the rest of API. +Technically it happened that AdminForth allows you to do this also + +```js +const minUgcAge = 18; +const usersWithNoUgcAccess = await admin.resource('adminuser').list( + [ + Filters.NEQ('role', 'Admin'), + { + insecureRawSQL: `(user_meta->>'age') < ${sqlstring.escape(minUgcAge)}` + } + + ], 15, 0, Sorts.DESC('createdAt') +); + +This will produce next SQL query: +``` + +``` +SELECT * +FROM "adminuser" +WHERE "role" != 'Admin' + AND (user_meta->>'age') < 18 +ORDER BY "createdAt" DESC +LIMIT 15 OFFSET 0; + +``` + + +Finds users with age less then 18 from meta field which should be a JSONB field in Postgress. + ## Create a new item in database Signature: