You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use the [Data source generator](http://loopback.io/doc/en/lb3/Data-source-generator.html) to add a PostgreSQL data source to your application.
48
+
Use the [Data source generator](http://loopback.io/doc/en/lb3/Data-source-generator.html) to add a PostgreSQL data source to your application.
49
49
The generator will prompt for the database server hostname, port, and other settings
50
50
required to connect to a PostgreSQL database. It will also run the `npm install` command above for you.
51
51
@@ -96,7 +96,7 @@ const config = {
96
96
97
97
Check out [node-pg-pool](https://github.com/brianc/node-pg-pool) and [node postgres pooling example](https://github.com/brianc/node-postgres#pooling-example) for more information.
98
98
99
-
### Properties
99
+
### Configuration options
100
100
101
101
<table>
102
102
<thead>
@@ -106,7 +106,7 @@ Check out [node-pg-pool](https://github.com/brianc/node-pg-pool) and [node postg
106
106
<th>Description</th>
107
107
</tr>
108
108
</thead>
109
-
<tbody>
109
+
<tbody>
110
110
<tr>
111
111
<td>connector</td>
112
112
<td>String</td>
@@ -176,6 +176,14 @@ Check out [node-pg-pool](https://github.com/brianc/node-pg-pool) and [node postg
176
176
<td>Boolean/String</td>
177
177
<td>Set to <code>false</code> to disable default sorting on <code>id</code> column(s). Set to <code>numericIdOnly</code> to only apply to IDs with a number type <code>id</code>.</td>
178
178
</tr>
179
+
<tr>
180
+
<td>allowExtendedOperators</td>
181
+
<td>Boolean</td>
182
+
<td>Set to <code>true</code> to enable PostgreSQL-specific operators
<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
-
228
213
## Defining models
229
214
230
215
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:
@@ -295,7 +280,7 @@ The model definition consists of the following properties.
295
280
<th>Description</th>
296
281
</tr>
297
282
</thead>
298
-
<tbody>
283
+
<tbody>
299
284
<tr>
300
285
<td>name</td>
301
286
<td>Camel-case of the database table name</td>
@@ -560,43 +545,65 @@ CustomerRepository.find({
560
545
});
561
546
```
562
547
563
-
## Querying Postgres Array type fields
548
+
## Extended operators
549
+
550
+
PostgreSQL supports the following PostgreSQL-specific operators:
551
+
552
+
- [`contains`](#operator-contains)
553
+
554
+
Please note extended operators are disabled by default, you must enable
555
+
them at datasource level or model level by setting `allowExtendedOperators` to
556
+
`true`.
557
+
558
+
### Operator `contains`
564
559
565
-
**Note** The fields you are querying should be setup to use the postgresql array data type - see Defining models
560
+
The `contains` operator allow you to query array properties and pick only
561
+
rows where the stored value contains all of the items specified by the query.
562
+
563
+
The operator is implemented using PostgreSQL [array operator
The PostgreSQL connector supports _model discovery_ that enables you to create LoopBack models
597
604
based on an existing database schema. Once you defined your datasource:
598
-
- LoopBack 4 users could use the commend [`lb4 discover`](https://loopback.io/doc/en/lb4/Discovering-models.html) to discover models.
599
-
- For LB3 users, please check [Discovering models from relational databases](https://loopback.io/doc/en/lb3/Discovering-models-from-relational-databases.html).
605
+
- LoopBack 4 users could use the commend [`lb4 discover`](https://loopback.io/doc/en/lb4/Discovering-models.html) to discover models.
606
+
- For LB3 users, please check [Discovering models from relational databases](https://loopback.io/doc/en/lb3/Discovering-models-from-relational-databases.html).
600
607
601
608
(See [database discovery API](http://apidocs.strongloop.com/loopback-datasource-juggler/#datasource-prototype-discoverandbuildmodels) for related APIs information)
602
609
@@ -670,7 +677,7 @@ Here are some limitations and tips:
670
677
671
678
### Auto-migrate/Auto-update models with foreign keys
672
679
673
-
Foreign key constraints can be defined in the model definition.
680
+
Foreign key constraints can be defined in the model definition.
674
681
675
682
**Note**: The order of table creation is important. A referenced table must exist before creating a foreign key constraint.
0 commit comments