Skip to content

Commit a487dc1

Browse files
authored
Merge pull request #424 from strongloop/fix-docs
fix README display on the site
2 parents 700d1bc + 41432b7 commit a487dc1

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

README.md

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ If you create a PostgreSQL data source using the data source generator as descri
2424

2525
Use the [Data source generator](http://loopback.io/doc/en/lb3/Data-source-generator.html) to add a PostgreSQL data source to your application.
2626
The generator will prompt for the database server hostname, port, and other settings
27-
required to connect to a PostgreSQL database. It will also run the `npm install` command above for you.
27+
required to connect to a PostgreSQL database. It will also run the `npm install` command above for you.
2828

2929
The entry in the application's `/server/datasources.json` will look like this:
3030

3131
{% include code-caption.html content="/server/datasources.json" %}
32+
3233
```javascript
3334
"mydb": {
3435
"name": "mydb",
@@ -50,6 +51,7 @@ Edit `datasources.json` to add other properties that enable you to connect the
5051
You can also specify connection pool settings in `datasources.json`. For instance you can specify the minimum and the maximum pool size, and the maximum pool client's idle time before closing the client.
5152

5253
Example of `datasource.json`:
54+
5355
```
5456
{
5557
"mypostgresdb": {
@@ -68,6 +70,7 @@ Example of `datasource.json`:
6870
}
6971
}
7072
```
73+
7174
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.
7275

7376
### Properties
@@ -210,6 +213,7 @@ The model definition consists of the following properties.
210213
For example:
211214

212215
{% include code-caption.html content="/common/models/model.json" %}
216+
213217
```javascript
214218
{
215219
"name": "Inventory",
@@ -404,18 +408,18 @@ You can query the nested fields with dot notation:
404408
```javascript
405409
Customer.find({
406410
where: {
407-
'address.state': 'California'
411+
"address.state": "California"
408412
},
409-
order: 'address.city'
410-
})
413+
order: "address.city"
414+
});
411415
```
412416

413417
## Discovery and auto-migration
414418

415419
### Model discovery
416420

417421
The PostgreSQL connector supports _model discovery_ that enables you to create LoopBack models
418-
based on an existing database schema using the unified [database discovery API](http://apidocs.strongloop.com/loopback-datasource-juggler/#datasource-prototype-discoverandbuildmodels). For more information on discovery, see [Discovering models from relational databases](https://loopback.io/doc/en/lb3/Discovering-models-from-relational-databases.html).
422+
based on an existing database schema using the unified [database discovery API](http://apidocs.strongloop.com/loopback-datasource-juggler/#datasource-prototype-discoverandbuildmodels). For more information on discovery, see [Discovering models from relational databases](https://loopback.io/doc/en/lb3/Discovering-models-from-relational-databases.html).
419423

420424
### Auto-migration
421425

@@ -429,8 +433,8 @@ model: a table, for example, PRODUCT under the 'public' schema within the databa
429433

430434
The auto-migrate method:
431435

432-
* Defines a primary key for the properties whose `id` property is true (or a positive number).
433-
* Creates a column with 'SERIAL' type if the `generated` property of the `id` property is true.
436+
- Defines a primary key for the properties whose `id` property is true (or a positive number).
437+
- Creates a column with 'SERIAL' type if the `generated` property of the `id` property is true.
434438

435439
Destroying models may result in errors due to foreign key integrity. First delete any related models by calling delete on models with relationships.
436440

@@ -440,7 +444,7 @@ Foreign key constraints can be defined in the model `options`. Removing or updat
440444

441445
If there is a reference to an object being deleted then the `DELETE` will fail. Likewise if there is a create with an invalid FK id then the `POST` will fail.
442446

443-
**Note**: The order of table creation is important. A referenced table must exist before creating a foreign key constraint.
447+
**Note**: The order of table creation is important. A referenced table must exist before creating a foreign key constraint.
444448

445449
For **LoopBack 4** users, define your models under the `models/` folder as follows:
446450

@@ -464,6 +468,7 @@ export class Customer extends Entity {
464468
name: string;
465469
}
466470
```
471+
467472
`order.model.ts`:
468473

469474
```ts
@@ -494,7 +499,7 @@ export class Order extends Entity {
494499
For **LoopBack 3** users, you can define your model JSON schema as follows:
495500

496501
```json
497-
{
502+
({
498503
"name": "Customer",
499504
"options": {
500505
"idInjection": false
@@ -512,7 +517,6 @@ For **LoopBack 3** users, you can define your model JSON schema as follows:
512517
}
513518
}
514519
},
515-
516520
{
517521
"name": "Order",
518522
"options": {
@@ -542,7 +546,7 @@ For **LoopBack 3** users, you can define your model JSON schema as follows:
542546
"length": 40
543547
}
544548
}
545-
}
549+
})
546550
```
547551

548552
Auto-migrate supports the automatic generation of property values. For PostgreSQL, the default id type is _integer_. If you have `generated: true` in the id property, it generates integers by default:
@@ -571,6 +575,7 @@ It is common to use UUIDs as the primary key in PostgreSQL instead of integers.
571575
},
572576
}
573577
```
578+
574579
The setting uses `uuid-ossp` extension and `uuid_generate_v4()` function as default.
575580

576581
If you'd like to use other extensions and functions, you can do:
@@ -596,24 +601,35 @@ WARNING: It is the users' responsibility to make sure the provided extension and
596601
## Running tests
597602

598603
### Own instance
604+
599605
If you have a local or remote PostgreSQL instance and would like to use that to run the test suite, use the following command:
606+
600607
- Linux
608+
601609
```bash
602610
POSTGRESQL_HOST=<HOST> POSTGRESQL_PORT=<PORT> POSTGRESQL_USER=<USER> POSTGRESQL_PASSWORD=<PASSWORD> POSTGRESQL_DATABASE=<DATABASE> CI=true npm test
603611
```
612+
604613
- Windows
614+
605615
```bash
606616
SET POSTGRESQL_HOST=<HOST> SET POSTGRESQL_PORT=<PORT> SET POSTGRESQL_USER=<USER> SET POSTGRESQL_PASSWORD=<PASSWORD> SET POSTGRESQL_DATABASE=<DATABASE> SET CI=true npm test
607617
```
608618

609619
### Docker
620+
610621
If you do not have a local PostgreSQL instance, you can also run the test suite with very minimal requirements.
622+
611623
- Assuming you have [Docker](https://docs.docker.com/engine/installation/) installed, run the following script which would spawn a PostgreSQL instance on your local:
624+
612625
```bash
613626
source setup.sh <HOST> <PORT> <USER> <PASSWORD> <DATABASE>
614627
```
628+
615629
where `<HOST>`, `<PORT>`, `<USER>`, `<PASSWORD>` and `<DATABASE>` are optional parameters. The default values are `localhost`, `5432`, `root`, `pass` and `testdb` respectively.
630+
616631
- Run the test:
632+
617633
```bash
618634
npm test
619635
```

0 commit comments

Comments
 (0)