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
{{ message }}
This repository was archived by the owner on Sep 4, 2024. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+91-6Lines changed: 91 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -8,15 +8,29 @@ For pending features, refer to the [Limitations](#limitations) section below.
8
8
9
9
## Installation
10
10
11
+
To install this extension in your Loopback 4 project, run the following command:
12
+
11
13
```sh
12
14
npm install loopback4-sequelize
13
15
```
14
16
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
+
15
29
## Usage
16
30
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).
18
32
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.
20
34
21
35
### Step 1: Configure DataSource
22
36
@@ -51,12 +65,83 @@ export class YourRepository extends SequelizeCrudRepository<
51
65
}
52
66
```
53
67
68
+
## Relations
69
+
70
+
### Supported Loopback Relations
71
+
72
+
With `SequelizeCrudRepository`, you can utilize following relations without any additional configuration:
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
+
54
138
## Limitations
55
139
56
140
Please note, the current implementation does not support the following:
57
141
58
142
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.
60
145
61
146
Community contribution is welcome.
62
147
@@ -69,12 +154,12 @@ If you think this extension is useful, please [star](https://help.github.com/en/
69
154
70
155
## Contributing
71
156
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.
73
158
74
159
## Code of conduct
75
160
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).
0 commit comments