@gapi/sequelize 1.8.151 → 1.8.153

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +101 -108
  2. package/package.json +4 -3
package/README.md CHANGED
@@ -1,13 +1,15 @@
1
1
  # @Gapi/Sequelize
2
2
 
3
- <!-- ![Build Status](http://gitlab.youvolio.com/gapi/gapi/badges/branch/build.svg) -->
3
+ <!-- ![Build Status](https://github.com/Stradivario/gapi/issues) -->
4
4
 
5
5
  #### @Gapi Sequelize module @StrongTyped
6
6
 
7
- ##### For questions/issues you can write ticket [here](http://gitlab.youvolio.com/gapi/gapi-sequelize/issues)
7
+ ##### For questions/issues you can write ticket [here](https://github.com/Stradivario/gapi/issues)
8
+
8
9
  ##### This module is intended to be used with [GAPI](https://github.com/Stradivario/gapi)
9
10
 
10
11
  ## Installation and basic examples:
12
+
11
13
  ##### To install this Gapi module, run:
12
14
 
13
15
  ```bash
@@ -17,156 +19,149 @@ $ npm install @gapi/sequelize --save
17
19
  ## Consuming gapi-sequelize
18
20
 
19
21
  ##### Import inside AppModule or CoreModule
20
- ```typescript
21
22
 
23
+ ```typescript
22
24
  import { Module } from '@rxdi/core';
23
25
  import { SequelizeModule } from '@gapi/sequelize';
24
26
 
25
27
  @Module({
26
- imports: [
27
- SequelizeModule.forRoot({
28
- dialect: 'postgres',
29
- host: process.env.DB_HOST || '',
30
- port: process.env.DB_PORT || 5432,
31
- username: process.env.DB_USERNAME || '',
32
- password: process.env.DB_PASSWORD || '',
33
- database: process.env.DB_NAME || 'your-database',
34
- storage: ':memory:',
35
- logging: false,
36
- modelPaths: [process.cwd() + '/src/models'],
37
- force: false
38
- })
39
- ]
28
+ imports: [
29
+ SequelizeModule.forRoot({
30
+ dialect: 'postgres',
31
+ host: process.env.DB_HOST || '',
32
+ port: process.env.DB_PORT || 5432,
33
+ username: process.env.DB_USERNAME || '',
34
+ password: process.env.DB_PASSWORD || '',
35
+ database: process.env.DB_NAME || 'your-database',
36
+ storage: ':memory:',
37
+ logging: false,
38
+ modelPaths: [process.cwd() + '/src/models'],
39
+ force: false,
40
+ }),
41
+ ],
40
42
  })
41
- export class CoreModule { }
43
+ export class CoreModule {}
42
44
  ```
43
45
 
44
46
  ##### Create folder root/src/models and put this testing User Typescript-Sequelize Model with Uppercase name example: "User.ts"
45
- ```typescript
46
47
 
48
+ ```typescript
47
49
  import {
48
- Table,
49
- Column,
50
- Model,
51
- CreatedAt,
52
- UpdatedAt,
53
- DeletedAt,
54
- PrimaryKey,
55
- AutoIncrement,
56
- HasMany,
57
- DataType,
58
- BelongsToMany
50
+ Table,
51
+ Column,
52
+ Model,
53
+ CreatedAt,
54
+ UpdatedAt,
55
+ DeletedAt,
56
+ PrimaryKey,
57
+ AutoIncrement,
58
+ HasMany,
59
+ DataType,
60
+ BelongsToMany,
59
61
  } from 'sequelize-typescript';
60
62
 
61
63
  export interface UserSettings {
62
- sidebar: boolean;
64
+ sidebar: boolean;
63
65
  }
64
66
 
65
67
  @Table
66
68
  export class User extends Model<User> {
69
+ @PrimaryKey
70
+ @AutoIncrement
71
+ @Column
72
+ id: number;
67
73
 
68
- @PrimaryKey
69
- @AutoIncrement
70
- @Column
71
- id: number;
72
-
73
- @Column
74
- name: string;
75
-
76
- @Column({
77
- type: DataType.ENUM({ values: ['ADMIN', 'USER'] })
78
- })
79
- type: 'ADMIN' | 'USER';
80
-
81
- @Column({
82
- type: DataType.JSONB,
83
- allowNull: true
84
- })
85
- settings: UserSettings;
74
+ @Column
75
+ name: string;
86
76
 
77
+ @Column({
78
+ type: DataType.ENUM({ values: ['ADMIN', 'USER'] }),
79
+ })
80
+ type: 'ADMIN' | 'USER';
87
81
 
88
- @CreatedAt
89
- creationDate: Date;
82
+ @Column({
83
+ type: DataType.JSONB,
84
+ allowNull: true,
85
+ })
86
+ settings: UserSettings;
90
87
 
91
- @UpdatedAt
92
- updatedOn: Date;
88
+ @CreatedAt
89
+ creationDate: Date;
93
90
 
94
- @DeletedAt
95
- deletionDate: Date;
91
+ @UpdatedAt
92
+ updatedOn: Date;
96
93
 
94
+ @DeletedAt
95
+ deletionDate: Date;
97
96
  }
98
-
99
97
  ```
100
98
 
101
99
  ##### Final use this class inside your services the following way
102
100
 
103
101
  ```typescript
104
- import { Service } from "@rxdi/core";
105
- import { UserType } from "../types/user.type";
102
+ import { Service } from '@rxdi/core';
103
+ import { UserType } from '../types/user.type';
106
104
  import { User } from '../../../models/User';
107
105
 
108
106
  @Service()
109
107
  export class AnotherService {
110
- trimFirstLetter(username: string): string {
111
- return username.charAt(1);
112
- }
108
+ trimFirstLetter(username: string): string {
109
+ return username.charAt(1);
110
+ }
113
111
  }
114
112
 
115
113
  @Service()
116
114
  export class UserService {
117
- constructor(
118
- private anotherService: AnotherService
119
- ) { }
120
-
121
- async findUser(id: number): Promise<User> {
122
- return await User.findOne({ where: { id: id } });
123
- }
124
-
125
- async addUser(user: User): Promise<User> {
126
- return await User.create(user);
127
- }
128
-
129
- async deleteUser(id: number) {
130
- return await User.destroy({ where: { id: id } });
131
- }
132
-
133
- async updateUser(user: User) {
134
- return await User.update(user, {
135
- where: {
136
- id: user.id
137
- }
138
- })
139
- }
140
-
115
+ constructor(private anotherService: AnotherService) {}
116
+
117
+ async findUser(id: number): Promise<User> {
118
+ return await User.findOne({ where: { id: id } });
119
+ }
120
+
121
+ async addUser(user: User): Promise<User> {
122
+ return await User.create(user);
123
+ }
124
+
125
+ async deleteUser(id: number) {
126
+ return await User.destroy({ where: { id: id } });
127
+ }
128
+
129
+ async updateUser(user: User) {
130
+ return await User.update(user, {
131
+ where: {
132
+ id: user.id,
133
+ },
134
+ });
135
+ }
141
136
  }
142
-
143
137
  ```
144
138
 
145
139
  #### Advanced getting sequelize instance to manage your sequelize connection
146
140
 
147
- ```typescript
141
+ ```typescript
148
142
  import { Service } from '@rxdi/core';
149
143
  import { SequelizeService } from '@gapi/sequelize';
150
144
 
151
145
  @Service()
152
- export class SequelizePrivateService extends SequelizeService implements SequelizeService {
153
- sequelize: Sequelize;
154
- constructor() {
155
- super({
156
- dialect: 'postgres',
157
- host: process.env.DB_HOST || '',
158
- port: process.env.DB_PORT || '5432',
159
- username: process.env.DB_USERNAME || '',
160
- password: process.env.DB_PASSWORD || '',
161
- name: process.env.DB_NAME || 'your-database',
162
- storage: ':memory:',
163
- logging: false,
164
- modelPaths: [process.cwd() + '/src/models'],
165
- force: false
166
- })
167
- }
146
+ export class SequelizePrivateService
147
+ extends SequelizeService
148
+ implements SequelizeService {
149
+ sequelize: Sequelize;
150
+ constructor() {
151
+ super({
152
+ dialect: 'postgres',
153
+ host: process.env.DB_HOST || '',
154
+ port: process.env.DB_PORT || '5432',
155
+ username: process.env.DB_USERNAME || '',
156
+ password: process.env.DB_PASSWORD || '',
157
+ name: process.env.DB_NAME || 'your-database',
158
+ storage: ':memory:',
159
+ logging: false,
160
+ modelPaths: [process.cwd() + '/src/models'],
161
+ force: false,
162
+ });
163
+ }
168
164
  }
169
-
170
165
  ```
171
166
 
172
167
  #### Next import SequelizePrivateService inside Core or AppModule
@@ -177,13 +172,11 @@ import { SequelizeModule } from '@gapi/sequelize';
177
172
  import { SequelizePrivateService } from './services/sequelize/sequelize.service.ts';
178
173
 
179
174
  @Module({
180
- services: [SequelizePrivateService]
175
+ services: [SequelizePrivateService],
181
176
  })
182
- export class CoreModule { }
183
-
177
+ export class CoreModule {}
184
178
  ```
185
179
 
186
-
187
180
  TODO: Better documentation...
188
181
 
189
182
  Enjoy ! :)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gapi/sequelize",
3
- "version": "1.8.151",
3
+ "version": "1.8.153",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/Stradivario/gapi-sequelize.git"
@@ -13,6 +13,7 @@
13
13
  "patch": "npm run build && npm version patch && npm publish --update-readme --access public && npm run delete-dist",
14
14
  "delete-dist": "rm -rf dist",
15
15
  "clean": "git clean -dxf",
16
+ "test": "echo test",
16
17
  "lint": "npx eslint . --ext .ts",
17
18
  "lint-fix": "npx eslint . --fix --ext .ts",
18
19
  "build": "rm -rf dist && tsc || true"
@@ -28,13 +29,13 @@
28
29
  ],
29
30
  "license": "MIT",
30
31
  "bugs": {
31
- "url": "http://gitlab.youvolio.com/gapi/gapi-sequelize/issues"
32
+ "url": "https://github.com/Stradivario/gapi/issues"
32
33
  },
33
34
  "dependencies": {
34
35
  "sequelize": "^5.8.2",
35
36
  "sequelize-typescript": "^1.1.0"
36
37
  },
37
38
  "devDependencies": {
38
- "@rxdi/core": "^0.7.173"
39
+ "@rxdi/core": "^0.7.182"
39
40
  }
40
41
  }