Skip to content

Commit d8be8fc

Browse files
committed
array_type_field_filter: Adds new section in README.
1) Adds Array field contains filter in readme file. 2) Explains the usage of allowExtendedOperators true.
1 parent 5fc5d1e commit d8be8fc

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

README.md

+58
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,29 @@ const config = {
202202
};
203203
```
204204

205+
206+
## Additional properties
207+
208+
<table>
209+
<thead>
210+
<tr>
211+
<th width="160">Property</th>
212+
<th width="90">Type</th>
213+
<th>Default</th>
214+
<th>Description</th>
215+
</tr>
216+
</thead>
217+
<tbody>
218+
<tr>
219+
<td>allowExtendedOperators</td>
220+
<td>Boolean</td>
221+
<td><code>false</code></td>
222+
<td>Set to <code>true</code> to enable using Postgres operators such as <code>contains</code> which is used to perform filter on postgres array type field.</td>
223+
</tr>
224+
</tbody>
225+
</table>
226+
227+
205228
## Defining models
206229

207230
LoopBack allows you to specify some database settings through the model definition and/or the property definition. These definitions would be mapped to the database. Please check out the CLI [`lb4 model`](https://loopback.io/doc/en/lb4/Model-generator.html) for generating LB4 models. The following is a typical LoopBack 4 model that specifies the schema, table and column details through model definition and property definitions:
@@ -412,6 +435,12 @@ details on LoopBack's data types.
412435
VARCHAR2<br/>
413436
Default length is 1024
414437
</td>
438+
</tr>
439+
<tr>
440+
<td>String[]</td>
441+
<td>
442+
VARCHAR2[]
443+
</td>
415444
</tr>
416445
<tr>
417446
<td>Number</td>
@@ -531,6 +560,35 @@ CustomerRepository.find({
531560
});
532561
```
533562
563+
## Querying Postgres Array type fields
564+
565+
**Note** The fields you are querying should be setup to use the postgresql array data type - see Defining models
566+
567+
Assuming a model such as this:
568+
569+
```ts
570+
@property({
571+
type: ['string'],
572+
postgresql: {
573+
dataType: 'varchar[]',
574+
},
575+
})
576+
categories?: string[];
577+
```
578+
579+
You can query the tags fields via setting allowExtendedOperators to true
580+
581+
```ts
582+
Model.dataSource.settings.allowExtendedOperators = true;
583+
const post = await Post.find({where: {
584+
{
585+
categories: {'contains': ['AA']},
586+
}
587+
}
588+
});
589+
```
590+
591+
534592
## Discovery and auto-migration
535593
536594
### Model discovery

0 commit comments

Comments
 (0)