Skip to content
This repository was archived by the owner on Sep 4, 2024. It is now read-only.

Commit 3ce2938

Browse files
committed
docs(readme): update relations instruction
add debug string, update video demo links, update limitations
1 parent 025a217 commit 3ce2938

File tree

1 file changed

+91
-6
lines changed

1 file changed

+91
-6
lines changed

README.md

Lines changed: 91 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,29 @@ For pending features, refer to the [Limitations](#limitations) section below.
88

99
## Installation
1010

11+
To install this extension in your Loopback 4 project, run the following command:
12+
1113
```sh
1214
npm install loopback4-sequelize
1315
```
1416

17+
You'll also need to install the driver for your preferred database:
18+
19+
```sh
20+
# One of the following:
21+
npm install --save pg pg-hstore # Postgres
22+
npm install --save mysql2
23+
npm install --save mariadb
24+
npm install --save sqlite3
25+
npm install --save tedious # Microsoft SQL Server
26+
npm install --save oracledb # Oracle Database
27+
```
28+
1529
## Usage
1630

17-
> You can watch a video demo of this extension by [clicking here](https://youtu.be/tHg5ZAj29YQ).
31+
> You can watch a video overview of this extension by [clicking here](https://youtu.be/ZrUxIk63oRc).
1832
19-
Both newly developed and existing projects can benefit from the extension. By just changing the parent classes in the target Data Source and Repositories.
33+
Both newly developed and existing projects can benefit from the extension by simply changing the parent classes in the target Data Source and Repositories.
2034

2135
### Step 1: Configure DataSource
2236

@@ -51,12 +65,83 @@ export class YourRepository extends SequelizeCrudRepository<
5165
}
5266
```
5367

68+
## Relations
69+
70+
### Supported Loopback Relations
71+
72+
With `SequelizeCrudRepository`, you can utilize following relations without any additional configuration:
73+
74+
1. [HasMany Relation](https://loopback.io/doc/en/lb4/HasMany-relation.html)
75+
2. [BelongsTo Relation](https://loopback.io/doc/en/lb4/BelongsTo-relation.html)
76+
3. [HasOne Relation](https://loopback.io/doc/en/lb4/HasOne-relation.html)
77+
4. [HasManyThrough Relation](https://loopback.io/doc/en/lb4/HasManyThrough-relation.html)
78+
5. [ReferencesMany Relation](https://loopback.io/doc/en/lb4/ReferencesMany-relation.html)
79+
80+
The default relation configuration, generated using the [lb4 relation](https://loopback.io/doc/en/lb4/Relation-generator.html) command (i.e. inclusion resolvers in the repository and property decorators in the model), remain unchanged.
81+
82+
### INNER JOIN
83+
84+
> Check the demo video of using inner joins here: https://youtu.be/ZrUxIk63oRc?t=76
85+
86+
When using `SequelizeCrudRepository`, the `find()`, `findOne()`, and `findById()` methods accept a new option called `required` in the include filter. Setting this option to `true` will result in an inner join query that explicitly requires the specified condition for the child model. If the row does not meet this condition, it will not be fetched and returned.
87+
88+
An example of the filter object might look like this to fetch the books who contains "Art" in their title, which belongs to category "Programming":
89+
90+
```json
91+
{
92+
"where": {"title": {"like": "%Art%"}},
93+
"include": [
94+
{
95+
"relation": "category",
96+
"scope": {
97+
"where": {
98+
"name": "Programming"
99+
}
100+
},
101+
"required": true // 👈
102+
}
103+
]
104+
}
105+
```
106+
107+
## Debug strings reference
108+
109+
There are three built-in debug strings available in this extension to aid in debugging. To learn more about how to use them, see [this page](https://loopback.io/doc/en/lb4/Setting-debug-strings.html).
110+
111+
<table>
112+
<tbody>
113+
<tr>
114+
<th>String</th>
115+
<th>Description</th>
116+
</tr>
117+
<tr>
118+
<th colspan="2">Datasource</th>
119+
</tr>
120+
<tr>
121+
<td>loopback:sequelize:datasource</td>
122+
<td>Database Connections logs</td>
123+
</tr>
124+
<tr>
125+
<td>loopback:sequelize:queries</td>
126+
<td>Logs Executed SQL Queries and Parameters</td>
127+
</tr>
128+
<tr>
129+
<th colspan="2">Repository</th>
130+
</tr>
131+
<tr>
132+
<td>loopback:sequelize:modelbuilder</td>
133+
<td>Logs Translation of Loopback Models Into Sequelize Supported Definitions. Helpful When Debugging Datatype Issues</td>
134+
</tr>
135+
</tbody>
136+
</table>
137+
54138
## Limitations
55139

56140
Please note, the current implementation does not support the following:
57141

58142
1. SQL Transactions.
59-
2. Sequelize Powered Migrations.
143+
2. Loopback Migrations (via default `migrate.ts`). Though you're good if using external packages like [`db-migrate`](https://www.npmjs.com/package/db-migrate).
144+
3. Connection Pooling is not implemented yet.
60145

61146
Community contribution is welcome.
62147

@@ -69,12 +154,12 @@ If you think this extension is useful, please [star](https://help.github.com/en/
69154

70155
## Contributing
71156

72-
Please read [CONTRIBUTING.md](https://github.com/sourcefuse/loopback4-sequelize/blob/main/.github/CONTRIBUTING.md) for details on the process for submitting pull requests to us.
157+
Please read [CONTRIBUTING.md](https://github.com/sourcefuse/loopback4-sequelize/blob/master/.github/CONTRIBUTING.md) for details on the process for submitting pull requests to us.
73158

74159
## Code of conduct
75160

76-
Code of conduct guidelines [here](https://github.com/sourcefuse/loopback4-sequelize/blob/main/.github/CODE_OF_CONDUCT.md).
161+
Code of conduct guidelines [here](https://github.com/sourcefuse/loopback4-sequelize/blob/master/.github/CODE_OF_CONDUCT.md).
77162

78163
## License
79164

80-
[MIT](https://github.com/sourcefuse/loopback4-sequelize/blob/main/LICENSE)
165+
[MIT](https://github.com/sourcefuse/loopback4-sequelize/blob/master/LICENSE)

0 commit comments

Comments
 (0)