express-sweet 1.0.12 → 1.0.16

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/docs/index.html CHANGED
@@ -6,7 +6,7 @@
6
6
  <title>Reference | Express Sweet</title>
7
7
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
8
8
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.3/css/all.css" integrity="sha384-SZXxX4whJ79/gErwcOYf+zWLeJdY/qpuqC4cAa9rOGUstPomtqpuNWT9wdPEn2fk" crossorigin="anonymous">
9
- <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.7.2/styles/agate.min.css">
9
+ <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.3.1/styles/github.min.css">
10
10
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.5.0/font/bootstrap-icons.css">
11
11
  <link href="styles/docs.css" rel="stylesheet">
12
12
  </head>
@@ -294,23 +294,13 @@ CREATE TABLE `book` (
294
294
  INSERT INTO `user` (`id`, `email`, `password`, `name`) VALUES
295
295
  (1, &#039;robin@example.com&#039;, &#039;password&#039;, &#039;Robin&#039;),
296
296
  (2, &#039;taylor@example.com&#039;, &#039;password&#039;, &#039;Taylor&#039;),
297
- (3, &#039;vivian@example.com&#039;, &#039;password&#039;, &#039;Vivian&#039;),
298
- (4, &#039;harry@example.com&#039;, &#039;password&#039;, &#039;Harry&#039;),
299
- (5, &#039;eliza@example.com&#039;, &#039;password&#039;, &#039;Eliza&#039;),
300
- (6, &#039;nancy@example.com&#039;, &#039;password&#039;, &#039;Nancy&#039;),
301
- (7, &#039;melinda@example.com&#039;, &#039;password&#039;, &#039;Melinda&#039;),
302
- (8, &#039;harley@example.com&#039;, &#039;password&#039;, &#039;Harley&#039;);
297
+ (3, &#039;vivian@example.com&#039;, &#039;password&#039;, &#039;Vivian&#039;);
303
298
 
304
299
  -- Add sample profile record
305
300
  INSERT INTO `profile` (`userId`, `address`, `tel`) VALUES
306
301
  (1, &#039;777 Brockton Avenue, Abington MA 2351&#039;, &#039;202-555-0105&#039;),
307
302
  (2, &#039;30 Memorial Drive, Avon MA 2322&#039;, &#039;&#039;),
308
- (3, &#039;250 Hartford Avenue, Bellingham MA 2019&#039;, &#039;202-555-0175&#039;),
309
- (4, &#039;700 Oak Street, Brockton MA 2301&#039;, &#039;202-555-0167&#039;),
310
- (5, &#039;66-4 Parkhurst Rd, Chelmsford MA 1824&#039;, &#039;202-555-0154&#039;),
311
- (6, &#039;591 Memorial Dr, Chicopee MA 1020&#039;, &#039;202-555-0141&#039;),
312
- (7, &#039;55 Brooksby Village Way, Danvers MA 1923&#039;, &#039;202-555-0196&#039;),
313
- (8, &#039;137 Teaticket Hwy, East Falmouth MA 2536&#039;, &#039;202-555-0167&#039;);
303
+ (3, &#039;250 Hartford Avenue, Bellingham MA 2019&#039;, &#039;202-555-0175&#039;);
314
304
 
315
305
  -- Add a sample user comment record
316
306
  INSERT INTO `comment` (`userId`, `text`) VALUES
@@ -320,12 +310,9 @@ INSERT INTO `comment` (`userId`, `text`) VALUES
320
310
 
321
311
  -- Add sample book record
322
312
  INSERT INTO `book` (`userId`, `title`) VALUES
323
- (1, &#039;The Stars Tonight&#039;),
324
- (1, &#039;A Guide to Courteous Thievery&#039;),
325
- (1, &#039;The Sound of Light&#039;),
326
- (2, &#039;The Stars Tonight&#039;),
327
- (2, &#039;Why She Said Yes&#039;);</code></pre>
328
-
313
+ (1, &#039;When Im Gone&#039;),
314
+ (1, &#039;Lose Yourself&#039;),
315
+ (2, &#039;When Im Gone&#039;);</code></pre>
329
316
  <p>
330
317
  Next, you need to set how the database is connected.<br>
331
318
  The database connection method can be set in <code>"config/database.js"</code>, so change it according to your environment.<br>
@@ -349,21 +336,21 @@ export default {
349
336
  development: {
350
337
  username: &#039;root&#039;,
351
338
  password: null,
352
- database: &#039;example&#039;,
339
+ database: &#039;testdb&#039;,
353
340
  host: &#039;localhost&#039;,
354
341
  dialect: &#039;mariadb&#039;
355
342
  },
356
343
  test: {
357
344
  username: &#039;root&#039;,
358
345
  password: null,
359
- database: &#039;example&#039;,
346
+ database: &#039;testdb&#039;,
360
347
  host: &#039;localhost&#039;,
361
348
  dialect: &#039;mariadb&#039;
362
349
  },
363
350
  production: {
364
351
  username: &#039;root&#039;,
365
352
  password: null,
366
- database: &#039;example&#039;,
353
+ database: &#039;testdb&#039;,
367
354
  host: &#039;localhost&#039;,
368
355
  dialect: &#039;mariadb&#039;
369
356
  }
@@ -377,21 +364,21 @@ module.exports = {
377
364
  development: {
378
365
  username: &#039;root&#039;,
379
366
  password: null,
380
- database: &#039;example&#039;,
367
+ database: &#039;testdb&#039;,
381
368
  host: &#039;localhost&#039;,
382
369
  dialect: &#039;mariadb&#039;
383
370
  },
384
371
  test: {
385
372
  username: &#039;root&#039;,
386
373
  password: null,
387
- database: &#039;example&#039;,
374
+ database: &#039;testdb&#039;,
388
375
  host: &#039;localhost&#039;,
389
376
  dialect: &#039;mariadb&#039;
390
377
  },
391
378
  production: {
392
379
  username: &#039;root&#039;,
393
380
  password: null,
394
- database: &#039;example&#039;,
381
+ database: &#039;testdb&#039;,
395
382
  host: &#039;localhost&#039;,
396
383
  dialect: &#039;mariadb&#039;
397
384
  }
@@ -912,13 +899,7 @@ module.exports = {
912
899
  The following example uses the user model to find the user who owns the credentials based on the username and password.<br>
913
900
  <pre><code class="js">authenticate_user: async (username, password) =&gt; {
914
901
  const UserModel = require(&#039;../models/UserModel&#039;);
915
- return UserModel.findOne({
916
- where: {
917
- email: username,
918
- password: password
919
- },
920
- raw: true
921
- });
902
+ return UserModel.findOne({where: {email: username, password: password}, raw: true});
922
903
  }</code></pre>
923
904
  </td>
924
905
  </tr>
@@ -931,10 +912,7 @@ module.exports = {
931
912
  The following example uses the user model to return the user information that owns the credentials based on the authenticated user's id.
932
913
  <pre><code class="js">subscribe_user: async (id) =&gt; {
933
914
  const UserModel = require(&#039;../models/UserModel&#039;);
934
- return UserModel.findOne({
935
- where: {id},
936
- raw: true
937
- });
915
+ return UserModel.findOne({where: {id}, raw: true});
938
916
  }</code></pre>
939
917
  </td>
940
918
  </tr>
@@ -944,9 +922,10 @@ module.exports = {
944
922
  By default, it requires an authenticated user for all requests.<br>
945
923
  You can use the <code>"allow_unauthenticated"</code> option to disable this behavior on certain requests.<br>
946
924
  For example, if you don’t want to authenticate all requests that contain "api" in the URL, set <code>"allow_unauthenticated"</code> as follows.
947
- <pre><code class="js">allow_unauthenticated: [
948
- &#039;/api&#039;
949
- ]</code></pre>
925
+ <pre><code class="js">allow_unauthenticated: [&#039;/api&#039;]</code></pre>
926
+
927
+ You can also use regular expressions.
928
+ <pre><code class="js">allow_unauthenticated: [/^\/api/]</code></pre>
950
929
  </td>
951
930
  </tr>
952
931
  <tr>
@@ -1016,13 +995,7 @@ export default {
1016
995
  * @type {(username: string, password: string) =&gt; Promise&lt;{[key: string]: any}|null&gt;}
1017
996
  */
1018
997
  authenticate_user: async (username, password) =&gt; {
1019
- return UserModel.findOne({
1020
- where: {
1021
- email: username,
1022
- password: password
1023
- },
1024
- raw: true
1025
- });
998
+ return UserModel.findOne({where: {email: username, password: password}, raw: true});
1026
999
  },
1027
1000
 
1028
1001
  /**
@@ -1033,15 +1006,12 @@ export default {
1033
1006
  * @type {(id: number|string) =&gt; Promise&lt;{[key: string]: any}&gt;}
1034
1007
  */
1035
1008
  subscribe_user: async (id) =&gt; {
1036
- return UserModel.findOne({
1037
- where: {id},
1038
- raw: true
1039
- });
1009
+ return UserModel.findOne({where: {id}, raw: true});
1040
1010
  },
1041
1011
 
1042
1012
  /**
1043
1013
  * URL without authentication. If the URL described in the access URL partially matches, authentication will not be performed, defaults to none.
1044
- * @type {string}
1014
+ * @type {(string|RegExp)[]}
1045
1015
  */
1046
1016
  allow_unauthenticated: [&#039;/api&#039;],
1047
1017
 
@@ -1099,13 +1069,7 @@ module.exports = {
1099
1069
  * @type {(username: string, password: string) =&gt; Promise&lt;{[key: string]: any}|null&gt;}
1100
1070
  */
1101
1071
  authenticate_user: async (username, password) =&gt; {
1102
- return UserModel.findOne({
1103
- where: {
1104
- email: username,
1105
- password: password
1106
- },
1107
- raw: true
1108
- });
1072
+ return UserModel.findOne({where: {email: username, password: password}, raw: true});
1109
1073
  },
1110
1074
 
1111
1075
  /**
@@ -1116,15 +1080,12 @@ module.exports = {
1116
1080
  * @type {(id: number|string) =&gt; Promise&lt;{[key: string]: any}&gt;}
1117
1081
  */
1118
1082
  subscribe_user: async (id) =&gt; {
1119
- return UserModel.findOne({
1120
- where: {id},
1121
- raw: true
1122
- });
1083
+ return UserModel.findOne({where: {id}, raw: true});
1123
1084
  },
1124
1085
 
1125
1086
  /**
1126
1087
  * URL without authentication. If the URL described in the access URL partially matches, authentication will not be performed, defaults to none.
1127
- * @type {string}
1088
+ * @type {(string|RegExp)[]}
1128
1089
  */
1129
1090
  allow_unauthenticated: [&#039;/api&#039;],
1130
1091
 
@@ -1216,38 +1177,32 @@ export default {
1216
1177
  development: {
1217
1178
  username: &#039;root&#039;,
1218
1179
  password: null,
1219
- database: &#039;example&#039;,
1180
+ database: &#039;testdb&#039;,
1220
1181
  host: &#039;localhost&#039;,
1221
- port: undefined,
1182
+ port: 3306,
1222
1183
  dialect: &#039;mariadb&#039;,
1223
1184
  timezone: &#039;+09:00&#039;,
1224
1185
  logging: false
1225
- //,timezone: &#039;Etc/GMT-9&#039;
1226
- //,dialectOptions: {useUTC: false, timezone: &#039;Etc/GMT-9&#039;}
1227
1186
  },
1228
1187
  test: {
1229
1188
  username: &#039;root&#039;,
1230
1189
  password: null,
1231
- database: &#039;example&#039;,
1190
+ database: &#039;testdb&#039;,
1232
1191
  host: &#039;localhost&#039;,
1233
- port: undefined,
1192
+ port: 3306,
1234
1193
  dialect: &#039;mariadb&#039;,
1235
1194
  timezone: &#039;+09:00&#039;,
1236
1195
  logging: false
1237
- //,timezone: &#039;Etc/GMT-9&#039;
1238
- //,dialectOptions: {useUTC: false, timezone: &#039;Etc/GMT-9&#039;}
1239
1196
  },
1240
1197
  production: {
1241
1198
  username: &#039;root&#039;,
1242
1199
  password: null,
1243
- database: &#039;example&#039;,
1200
+ database: &#039;testdb&#039;,
1244
1201
  host: &#039;localhost&#039;,
1245
- port: undefined,
1202
+ port: 3306,
1246
1203
  dialect: &#039;mariadb&#039;,
1247
1204
  timezone: &#039;+09:00&#039;,
1248
1205
  logging: false
1249
- //,timezone: &#039;Etc/GMT-9&#039;
1250
- //,dialectOptions: {useUTC: false, timezone: &#039;Etc/GMT-9&#039;}
1251
1206
  }
1252
1207
  }</code></pre>
1253
1208
  </div>
@@ -1259,38 +1214,32 @@ module.exports = {
1259
1214
  development: {
1260
1215
  username: &#039;root&#039;,
1261
1216
  password: null,
1262
- database: &#039;example&#039;,
1217
+ database: &#039;testdb&#039;,
1263
1218
  host: &#039;localhost&#039;,
1264
- port: undefined,
1219
+ port: 3306,
1265
1220
  dialect: &#039;mariadb&#039;,
1266
1221
  timezone: &#039;+09:00&#039;,
1267
1222
  logging: false
1268
- //,timezone: &#039;Etc/GMT-9&#039;
1269
- //,dialectOptions: {useUTC: false, timezone: &#039;Etc/GMT-9&#039;}
1270
1223
  },
1271
1224
  test: {
1272
1225
  username: &#039;root&#039;,
1273
1226
  password: null,
1274
- database: &#039;example&#039;,
1227
+ database: &#039;testdb&#039;,
1275
1228
  host: &#039;localhost&#039;,
1276
- port: undefined,
1229
+ port: 3306,
1277
1230
  dialect: &#039;mariadb&#039;,
1278
1231
  timezone: &#039;+09:00&#039;,
1279
1232
  logging: false
1280
- //,timezone: &#039;Etc/GMT-9&#039;
1281
- //,dialectOptions: {useUTC: false, timezone: &#039;Etc/GMT-9&#039;}
1282
1233
  },
1283
1234
  production: {
1284
1235
  username: &#039;root&#039;,
1285
1236
  password: null,
1286
- database: &#039;example&#039;,
1237
+ database: &#039;testdb&#039;,
1287
1238
  host: &#039;localhost&#039;,
1288
- port: undefined,
1239
+ port: 3306,
1289
1240
  dialect: &#039;mariadb&#039;,
1290
1241
  timezone: &#039;+09:00&#039;,
1291
1242
  logging: false
1292
- //,timezone: &#039;Etc/GMT-9&#039;
1293
- //,dialectOptions: {useUTC: false, timezone: &#039;Etc/GMT-9&#039;}
1294
1243
  }
1295
1244
  }</code></pre>
1296
1245
  </div>
@@ -1937,20 +1886,70 @@ Else
1937
1886
  <td class="min-w-150px text-primary fw-bolder">empty</td>
1938
1887
  <td class="min-w-200px w-100">
1939
1888
  <h4 id="view-helper-empty"><code class="method">empty</code></h4>
1940
- <p>Check if an array is empty.</p>
1889
+ <p>
1890
+ Check if it is empty.<br>
1891
+ If the value is an array, returns true if there are no elements.<br>
1892
+ If the value is a string, the leading and trailing spaces are trimmed and then checked.
1893
+ </p>
1941
1894
  <p class="fw-bolder mb-0">Params:</p>
1942
1895
  <ul>
1943
- <li>{any[]} items Array/object to be checked.</li>
1896
+ <li>{any} value Character strings, arrays, objects, etc. to be checked.</li>
1944
1897
  </ul>
1945
1898
  <p class="fw-bolder mb-0">Return:</p>
1946
- <p>{boolean} Returns true if the array is empty, false otherwise.</p>
1899
+ <p>{boolean} Returns true if the value is empty, false otherwise.</p>
1947
1900
  <p class="fw-bolder mb-0">Example:</p>
1948
- <pre class="mb-0"><code class="js">let items = [5, 6];
1949
- {{empty items}} =&gt; false
1901
+ <pre class="mb-0"><code class="js">// If the value is an array.
1902
+ let value = [5, 6];
1903
+ {{empty value}} =&gt; false
1950
1904
 
1951
- {{#if (empty items)}}
1905
+ {{#if (empty value)}}
1952
1906
  Hello
1953
- {{/if}}</code></pre>
1907
+ {{/if}}
1908
+
1909
+ // If the value is a string.
1910
+ let value = &#039;Hello&#039;;
1911
+ {{empty value}} =&gt; false
1912
+
1913
+ let value = &#039;&#039;;
1914
+ {{empty value}} =&gt; true
1915
+
1916
+ let value = &#039; &#039;;
1917
+ {{empty value}} =&gt; true</code></pre>
1918
+ </td>
1919
+ </tr>
1920
+ <tr>
1921
+ <td class="min-w-150px text-primary fw-bolder">not_empty</td>
1922
+ <td class="min-w-200px w-100">
1923
+ <h4 id="view-helper-not_empty"><code class="method">not_empty</code></h4>
1924
+ <p>
1925
+ Check that it is not empty.<br>
1926
+ If the value is an array, returns true if there is an element.<br>
1927
+ If the value is a string, the leading and trailing spaces are trimmed and then checked.
1928
+ </p>
1929
+ <p class="fw-bolder mb-0">Params:</p>
1930
+ <ul>
1931
+ <li>{any} value Character strings, arrays, objects, etc. to be checked.</li>
1932
+ </ul>
1933
+ <p class="fw-bolder mb-0">Return:</p>
1934
+ <p>{boolean} Returns true if the value is not empty, false otherwise.</p>
1935
+ <p class="fw-bolder mb-0">Example:</p>
1936
+ <pre class="mb-0"><code class="js">// If the value is an array.
1937
+ let value = [5, 6];
1938
+ {{not_empty value}} =&gt; true
1939
+
1940
+ {{#if (not_empty value)}}
1941
+ Hello
1942
+ {{/if}}
1943
+
1944
+ // If the value is a string.
1945
+ let value = &#039;Hello&#039;;
1946
+ {{not_empty value}} =&gt; true
1947
+
1948
+ let value = &#039;&#039;;
1949
+ {{not_empty value}} =&gt; false
1950
+
1951
+ let value = &#039; &#039;;
1952
+ {{not_empty value}} =&gt; false</code></pre>
1954
1953
  </td>
1955
1954
  </tr>
1956
1955
  <tr>
@@ -2196,9 +2195,8 @@ let value = &#039;2&#039;
2196
2195
  <!--begin::Accessing Models-->
2197
2196
  <h2 id="model-accessing">Accessing Models</h2>
2198
2197
  <p>
2199
- Model classes are stored in the "models" directory in the root directory.<br>
2200
- Loading the model gives you instant access to the model’s functions for working with the database.<br>
2201
- In the following example, "routes/users.js" loads "models/UserModel.js" and tries CRUD to the user table.
2198
+ Place the model in the "models" directory of the root directory.<br>
2199
+ When you load the model, you have immediate access to the model's functions for working with the database.
2202
2200
  </p>
2203
2201
  <div class="example">
2204
2202
  <ul class="nav nav-tabs">
@@ -2211,34 +2209,34 @@ let value = &#039;2&#039;
2211
2209
  </ul>
2212
2210
  <div class="tab-content">
2213
2211
  <div class="tab-pane fade show active" id="model-accessing-esm">
2214
- <pre><code class="js">import UserModel from &#039;../models/UserModel&#039;;
2212
+ <pre><code class="js">import BookModel from &#039;../models/BookModel&#039;;
2215
2213
 
2216
- // INSERT INTO user (email, name) VALUES (&#039;robin@example.com&#039;, &#039;Robin&#039;)
2217
- await UserModel.create({email: &#039;robin@example.com&#039;, name: &#039;Robin&#039;});
2214
+ // INSERT INTO book (title) VALUES (&#039;When Im Gone&#039;)
2215
+ await BookModel.create({title: &#039;When Im Gone&#039;});
2218
2216
 
2219
- // SELECT * FROM user
2220
- await UserModel.findAll();
2217
+ // SELECT * FROM book
2218
+ await BookModel.findAll();
2221
2219
 
2222
- // UPDATE user SET name = &#039;Taylor&#039; WHERE id= 1
2223
- await UserModel.update({name: &#039;Taylor&#039;}, {where: {id: 1}});
2220
+ // UPDATE book SET title = &#039;When Im Gone&#039; WHERE id= 1
2221
+ await BookModel.update({title: &#039;When Im Gone&#039;}, {where: {id: 1}});
2224
2222
 
2225
- // DELETE FROM user WHERE id= 1
2226
- await UserModel.destroy({where: {id: 1}});</code></pre>
2223
+ // DELETE FROM book WHERE id= 1
2224
+ await BookModel.destroy({where: {id: 1}});</code></pre>
2227
2225
  </div>
2228
2226
  <div class="tab-pane fade" id="model-accessing-cjs">
2229
- <pre><code class="js">const UserModel = require(&#039;../models/UserModel&#039;);
2227
+ <pre><code class="js">const BookModel = require(&#039;../models/BookModel&#039;);
2230
2228
 
2231
- // INSERT INTO user (email, name) VALUES (&#039;robin@example.com&#039;, &#039;Robin&#039;)
2232
- await UserModel.create({email: &#039;robin@example.com&#039;, name: &#039;Robin&#039;});
2229
+ // INSERT INTO book (title) VALUES (&#039;When Im Gone&#039;)
2230
+ await BookModel.create({title: &#039;When Im Gone&#039;});
2233
2231
 
2234
- // SELECT * FROM user
2235
- await UserModel.findAll();
2232
+ // SELECT * FROM book
2233
+ await BookModel.findAll();
2236
2234
 
2237
- // UPDATE user SET name = &#039;Taylor&#039; WHERE id= 1
2238
- await UserModel.update({name: &#039;Taylor&#039;}, {where: {id: 1}});
2235
+ // UPDATE book SET title = &#039;When Im Gone&#039; WHERE id= 1
2236
+ await BookModel.update({title: &#039;When Im Gone&#039;}, {where: {id: 1}});
2239
2237
 
2240
- // DELETE FROM user WHERE id= 1
2241
- await UserModel.destroy({where: {id: 1}});</code></pre>
2238
+ // DELETE FROM book WHERE id= 1
2239
+ await BookModel.destroy({where: {id: 1}});</code></pre>
2242
2240
  </div>
2243
2241
  </div>
2244
2242
  </div>
@@ -2521,65 +2519,65 @@ module.exports = class extends Model {
2521
2519
  </ul>
2522
2520
  <div class="tab-content">
2523
2521
  <div class="tab-pane fade show active" id="model-op-esm">
2524
- <pre><code class="js">import UserModel from &#39;../models/UserModel&#39;;
2522
+ <pre><code class="js">import BookModel from &#39;../models/BookModel&#39;;
2525
2523
 
2526
- // SELECT * FROM user WHERE email = &#39;robin@example.com&#39; AND password = &#39;password&#39;;
2527
- UserModel.findOne({
2524
+ // SELECT * FROM book WHERE title = &#39;When Im Gone&#39; AND genre = &#39;Nonfiction&#39;;
2525
+ BookModel.findOne({
2528
2526
  where: {
2529
- [UserModel.Op.and]: [
2530
- {email: &#39;robin@example.com&#39;},
2531
- {password: &#39;password&#39;}
2527
+ [BookModel.Op.and]: [
2528
+ {title: &#39;When Im Gone&#39;},
2529
+ {genre: &#39;Nonfiction&#39;}
2532
2530
  ]
2533
2531
  }
2534
2532
  });
2535
2533
 
2536
- // SELECT * FROM user WHERE name = &#39;Robin&#39; OR name = &#39;Taylor&#39;;
2537
- UserModel.findAll({
2534
+ // SELECT * FROM book WHERE title = &#39;When Im Gone&#39; OR title = &#39;Lose Yourself&#39;;
2535
+ BookModel.findAll({
2538
2536
  where: {
2539
- [UserModel.Op.or]: [
2540
- {name: &#39;Robin&#39;},
2541
- {name: &#39;Taylor&#39;}
2537
+ [BookModel.Op.or]: [
2538
+ {title: &#39;When Im Gone&#39;},
2539
+ {title: &#39;Lose Yourself&#39;}
2542
2540
  ]
2543
2541
  }
2544
2542
  });
2545
2543
 
2546
- // DELETE FROM user WHERE name = &#39;Robin&#39; OR name = &#39;Taylor&#39;;
2547
- UserModel.destroy({
2544
+ // DELETE FROM user WHERE name = &#39;When Im Gone&#39; OR name = &#39;Lose Yourself&#39;;
2545
+ BookModel.destroy({
2548
2546
  where: {
2549
- name: {
2550
- [UserModel.Op.or]: [&#39;Robin&#39;, &#39;Taylor&#39;]
2547
+ title: {
2548
+ [BookModel.Op.or]: [&#39;When Im Gone&#39;, &#39;Lose Yourself&#39;]
2551
2549
  }
2552
2550
  }
2553
2551
  });</code></pre>
2554
2552
  </div>
2555
2553
  <div class="tab-pane fade" id="model-op-cjs">
2556
- <pre><code class="js">const UserModel = require(&#39;../models/UserModel&#39;);
2554
+ <pre><code class="js">const BookModel = require(&#39;../models/BookModel&#39;);
2557
2555
 
2558
- // SELECT * FROM user WHERE email = &#39;robin@example.com&#39; AND password = &#39;password&#39;;
2559
- UserModel.findOne({
2556
+ // SELECT * FROM book WHERE title = &#39;When Im Gone&#39; AND genre = &#39;Nonfiction&#39;;
2557
+ BookModel.findOne({
2560
2558
  where: {
2561
- [UserModel.Op.and]: [
2562
- {email: &#39;robin@example.com&#39;},
2563
- {password: &#39;password&#39;}
2559
+ [BookModel.Op.and]: [
2560
+ {title: &#39;When Im Gone&#39;},
2561
+ {genre: &#39;Nonfiction&#39;}
2564
2562
  ]
2565
2563
  }
2566
2564
  });
2567
2565
 
2568
- // SELECT * FROM user WHERE name = &#39;Robin&#39; OR name = &#39;Taylor&#39;;
2569
- UserModel.findAll({
2566
+ // SELECT * FROM book WHERE title = &#39;When Im Gone&#39; OR title = &#39;Lose Yourself&#39;;
2567
+ BookModel.findAll({
2570
2568
  where: {
2571
- [UserModel.Op.or]: [
2572
- {name: &#39;Robin&#39;},
2573
- {name: &#39;Taylor&#39;}
2569
+ [BookModel.Op.or]: [
2570
+ {title: &#39;When Im Gone&#39;},
2571
+ {title: &#39;Lose Yourself&#39;}
2574
2572
  ]
2575
2573
  }
2576
2574
  });
2577
2575
 
2578
- // DELETE FROM user WHERE name = &#39;Robin&#39; OR name = &#39;Taylor&#39;;
2579
- UserModel.destroy({
2576
+ // DELETE FROM user WHERE name = &#39;When Im Gone&#39; OR name = &#39;Lose Yourself&#39;;
2577
+ BookModel.destroy({
2580
2578
  where: {
2581
- name: {
2582
- [UserModel.Op.or]: [&#39;Robin&#39;, &#39;Taylor&#39;]
2579
+ title: {
2580
+ [BookModel.Op.or]: [&#39;When Im Gone&#39;, &#39;Lose Yourself&#39;]
2583
2581
  }
2584
2582
  }
2585
2583
  });</code></pre>
@@ -2619,9 +2617,9 @@ const books = await BookModel.findAll({
2619
2617
  });
2620
2618
 
2621
2619
  // Output: books= [
2622
- // { title: 'MOBY DICK' },
2623
- // { title: 'GET RICH REALLY FAST' },
2624
- // { title: 'FINDING INNER PEACE' }
2620
+ // {title: 'MOBY DICK'},
2621
+ // {title: 'GET RICH REALLY FAST'},
2622
+ // {title: 'FINDING INNER PEACE'}
2625
2623
  // ]
2626
2624
  console.log('books=', books);</code></pre>
2627
2625
  </div>
@@ -2637,9 +2635,9 @@ const books = await BookModel.findAll({
2637
2635
  });
2638
2636
 
2639
2637
  // Output: books= [
2640
- // { title: &#39;MOBY DICK&#39; },
2641
- // { title: &#39;GET RICH REALLY FAST&#39; },
2642
- // { title: &#39;FINDING INNER PEACE&#39; }
2638
+ // {title: &#39;MOBY DICK&#39;},
2639
+ // {title: &#39;GET RICH REALLY FAST&#39;},
2640
+ // {title: &#39;FINDING INNER PEACE&#39;}
2643
2641
  // ]
2644
2642
  console.log(&#39;books=&#39;, books);</code></pre>
2645
2643
  </div>
@@ -2691,9 +2689,8 @@ const books = await BookModel.findAll({
2691
2689
  });
2692
2690
 
2693
2691
  // Output: books= [
2694
- // { id: 1, title: &#39;Moby Dick&#39;, count: 2 },
2695
- // { id: 2, title: &#39;Get Rich Really Fast&#39;, count: 1 },
2696
- // { id: 3, title: &#39;Finding Inner Peace&#39;, count: 0 }
2692
+ // {id: 1, title: &#39;When Im Gone&#39;, count: 2},
2693
+ // {id: 2, title: &#39;Lose Yourself&#39;, count: 1}
2697
2694
  // ]
2698
2695
  console.log(&#39;books=&#39;, books);</code></pre>
2699
2696
  </div>
@@ -2716,9 +2713,8 @@ const books = await BookModel.findAll({
2716
2713
  });
2717
2714
 
2718
2715
  // Output: books= [
2719
- // { id: 1, title: &#39;Moby Dick&#39;, count: 2 },
2720
- // { id: 2, title: &#39;Get Rich Really Fast&#39;, count: 1 },
2721
- // { id: 3, title: &#39;Finding Inner Peace&#39;, count: 0 }
2716
+ // {id: 1, title: &#39;When Im Gone&#39;, count: 2},
2717
+ // {id: 2, title: &#39;Lose Yourself&#39;, count: 1}
2722
2718
  // ]
2723
2719
  console.log(&#39;books=&#39;, books);</code></pre>
2724
2720
  </div>
@@ -2734,7 +2730,7 @@ console.log(&#39;books=&#39;, books);</code></pre>
2734
2730
  The attr can either be an object taken from Model.rawAttributes (for example Model.rawAttributes.id or Model.rawAttributes.name).<br>
2735
2731
  The attribute should be defined in your model definition.<br>
2736
2732
  The attribute can also be an object from one of the sequelize utility functions (sequelize.fn, sequelize.col etc.)<br>
2737
- For string attributes, use the regular { where: { attr: something }} syntax.<br>
2733
+ For string attributes, use the regular {where: {attr: something}} syntax.<br>
2738
2734
  If you don't want your string to be escaped, use sequelize.literal.<br>
2739
2735
  See <a href="https://sequelize.org/master/class/lib/sequelize.js~Sequelize.html#static-method-where" target="_blank">here</a> for details.
2740
2736
  </p>
@@ -2761,7 +2757,7 @@ const books = await BookModel.findAll({
2761
2757
  raw: true
2762
2758
  });
2763
2759
 
2764
- // Output: books= [ { title: &#39;Moby Dick&#39; } ]
2760
+ // Output: books= [{title: &#39;When Im Gone&#39;}]
2765
2761
  console.log(&#39;books=&#39;, books);</code></pre>
2766
2762
  </div>
2767
2763
  <div class="tab-pane fade" id="model-where-cjs">
@@ -2777,7 +2773,7 @@ const books = await BookModel.findAll({
2777
2773
  raw: true
2778
2774
  });
2779
2775
 
2780
- // Output: books= [ { title: &#39;Moby Dick&#39; } ]
2776
+ // Output: books= [{title: &#39;When Im Gone&#39;}]
2781
2777
  console.log(&#39;books=&#39;, books);</code></pre>
2782
2778
  </div>
2783
2779
  </div>
@@ -2791,6 +2787,19 @@ console.log(&#39;books=&#39;, books);</code></pre>
2791
2787
  See <a href="https://sequelize.org/master/variable/index.html#static-variable-QueryTypes" target="_blank">here</a> for details.
2792
2788
  </td>
2793
2789
  </tr>
2790
+ <tr>
2791
+ <td class="min-w-300px text-primary fw-bolder">public static readonly Transaction: (typeof <a href="https://sequelize.org/master/class/lib/transaction.js~Transaction.html" target="_blank">sequelize.Transaction</a>)</td>
2792
+ <td class="min-w-200px w-100">
2793
+ Reference to <a href="https://sequelize.org/master/class/lib/transaction.js~Transaction.html" target="_blank">sequelize.Transaction</a>.<br>
2794
+ This includes properties such as isolation level enums used with the transaction option.<br>
2795
+ See <a href="https://sequelize.org/master/class/lib/transaction.js~Transaction.html" target="_blank">here</a> for details.
2796
+ <pre><code class="js">const BookModel = require(&#39;../models/BookModel&#39;);
2797
+ BookModel.Transaction.ISOLATION_LEVELS.READ_UNCOMMITTED // &quot;READ UNCOMMITTED&quot;
2798
+ BookModel.Transaction.ISOLATION_LEVELS.READ_COMMITTED // &quot;READ COMMITTED&quot;
2799
+ BookModel.Transaction.ISOLATION_LEVELS.REPEATABLE_READ // &quot;REPEATABLE READ&quot;
2800
+ BookModel.Transaction.ISOLATION_LEVELS.SERIALIZABLE // &quot;SERIALIZABLE&quot;</code></pre>
2801
+ </td>
2802
+ </tr>
2794
2803
  </tbody>
2795
2804
  </table>
2796
2805
 
@@ -2859,13 +2868,17 @@ module.exports = class extends Model {
2859
2868
  </td>
2860
2869
  </tr>
2861
2870
  <tr>
2862
- <td class="min-w-300px text-primary fw-bolder">public static async begin(): Promise&lt;<a href="https://sequelize.org/master/class/lib/transaction.js~Transaction.html" target="_blank">sequelize.Transaction</a>&gt;</td>
2871
+ <td class="min-w-300px text-primary fw-bolder">public static async begin(opts?: sequelize.TransactionOptions): Promise&lt;<a href="https://sequelize.org/master/class/lib/transaction.js~Transaction.html" target="_blank">sequelize.Transaction</a>&gt;</td>
2863
2872
  <td class="min-w-200px w-100">
2864
2873
  <p>
2865
2874
  Starts a transaction and returns a transaction object to identify the running transaction.<br>
2866
2875
  This is an alias for the <code>"sequelize.Sequelize.transaction()"</code> method.<br>
2867
2876
  See <a href="https://sequelize.org/master/class/lib/sequelize.js~Sequelize.html#instance-method-transaction" target="_blank">here</a> and <a href="https://sequelize.org/master/class/lib/transaction.js~Transaction.html" target="_blank">here</a> for more information.
2868
2877
  </p>
2878
+ <p class="fw-bolder mb-0">Params:</p>
2879
+ <ul>
2880
+ <li>{sequelize.TransactionOptions} opts? Options provided when the transaction is created..</li>
2881
+ </ul>
2869
2882
  <p class="fw-bolder mb-0">Return:</p>
2870
2883
  <p>{Promise&lt;sequelize.Transaction&gt;} Returns a transaction object to identify the transaction being executed.</p>
2871
2884
  <p class="fw-bolder mb-0">Example:</p>
@@ -2880,49 +2893,74 @@ module.exports = class extends Model {
2880
2893
  </ul>
2881
2894
  <div class="tab-content">
2882
2895
  <div class="tab-pane fade show active" id="model-begin-esm">
2883
- <pre><code class="js">import UserModel from &#039;../models/UserModel&#039;;
2884
-
2896
+ <pre><code class="js">import BookModel from &#039;../models/BookModel&#039;;
2897
+
2898
+ // Simple transaction usage example.
2885
2899
  let transaction;
2886
2900
  try {
2887
- // START TRANSACTION;
2888
- transaction = await UserModel.begin();
2889
-
2890
- // SELECT `id`, `email`, `password`, `name`, `created`, `modified` FROM `user` AS `user` WHERE `user`.`id` = 1;
2891
- const user = await UserModel.findOne({where: {id: 1}}, {transaction});
2892
- user.name = &#039;Jane&#039;;
2893
-
2894
- // UPDATE `user` SET `name`=? WHERE `id` = ?
2895
- await user.save({transaction});
2901
+ transaction = await BookModel.begin();
2902
+ const book = await BookModel.create({title: &#039;When Im Gone&#039;}, {transaction});
2903
+ await transaction.commit();
2904
+ } catch(error) {
2905
+ if (transaction)
2906
+ await transaction.rollback();
2907
+ }
2896
2908
 
2897
- // COMMIT;
2909
+ // You can also use transaction options.
2910
+ let transaction;
2911
+ try {
2912
+ transaction = await BookModel.begin({
2913
+ isolationLevel: BookModel.Transaction.ISOLATION_LEVELS.REPEATABLE_READ,
2914
+ type: BookModel.Transaction.TYPES.DEFERRED,
2915
+ });
2916
+ const book = await BookModel.findOne({where: {id: 1}}, {transaction});
2917
+ book.title = &#039;When Im Gone&#039;;
2918
+ await book.save({transaction});
2898
2919
  await transaction.commit();
2899
- } catch(e) {
2900
- // ROLLBACK;
2901
- await transaction.rollback();
2920
+
2921
+ // Check the update result.
2922
+ // Output: New title of book: When Im Gone
2923
+ await book.reload();
2924
+ console.log(`New title of book: ${book.title}`);
2925
+ } catch (err) {
2926
+ if (transaction)
2927
+ await transaction.rollback();
2902
2928
  }</code></pre>
2903
2929
  </div>
2904
2930
  <div class="tab-pane fade" id="model-begin-cjs">
2905
- <pre><code class="js">const UserModel = require(&#039;../models/UserModel&#039;);
2931
+ <pre><code class="js">const BookModel = require(&#039;../models/BookModel&#039;);
2906
2932
 
2933
+ // Simple transaction usage example.
2907
2934
  let transaction;
2908
2935
  try {
2909
- // START TRANSACTION;
2910
- transaction = await UserModel.begin();
2911
-
2912
- // SELECT `id`, `email`, `password`, `name`, `created`, `modified` FROM `user` AS `user` WHERE `user`.`id` = 1;
2913
- const user = await UserModel.findOne({where: {id: 1}}, {transaction});
2914
- user.name = &#039;Jane&#039;;
2915
-
2916
- // UPDATE `user` SET `name`=? WHERE `id` = ?
2917
- await user.save({transaction});
2918
-
2919
- // COMMIT;
2936
+ transaction = await BookModel.begin();
2937
+ const book = await BookModel.create({title: &#039;When Im Gone&#039;}, {transaction});
2920
2938
  await transaction.commit();
2921
- } catch(e) {
2922
- // ROLLBACK;
2923
- await transaction.rollback();
2939
+ } catch(error) {
2940
+ if (transaction)
2941
+ await transaction.rollback();
2924
2942
  }
2925
- </code></pre>
2943
+
2944
+ // You can also use transaction options.
2945
+ let transaction;
2946
+ try {
2947
+ transaction = await BookModel.begin({
2948
+ isolationLevel: BookModel.Transaction.ISOLATION_LEVELS.REPEATABLE_READ,
2949
+ type: BookModel.Transaction.TYPES.DEFERRED,
2950
+ });
2951
+ const book = await BookModel.findOne({where: {id: 1}}, {transaction});
2952
+ book.title = &#039;When Im Gone&#039;;
2953
+ await book.save({transaction});
2954
+ await transaction.commit();
2955
+
2956
+ // Check the update result.
2957
+ // Output: New title of book: When Im Gone
2958
+ await book.reload();
2959
+ console.log(`New title of book: ${book.title}`);
2960
+ } catch (err) {
2961
+ if (transaction)
2962
+ await transaction.rollback();
2963
+ }</code></pre>
2926
2964
  </div>
2927
2965
  </div>
2928
2966
  </div>
@@ -2954,16 +2992,16 @@ try {
2954
2992
  </ul>
2955
2993
  <div class="tab-content">
2956
2994
  <div class="tab-pane fade show active" id="model-create-esm">
2957
- <pre><code class="js">import UserModel from &#039;../models/UserModel&#039;;
2995
+ <pre><code class="js">import BookModel from &#039;../models/BookModel&#039;;
2958
2996
 
2959
- // INSERT INTO `user` (`id`,`email`,`password`,`name`) VALUES (DEFAULT,&#039;ellen@example.com&#039;,&#039;password&#039;,&#039;Ellen&#039;);
2960
- await UserModel.create({email: &#039;ellen@example.com&#039;, password: &#039;password&#039;, name: &#039;Ellen&#039;});</code></pre>
2997
+ // INSERT INTO `book` (`id`,`title`) VALUES (DEFAULT,&#039;When Im Gone&#039;);
2998
+ await BookModel.create({title: &#039;When Im Gone&#039;});</code></pre>
2961
2999
  </div>
2962
3000
  <div class="tab-pane fade" id="model-create-cjs">
2963
- <pre><code class="js">const UserModel = require(&#039;../models/UserModel&#039;);
3001
+ <pre><code class="js">const BookModel = require(&#039;../models/BookModel&#039;);
2964
3002
 
2965
- // INSERT INTO `user` (`id`,`email`,`password`,`name`) VALUES (DEFAULT,&#039;ellen@example.com&#039;,&#039;password&#039;,&#039;Ellen&#039;);
2966
- await UserModel.create({email: &#039;ellen@example.com&#039;, password: &#039;password&#039;, name: &#039;Ellen&#039;});</code></pre>
3003
+ // INSERT INTO `book` (`id`,`title`) VALUES (DEFAULT,&#039;When Im Gone&#039;);
3004
+ await BookModel.create({title: &#039;When Im Gone&#039;});</code></pre>
2967
3005
  </div>
2968
3006
  </div>
2969
3007
  </div>
@@ -2994,26 +3032,26 @@ await UserModel.create({email: &#039;ellen@example.com&#039;, password: &#039;pa
2994
3032
  </ul>
2995
3033
  <div class="tab-content">
2996
3034
  <div class="tab-pane fade show active" id="model-save-esm">
2997
- <pre><code class="js">import UserModel from &#039;../models/UserModel&#039;;
3035
+ <pre><code class="js">import BookModel from &#039;../models/BookModel&#039;;
2998
3036
 
2999
- // INSERT INTO `user` (`id`,`email`,`password`,`name`) VALUES (DEFAULT,&#039;jane@example.com&#039;,&#039;password&#039;,&#039;Jane&#039;);
3000
- const user = UserModel.build({email: &#039;jane@example.com&#039;, password: &#039;password&#039;, name: &#039;Jane&#039;});
3001
- await user.save();
3037
+ // INSERT INTO `book` (`id`,`title`) VALUES (DEFAULT,&#039;When Im Gone&#039;);
3038
+ const book = BookModel.build({title: &#039;When Im Gone&#039;});
3039
+ await book.save();
3002
3040
 
3003
- // UPDATE `user` SET `name`=&#039;Ada&#039; WHERE `id` = 1;
3004
- user.name = &#039;Ada&#039;;
3005
- await user.save();</code></pre>
3041
+ // UPDATE `book` SET `title`=&#039;Lose Yourself&#039; WHERE `id` = 1;
3042
+ book.title = &#039;Lose Yourself&#039;;
3043
+ await book.save();</code></pre>
3006
3044
  </div>
3007
3045
  <div class="tab-pane fade" id="model-save-cjs">
3008
- <pre><code class="js">const UserModel = require(&#039;../models/UserModel&#039;);
3046
+ <pre><code class="js">const BookModel = require(&#039;../models/BookModel&#039;);
3009
3047
 
3010
- // INSERT INTO `user` (`id`,`email`,`password`,`name`) VALUES (DEFAULT,'jane@example.com','password','Jane');
3011
- const user = UserModel.build({email: 'jane@example.com', password: 'password', name: 'Jane'});
3012
- await user.save();
3048
+ // INSERT INTO `book` (`id`,`title`) VALUES (DEFAULT,&#039;When Im Gone&#039;);
3049
+ const book = BookModel.build({title: &#039;When Im Gone&#039;});
3050
+ await book.save();
3013
3051
 
3014
- // UPDATE `user` SET `name`='Ada' WHERE `id` = 1;
3015
- user.name = 'Ada';
3016
- await user.save();</code></pre>
3052
+ // UPDATE `book` SET `title`=&#039;Lose Yourself&#039; WHERE `id` = 1;
3053
+ book.title = &#039;Lose Yourself&#039;;
3054
+ await book.save();</code></pre>
3017
3055
  </div>
3018
3056
  </div>
3019
3057
  </div>
@@ -3045,16 +3083,16 @@ await user.save();</code></pre>
3045
3083
  </ul>
3046
3084
  <div class="tab-content">
3047
3085
  <div class="tab-pane fade show active" id="model-find-one-esm">
3048
- <pre><code class="js">import UserModel from &#039;../models/UserModel&#039;;
3086
+ <pre><code class="js">import BookModel from &#039;../models/BookModel&#039;;
3049
3087
 
3050
- // SELECT `id`, `email`, `password`, `name`, `created`, `modified` FROM `user` AS `user` LIMIT 1;
3051
- await UserModel.findOne();</code></pre>
3088
+ // SELECT `id`, `title`, `created`, `modified` FROM `book` AS `book` LIMIT 1;
3089
+ await BookModel.findOne();</code></pre>
3052
3090
  </div>
3053
3091
  <div class="tab-pane fade" id="model-find-one-cjs">
3054
- <pre><code class="js">const UserModel = require(&#039;../models/UserModel&#039;);
3092
+ <pre><code class="js">const BookModel = require(&#039;../models/BookModel&#039;);
3055
3093
 
3056
- // SELECT `id`, `email`, `password`, `name`, `created`, `modified` FROM `user` AS `user` LIMIT 1;
3057
- await UserModel.findOne();</code></pre>
3094
+ // SELECT `id`, `title`, `created`, `modified` FROM `book` AS `book` LIMIT 1;
3095
+ await BookModel.findOne();</code></pre>
3058
3096
  </div>
3059
3097
  </div>
3060
3098
  </div>
@@ -3085,25 +3123,25 @@ await UserModel.findOne();</code></pre>
3085
3123
  </ul>
3086
3124
  <div class="tab-content">
3087
3125
  <div class="tab-pane fade show active" id="model-find-all-esm">
3088
- <pre><code class="js">import UserModel from &#039;../models/UserModel&#039;;
3126
+ <pre><code class="js">import BookModel from &#039;../models/BookModel&#039;;
3089
3127
 
3090
- // SELECT `id`, `email`, `password`, `name`, `created`, `modified` FROM `user` AS `user` WHERE `user`.`name` LIKE &#039;Robin%&#039;;
3091
- const users = await UserModel.findAll({
3128
+ // SELECT `id`, `title`, `created`, `modified` FROM `book` AS `book` WHERE `book`.`title` LIKE &#039;When Im Gone%&#039;;
3129
+ await BookModel.findAll({
3092
3130
  where: {
3093
- name: {
3094
- [UserModel.Op.like]: &#039;Robin%&#039;
3131
+ title: {
3132
+ [BookModel.Op.like]: &#039;When Im Gone%&#039;
3095
3133
  }
3096
3134
  }
3097
3135
  });</code></pre>
3098
3136
  </div>
3099
3137
  <div class="tab-pane fade" id="model-find-all-cjs">
3100
- <pre><code class="js">const UserModel = require(&#039;../models/UserModel&#039;);
3138
+ <pre><code class="js">const BookModel = require(&#039;../models/BookModel&#039;);
3101
3139
 
3102
- // SELECT `id`, `email`, `password`, `name`, `created`, `modified` FROM `user` AS `user` WHERE `user`.`name` LIKE &#039;Robin%&#039;;
3103
- const users = await UserModel.findAll({
3140
+ // SELECT `id`, `title`, `created`, `modified` FROM `book` AS `book` WHERE `book`.`title` LIKE &#039;When Im Gone%&#039;;
3141
+ await BookModel.findAll({
3104
3142
  where: {
3105
- name: {
3106
- [UserModel.Op.like]: &#039;Robin%&#039;
3143
+ title: {
3144
+ [BookModel.Op.like]: &#039;When Im Gone%&#039;
3107
3145
  }
3108
3146
  }
3109
3147
  });</code></pre>
@@ -3137,16 +3175,16 @@ const users = await UserModel.findAll({
3137
3175
  </ul>
3138
3176
  <div class="tab-content">
3139
3177
  <div class="tab-pane fade show active" id="model-count-esm">
3140
- <pre><code class="js">import UserModel from &#039;../models/UserModel&#039;;
3178
+ <pre><code class="js">import BookModel from &#039;../models/BookModel&#039;;
3141
3179
 
3142
- // SELECT count(*) AS `count` FROM `user` AS `user`;
3143
- await UserModel.count();</code></pre>
3180
+ // SELECT count(*) AS `count` FROM `book` AS `book`;
3181
+ await BookModel.count();</code></pre>
3144
3182
  </div>
3145
3183
  <div class="tab-pane fade" id="model-count-cjs">
3146
- <pre><code class="js">const UserModel = require(&#039;../models/UserModel&#039;);
3184
+ <pre><code class="js">const BookModel = require(&#039;../models/BookModel&#039;);
3147
3185
 
3148
- // SELECT count(*) AS `count` FROM `user` AS `user`;
3149
- await UserModel.count();</code></pre>
3186
+ // SELECT count(*) AS `count` FROM `book` AS `book`;
3187
+ await BookModel.count();</code></pre>
3150
3188
  </div>
3151
3189
  </div>
3152
3190
  </div>
@@ -3178,22 +3216,16 @@ await UserModel.count();</code></pre>
3178
3216
  </ul>
3179
3217
  <div class="tab-content">
3180
3218
  <div class="tab-pane fade show active" id="model-update-esm">
3181
- <pre><code class="js">import UserModel from &#039;../models/UserModel&#039;;
3219
+ <pre><code class="js">import BookModel from &#039;../models/BookModel&#039;;
3182
3220
 
3183
- // UPDATE `user` SET `name`=&#039;Jane&#039; WHERE `id` = 1;
3184
- await UserModel.update(
3185
- {name: &#039;Jane&#039;},
3186
- {where: {id: 1}}
3187
- );</code></pre>
3221
+ // UPDATE `book` SET `title`=&#039;Lose Yourself&#039; WHERE `id` = 1;
3222
+ await BookModel.update({title: &#039;Lose Yourself&#039;}, {where: {id: 1}});</code></pre>
3188
3223
  </div>
3189
3224
  <div class="tab-pane fade" id="model-update-cjs">
3190
- <pre><code class="js">const UserModel = require(&#039;../models/UserModel&#039;);
3225
+ <pre><code class="js">const BookModel = require(&#039;../models/BookModel&#039;);
3191
3226
 
3192
- // UPDATE `user` SET `name`=&#039;Jane&#039; WHERE `id` = 1;
3193
- await UserModel.update(
3194
- {name: &#039;Jane&#039;},
3195
- {where: {id: 1}}
3196
- );</code></pre>
3227
+ // UPDATE `book` SET `title`=&#039;Lose Yourself&#039; WHERE `id` = 1;
3228
+ await BookModel.update({title: &#039;Lose Yourself&#039;}, {where: {id: 1}});</code></pre>
3197
3229
  </div>
3198
3230
  </div>
3199
3231
  </div>
@@ -3228,26 +3260,16 @@ await UserModel.update(
3228
3260
  </ul>
3229
3261
  <div class="tab-content">
3230
3262
  <div class="tab-pane fade show active" id="model-upsert-esm">
3231
- <pre><code class="js">import UserModel from &#039;../models/UserModel&#039;;
3263
+ <pre><code class="js">import BookModel from &#039;../models/BookModel&#039;;
3232
3264
 
3233
- // INSERT INTO `user` (`email`,`password`,`name`) VALUES (?,?,?)
3234
- // ON DUPLICATE KEY UPDATE `email`=VALUES(`email`),`password`=VALUES(`password`),`name`=VALUES(`name`);
3235
- await UserModel.upsert({
3236
- email: &#039;robin@example.com&#039;,
3237
- password: &#039;password&#039;,
3238
- name: &#039;Robin&#039;
3239
- });</code></pre>
3265
+ // INSERT INTO `book` (`title`) VALUES (?) ON DUPLICATE KEY UPDATE `title`=VALUES(`title`);
3266
+ await BookModel.upsert({title: &#039;Lose Yourself&#039;});</code></pre>
3240
3267
  </div>
3241
3268
  <div class="tab-pane fade" id="model-upsert-cjs">
3242
- <pre><code class="js">const UserModel = require(&#039;../models/UserModel&#039;);
3269
+ <pre><code class="js">const BookModel = require(&#039;../models/BookModel&#039;);
3243
3270
 
3244
- // INSERT INTO `user` (`email`,`password`,`name`) VALUES (?,?,?)
3245
- // ON DUPLICATE KEY UPDATE `email`=VALUES(`email`),`password`=VALUES(`password`),`name`=VALUES(`name`);
3246
- await UserModel.upsert({
3247
- email: &#039;robin@example.com&#039;,
3248
- password: &#039;password&#039;,
3249
- name: &#039;Robin&#039;
3250
- });</code></pre>
3271
+ // INSERT INTO `book` (`title`) VALUES (?) ON DUPLICATE KEY UPDATE `title`=VALUES(`title`);
3272
+ await BookModel.upsert({title: &#039;Lose Yourself&#039;});</code></pre>
3251
3273
  </div>
3252
3274
  </div>
3253
3275
  </div>
@@ -3278,16 +3300,16 @@ await UserModel.upsert({
3278
3300
  </ul>
3279
3301
  <div class="tab-content">
3280
3302
  <div class="tab-pane fade show active" id="model-destroy-esm">
3281
- <pre><code class="js">import UserModel from &#039;../models/UserModel&#039;;
3303
+ <pre><code class="js">import BookModel from &#039;../models/BookModel&#039;;
3282
3304
 
3283
3305
  // DELETE FROM `user` WHERE `id` = 1;
3284
- await UserModel.destroy({where: {id :1}});</code></pre>
3306
+ await BookModel.destroy({where: {id :1}});</code></pre>
3285
3307
  </div>
3286
3308
  <div class="tab-pane fade" id="model-destroy-cjs">
3287
- <pre><code class="js">const UserModel = require(&#039;../models/UserModel&#039;);
3309
+ <pre><code class="js">const BookModel = require(&#039;../models/BookModel&#039;);
3288
3310
 
3289
3311
  // DELETE FROM `user` WHERE `id` = 1;
3290
- await UserModel.destroy({where: {id :1}});</code></pre>
3312
+ await BookModel.destroy({where: {id :1}});</code></pre>
3291
3313
  </div>
3292
3314
  </div>
3293
3315
  </div>
@@ -3863,11 +3885,11 @@ module.exports = class extends Model {
3863
3885
  // "books": [
3864
3886
  // {
3865
3887
  // "userId": 1,
3866
- // "title": "The Stars Tonight"
3888
+ // "title": "When Im Gone"
3867
3889
  // },
3868
3890
  // {
3869
3891
  // "userId": 1,
3870
- // "title": "A Guide to Courteous Thievery"
3892
+ // "title": "Lose Yourself"
3871
3893
  // }
3872
3894
  // ]
3873
3895
  // }
@@ -3900,11 +3922,11 @@ await UserModel.findAll({
3900
3922
  // "books": [
3901
3923
  // {
3902
3924
  // "userId": 1,
3903
- // "title": "The Stars Tonight"
3925
+ // "title": "When Im Gone"
3904
3926
  // },
3905
3927
  // {
3906
3928
  // "userId": 1,
3907
- // "title": "A Guide to Courteous Thievery"
3929
+ // "title": "Lose Yourself"
3908
3930
  // }
3909
3931
  // ]
3910
3932
  // }
@@ -3935,11 +3957,11 @@ await UserModel.findAll({
3935
3957
  <p class="fw-bolder mb-0">Example:</p>
3936
3958
  <pre><code class="js">// By default the function will return two arguments - a results array, and an object containing metadata (such as amount of affected rows, etc).
3937
3959
  // Note that since this is a raw query, the metadata are dialect specific.
3938
- const [results, metadata] = await UserModel.query(&quot;UPDATE user SET name = &#039;Beil&#039; WHERE id = 1&quot;);
3960
+ const [results, metadata] = await BookModel.query(&quot;UPDATE book SET title = &#039;Lose Yourself&#039; WHERE id = 1&quot;);
3939
3961
 
3940
3962
  // In cases where you don&#039;t need to access the metadata you can pass in a query type to tell sequelize how to format the results. For example, for a simple select query you could do:
3941
3963
  // We didn&#039;t need to destructure the result here - the results were returned directly
3942
- const users = await sequelize.query(&quot;SELECT * FROM user&quot;, {type: UserModel.QueryTypes.SELECT});</code></pre>
3964
+ await BookModel.query(&quot;SELECT * FROM book&quot;, {type: BookModel.QueryTypes.SELECT});</code></pre>
3943
3965
  </td>
3944
3966
  </tr>
3945
3967
  </tbody>
@@ -4434,11 +4456,11 @@ const client = new sweet.services.AWSRekognitionClient({
4434
4456
  try {
4435
4457
  // Creates a collection.
4436
4458
  await client.createCollection(&#039;MyCollection&#039;);
4437
- } catch (e) {
4459
+ } catch(err) {
4438
4460
  // You can get the resulting HTTP status code from the exception.
4439
- console.log(`name: ${e.name}`);
4440
- console.log(`statusCode: ${e.statusCode}`);
4441
- console.log(`message: ${e.message}`);
4461
+ console.log(`name: ${err.name}`);
4462
+ console.log(`statusCode: ${err.statusCode}`);
4463
+ console.log(`message: ${err.message}`);
4442
4464
  }</code></pre>
4443
4465
  </div>
4444
4466
  <div class="tab-pane fade" id="rekog-method-create-collection-cjs">
@@ -4453,11 +4475,11 @@ const client = new AWSRekognitionClient({
4453
4475
  try {
4454
4476
  // Creates a collection.
4455
4477
  await client.createCollection(&#039;MyCollection&#039;);
4456
- } catch (e) {
4478
+ } catch(err) {
4457
4479
  // You can get the resulting HTTP status code from the exception.
4458
- console.log(`name: ${e.name}`);
4459
- console.log(`statusCode: ${e.statusCode}`);
4460
- console.log(`message: ${e.message}`);
4480
+ console.log(`name: ${err.name}`);
4481
+ console.log(`statusCode: ${err.statusCode}`);
4482
+ console.log(`message: ${err.message}`);
4461
4483
  }</code></pre>
4462
4484
  </div>
4463
4485
  </div>
@@ -4633,11 +4655,11 @@ const faceId = await client.indexFace(&#039;MyCollection&#039;, fs.readFileSync(
4633
4655
  // message: No face was found in the image
4634
4656
  try {
4635
4657
  await client.indexFace(&#039;MyCollection&#039;, &#039;img.jpg&#039;);
4636
- } catch (e) {
4658
+ } catch(err) {
4637
4659
  // You can get the resulting HTTP status code from the exception.
4638
- console.log(`name: ${e.name}`);
4639
- console.log(`statusCode: ${e.statusCode}`);
4640
- console.log(`message: ${e.message}`);
4660
+ console.log(`name: ${err.name}`);
4661
+ console.log(`statusCode: ${err.statusCode}`);
4662
+ console.log(`message: ${err.message}`);
4641
4663
  }
4642
4664
 
4643
4665
  // If multiple faces are found in the image, throw an error.
@@ -4646,11 +4668,11 @@ try {
4646
4668
  // message: Multiple faces found in the image
4647
4669
  try {
4648
4670
  await client.indexFace(&#039;MyCollection&#039;, &#039;img.jpg&#039;);
4649
- } catch (e) {
4671
+ } catch(err) {
4650
4672
  // You can get the resulting HTTP status code from the exception.
4651
- console.log(`name: ${e.name}`);
4652
- console.log(`statusCode: ${e.statusCode}`);
4653
- console.log(`message: ${e.message}`);
4673
+ console.log(`name: ${err.name}`);
4674
+ console.log(`statusCode: ${err.statusCode}`);
4675
+ console.log(`message: ${err.message}`);
4654
4676
  }</code></pre>
4655
4677
  </div>
4656
4678
  <div class="tab-pane fade" id="rekog-method-index-face-cjs">
@@ -4678,11 +4700,11 @@ const faceId = await client.indexFace(&#039;MyCollection&#039;, fs.readFileSync(
4678
4700
  // message: No face was found in the image
4679
4701
  try {
4680
4702
  await client.indexFace(&#039;MyCollection&#039;, &#039;img.jpg&#039;);
4681
- } catch (e) {
4703
+ } catch(err) {
4682
4704
  // You can get the resulting HTTP status code from the exception.
4683
- console.log(`name: ${e.name}`);
4684
- console.log(`statusCode: ${e.statusCode}`);
4685
- console.log(`message: ${e.message}`);
4705
+ console.log(`name: ${err.name}`);
4706
+ console.log(`statusCode: ${err.statusCode}`);
4707
+ console.log(`message: ${err.message}`);
4686
4708
  }
4687
4709
 
4688
4710
  // If multiple faces are found in the image, throw an error.
@@ -4691,11 +4713,11 @@ try {
4691
4713
  // message: Multiple faces found in the image
4692
4714
  try {
4693
4715
  await client.indexFace(&#039;MyCollection&#039;, &#039;img.jpg&#039;);
4694
- } catch (e) {
4716
+ } catch(err) {
4695
4717
  // You can get the resulting HTTP status code from the exception.
4696
- console.log(`name: ${e.name}`);
4697
- console.log(`statusCode: ${e.statusCode}`);
4698
- console.log(`message: ${e.message}`);
4718
+ console.log(`name: ${err.name}`);
4719
+ console.log(`statusCode: ${err.statusCode}`);
4720
+ console.log(`message: ${err.message}`);
4699
4721
  }</code></pre>
4700
4722
  </div>
4701
4723
  </div>
@@ -5063,7 +5085,7 @@ await client.deleteFaces(&#039;MyCollection&#039;, [&#039;f7befa24-3b83-43cc-b21
5063
5085
 
5064
5086
  <script src="https://code.jquery.com/jquery-3.6.0.slim.min.js" integrity="sha256-u7e5khyithlIdTpu22PHhENmPcRdFiHRjhAuHcs05RI=" crossorigin="anonymous"></script>
5065
5087
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script>
5066
- <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.7.2/highlight.min.js"></script>
5088
+ <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.3.1/highlight.min.js"></script>
5067
5089
  <script src="scripts/docs.js"></script>
5068
5090
  </body>
5069
5091
  </html>