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

Commit 7465f83

Browse files
authored
docs(readme.md): add installation and usage details
and add tags in package.json
1 parent 850b467 commit 7465f83

File tree

3 files changed

+38
-20
lines changed

3 files changed

+38
-20
lines changed

.vscode/settings.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"**/.hg": true,
1616
"**/.svn": true,
1717
"**/CVS": true,
18-
"dist": true,
1918
},
2019
"files.insertFinalNewline": true,
2120
"files.trimTrailingWhitespace": true,

README.md

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,48 @@
11
# loopback4-sequelize
22

3-
[![LoopBack](https://github.com/loopbackio/loopback-next/raw/master/docs/site/imgs/branding/Powered-by-LoopBack-Badge-(blue)-@2x.png)](http://loopback.io/)
3+
[![LoopBack](<https://github.com/loopbackio/loopback-next/raw/master/docs/site/imgs/branding/Powered-by-LoopBack-Badge-(blue)-@2x.png>)](http://loopback.io/)
44

5-
## Installation
5+
This is a loopback 4 extension that provides Sequelize powered repository methods which is more performant than juggler (the default ORM in Loopback) for relational databases.
66

7-
Install LB4SequelizeComponent using `npm`;
7+
## Installation
88

99
```sh
10-
$ [npm install | yarn add] loopback4-sequelize
10+
npm install loopback4-sequelize
1111
```
1212

13-
## Basic Use
13+
## Usage
14+
15+
The extension can be used in new as well as existing projects. By just changing the parent classes in target Data Source and Repositories.
16+
17+
### Step 1: Configure DataSource
1418

15-
Configure and load LB4SequelizeComponent in the application constructor
16-
as shown below.
19+
Change the parent class from `juggler.DataSource` to `SequelizeDataSource` like below.
1720

1821
```ts
19-
import {LB4SequelizeComponent, LB4SequelizeComponentOptions, DEFAULT_LOOPBACK4_SEQUELIZE_OPTIONS} from 'loopback4-sequelize';
2022
// ...
21-
export class MyApplication extends BootMixin(ServiceMixin(RepositoryMixin(RestApplication))) {
22-
constructor(options: ApplicationConfig = {}) {
23-
const opts: LB4SequelizeComponentOptions = DEFAULT_LOOPBACK4_SEQUELIZE_OPTIONS;
24-
this.configure(LB4SequelizeComponentBindings.COMPONENT).to(opts);
25-
// Put the configuration options here
26-
});
27-
this.component(LB4SequelizeComponent);
28-
// ...
29-
}
23+
import {SequelizeDataSource} from 'loopback4-sequelize';
24+
25+
// ...
26+
export class PgDataSource
27+
extends SequelizeDataSource
28+
implements LifeCycleObserver {
29+
// ...
30+
}
31+
```
32+
33+
### Step 2: Configure Repository
34+
35+
Change the parent class from `DefaultCrudRepository` to `SequelizeRepository` like below.
36+
37+
```ts
38+
// ...
39+
import {SequelizeRepository} from 'loopback4-sequelize';
40+
41+
export class YourRepository extends SequelizeRepository<
42+
YourModel,
43+
typeof YourModel.prototype.id,
44+
YourModelRelations
45+
> {
3046
// ...
3147
}
3248
```

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
"description": "Loopback 4 extension that provides Sequelize powered repository methods.",
55
"keywords": [
66
"loopback-extension",
7-
"loopback"
7+
"loopback",
8+
"loopback4-sequelize",
9+
"sequelize",
10+
"repository"
811
],
912
"main": "dist/index.js",
1013
"types": "dist/index.d.ts",
@@ -30,7 +33,7 @@
3033
},
3134
"repository": {
3235
"type": "git",
33-
"url": "https://github.com/shubhamp-sf/loopback4-sequelize-extension"
36+
"url": ""
3437
},
3538
"author": "Shubham Prajapat <shubham.prajapat@sourcefuse.com>",
3639
"license": "",

0 commit comments

Comments
 (0)