File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
adminforth/documentation/docs/tutorial/03-Customization Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -123,6 +123,39 @@ const users = await admin.resource('adminuser').list(
123123);
124124```
125125
126+ ## Using a raw SQL in queries.
127+
128+ Rarely you might want to add ciondition for some exotic SQL but still want to keep the rest of API.
129+ Technically it happened that AdminForth allows you to do this also
130+
131+ ``` js
132+ const minUgcAge = 18 ;
133+ const usersWithNoUgcAccess = await admin .resource (' adminuser' ).list (
134+ [
135+ Filters .NEQ (' role' , ' Admin' ),
136+ {
137+ insecureRawSQL: ` (user_meta->>'age') < ${ sqlstring .escape (minUgcAge)} `
138+ }
139+
140+ ], 15 , 0 , Sorts .DESC (' createdAt' )
141+ );
142+
143+ This will produce next SQL query:
144+ ```
145+
146+ ```
147+ SELECT *
148+ FROM "adminuser"
149+ WHERE "role" != 'Admin'
150+ AND (user_meta->>'age') < 18
151+ ORDER BY "createdAt" DESC
152+ LIMIT 15 OFFSET 0;
153+
154+ ```
155+
156+
157+ Finds users with age less then 18 from meta field which should be a JSONB field in Postgress.
158+
126159## Create a new item in database
127160
128161Signature:
You can’t perform that action at this time.
0 commit comments