From 356f4dfeabc8a7850927d5e8299e4ec3e76b56bf Mon Sep 17 00:00:00 2001 From: Sciederrick Date: Wed, 24 Jul 2024 19:25:09 +0300 Subject: [PATCH] docs(Typebox): Schema for allowed query properties Replace $ilike with a complete example using $regex --- docs/api/schema/typebox.md | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/docs/api/schema/typebox.md b/docs/api/schema/typebox.md index 1396a5e3de..e72aafdccf 100644 --- a/docs/api/schema/typebox.md +++ b/docs/api/schema/typebox.md @@ -97,7 +97,7 @@ const messageQuerySchema = querySyntax(messageQueryProperties) type MessageQuery = Static ``` -Additional special query properties [that are not already included in the query syntax](../databases/querying.md) like `$ilike` can be added like this: +Additional special query properties [that are not already included in the query syntax](../databases/querying.md) like `$regex` can be added like this: ```ts import { querySyntax } from '@feathersjs/typebox' @@ -108,10 +108,10 @@ const messageQueryProperties = Type.Pick(messageSchema, ['id', 'text', 'createdA }) const messageQuerySchema = Type.Intersect( [ - // This will additionally allow querying for `{ name: { $ilike: 'Dav%' } }` + // This will additionally allow querying for `{ name: { $regex: 'Dav', $options: 'i' } }` querySyntax(messageQueryProperties, { name: { - $ilike: Type.String() + $regex: Type.String(), $options: Type.String() } }), // Add additional query properties here @@ -121,6 +121,18 @@ const messageQuerySchema = Type.Intersect( ) ``` +Finally, in the class module, add the operators: + +```ts +export const getOptions = (app: Application): MongoDBAdapterOptions => { + return { + paginate: app.get('paginate'), + Model: app.get('mongodbClient').then((db) => db.collection('example')), + operators: ['$regex', '$options'] // add the operators + } +} +``` + To allow additional query properties outside of the query syntax use the intersection type: ```ts