express-sweet 2.0.7 → 2.0.9

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.
package/README.md CHANGED
@@ -1173,9 +1173,9 @@ To take advantage of EXPRESS SWEET’s model, you would simply create a new mode
1173
1173
  This class provides convenient access to the database connection, the Query Builder, and a number of additional convenience methods.
1174
1174
  For more information, see [reference](#model-class).
1175
1175
  ```js
1176
- import * as expressExtension from 'express-sweet';
1176
+ import * as expx from 'express-sweet';
1177
1177
 
1178
- export default class extends expressExtension.database.Model {
1178
+ export default class extends expx.database.Model {
1179
1179
  static get table() {
1180
1180
  return 'user';
1181
1181
  }
@@ -1216,9 +1216,31 @@ For more information on database configuration, see [Database configuration](#co
1216
1216
  `Promise<boolean>` Returns `true` if it can connect to the database, `false` if it cannot.
1217
1217
 
1218
1218
  ```js
1219
- import * as expressExtension from 'express-sweet';
1219
+ import * as expx from 'express-sweet';
1220
1220
 
1221
- await expressExtension.database.Database.isConnect();
1221
+ // Create Database instance.
1222
+ const config = await expx.utils.loadDatabaseConfig();
1223
+ const database = new expx.database.Database(config.database, config.username, config.password, config);
1224
+
1225
+ // Check database connection.
1226
+ await database.isConnect();
1227
+ ```
1228
+ - `public getConfig()`
1229
+ Returns the current database configuration object containing all sequelize options.
1230
+
1231
+ **Return:**
1232
+ `object` Database configuration object containing all sequelize options.
1233
+
1234
+ ```js
1235
+ import * as expx from 'express-sweet';
1236
+
1237
+ // Create Database instance.
1238
+ const config = await expx.utils.loadDatabaseConfig();
1239
+ const database = new expx.database.Database(config.database, config.username, config.password, config);
1240
+
1241
+ // Get database configuration.
1242
+ const currentConfig = database.getConfig();
1243
+ console.log(currentConfig);
1222
1244
  ```
1223
1245
 
1224
1246
  #### Model Class extends [sequelize.Model](https://sequelize.org/api/v6/class/src/model.js~model)
@@ -1229,9 +1251,9 @@ See [here](https://sequelize.org/api/v6/class/src/model.js~model) for more infor
1229
1251
  - `protected static table: string`
1230
1252
  The name of the table that the model accesses. This member must be defined in a subclass.
1231
1253
  ```js
1232
- import * as expressExtension from 'express-sweet';
1254
+ import * as expx from 'express-sweet';
1233
1255
 
1234
- export default class extends expressExtension.database.Model {
1256
+ export default class extends expx.database.Model {
1235
1257
  static get table() {
1236
1258
  return 'user';
1237
1259
  }
@@ -1240,9 +1262,9 @@ See [here](https://sequelize.org/api/v6/class/src/model.js~model) for more infor
1240
1262
  - `protected static attributes: sequelize.ModelAttributes`
1241
1263
  List of columns in the table accessed by this model. This member must be defined in a subclass.
1242
1264
  ```js
1243
- import * as expressExtension from 'express-sweet';
1265
+ import * as expx from 'express-sweet';
1244
1266
 
1245
- export default class extends expressExtension.database.Model {
1267
+ export default class extends expx.database.Model {
1246
1268
  static get attributes() {
1247
1269
  return {
1248
1270
  id: {
@@ -1378,10 +1400,10 @@ See [here](https://sequelize.org/api/v6/class/src/model.js~model) for more infor
1378
1400
  See the [here](https://sequelize.org/api/v6/class/src/associations/base.js~association) for more information.
1379
1401
  If you omit the alias (`as`) option, the associated name will be hasOne, singular for belongsTo, and plural for hasMany.
1380
1402
  ```js
1381
- import * as expressExtension from 'express-sweet';
1403
+ import * as expx from 'express-sweet';
1382
1404
  import ProfileModel from './ProfileModel';
1383
1405
 
1384
- export default class extends expressExtension.database.Model {
1406
+ export default class extends expx.database.Model {
1385
1407
  static association() {
1386
1408
  // User has one profile.
1387
1409
  this.hasOne(ProfileModel, {
@@ -1624,10 +1646,10 @@ See [here](https://sequelize.org/api/v6/class/src/model.js~model) for more infor
1624
1646
 
1625
1647
  This is a user model that defines an association in which the user has one profile.
1626
1648
  ```js
1627
- import * as expressExtension from 'express-sweet';
1649
+ import * as expx from 'express-sweet';
1628
1650
  import ProfileModel from './ProfileModel';
1629
1651
 
1630
- export default class extends expressExtension.database.Model {
1652
+ export default class extends expx.database.Model {
1631
1653
  static association() {
1632
1654
  // User has one profile.
1633
1655
  this.hasOne(ProfileModel, {
@@ -1702,10 +1724,10 @@ See [here](https://sequelize.org/api/v6/class/src/model.js~model) for more infor
1702
1724
 
1703
1725
  This is a profile model that defines an association whose profile belongs to one user.
1704
1726
  ```js
1705
- import * as expressExtension from 'express-sweet';
1727
+ import * as expx from 'express-sweet';
1706
1728
  import UserModel from './UserModel';
1707
1729
 
1708
- export default class extends expressExtension.database.Model {
1730
+ export default class extends expx.database.Model {
1709
1731
  static association() {
1710
1732
  // Profile belongs to one user.
1711
1733
  this.belongsTo(UserModel, {
@@ -1779,10 +1801,10 @@ See [here](https://sequelize.org/api/v6/class/src/model.js~model) for more infor
1779
1801
 
1780
1802
  This is a user model that defines an association in which the user has many comments.
1781
1803
  ```js
1782
- import * as expressExtension from 'express-sweet';
1804
+ import * as expx from 'express-sweet';
1783
1805
  import CommentModel from './CommentModel';
1784
1806
 
1785
- export default class extends expressExtension.database.Model {
1807
+ export default class extends expx.database.Model {
1786
1808
  static association() {
1787
1809
  // User has many comments.
1788
1810
  this.hasMany(CommentModel, {
@@ -1914,10 +1936,10 @@ See [here](https://sequelize.org/api/v6/class/src/model.js~model) for more infor
1914
1936
 
1915
1937
  This is a user model that defines an association where users and books have a many-to-many relationship.
1916
1938
  ```js
1917
- import * as expressExtension from 'express-sweet';
1939
+ import * as expx from 'express-sweet';
1918
1940
  import BookModel from './BookModel';
1919
1941
 
1920
- export default class extends expressExtension.database.Model {
1942
+ export default class extends expx.database.Model {
1921
1943
  static association() {
1922
1944
  // Users have many books, and books belong to many users.
1923
1945
  this.belongsToMany(BookModel, {
@@ -2146,11 +2168,11 @@ The post-authentication logic depends on whether the login request is received a
2146
2168
  If you redirect to /, the page will automatically switch to the URL specified in `success_redirect` of `config/authentication.js`.
2147
2169
  ```js
2148
2170
  import {Router} from 'express';
2149
- import * as expressExtension from 'express-sweet';
2171
+ import * as expx from 'express-sweet';
2150
2172
 
2151
2173
  const router = Router();
2152
2174
  router.post('/login', async (req, res, next) => {
2153
- const isAuthenticated = await expressExtension.services.Authentication.authenticate(req, res, next);
2175
+ const isAuthenticated = await expx.services.Authentication.authenticate(req, res, next);
2154
2176
  res.json(isAuthenticated);
2155
2177
  });
2156
2178
  export default router;
@@ -2180,15 +2202,15 @@ The post-authentication logic depends on whether the login request is received a
2180
2202
  If it fails, redirect to the page with the URL specified by `failure_redirect` in `config/authentication.js`.
2181
2203
  ```js
2182
2204
  import {Router} from 'express';
2183
- import * as expressExtension from 'express-sweet';
2205
+ import * as expx from 'express-sweet';
2184
2206
 
2185
2207
  const router = Router();
2186
2208
  router.post('/login', async (req, res, next) => {
2187
- const isAuthenticated = await expressExtension.services.Authentication.authenticate(req, res, next);
2209
+ const isAuthenticated = await expx.services.Authentication.authenticate(req, res, next);
2188
2210
  if (isAuthenticated)
2189
- await expressExtension.services.Authentication.successRedirect(res);
2211
+ await expx.services.Authentication.successRedirect(res);
2190
2212
  else
2191
- await expressExtension.services.Authentication.failureRedirect(req, res);
2213
+ await expx.services.Authentication.failureRedirect(req, res);
2192
2214
  });
2193
2215
  export default router;
2194
2216
  ```
@@ -2207,11 +2229,11 @@ If you want to log out the user, call the `services/Authentication.logout()` met
2207
2229
  Invoking `logout()` will remove the `req.user` property and clear the login session (if any).
2208
2230
  ```js
2209
2231
  import {Router} from 'express';
2210
- import * as expressExtension from 'express-sweet';
2232
+ import * as expx from 'express-sweet';
2211
2233
 
2212
2234
  const router = Router();
2213
2235
  router.get('/logout', (req, res) => {
2214
- expressExtension.services.Authentication.logout(req);
2236
+ expx.services.Authentication.logout(req);
2215
2237
  res.redirect('/');
2216
2238
  });
2217
2239
  export default router;