express-sweet 1.0.11 → 1.0.15
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/CHANGELOG.md +0 -87
- package/docs/index.html +345 -295
- package/docs/styles/docs.css +5 -10
- package/package.json +1 -1
- package/dist/build.common.js +0 -53
- package/dist/build.esm.js +0 -53
- package/types/database/Database.d.ts +0 -162
- package/types/database/Model.d.ts +0 -158
- package/types/database/index.d.ts +0 -4
- package/types/database/loadModels.d.ts +0 -6
- package/types/exceptions/ApiError.d.ts +0 -29
- package/types/exceptions/index.d.ts +0 -2
- package/types/handlebars_helpers/comparison.d.ts +0 -261
- package/types/handlebars_helpers/html.d.ts +0 -11
- package/types/handlebars_helpers/index.d.ts +0 -5
- package/types/handlebars_helpers/object.d.ts +0 -21
- package/types/handlebars_helpers/string.d.ts +0 -12
- package/types/index.d.ts +0 -9
- package/types/interfaces/AuthenticationOptions.d.ts +0 -84
- package/types/interfaces/BoundingBox.d.ts +0 -25
- package/types/interfaces/Config.d.ts +0 -66
- package/types/interfaces/DatabaseOptions.d.ts +0 -7
- package/types/interfaces/FaceMatch.d.ts +0 -31
- package/types/interfaces/RekognitionOptions.d.ts +0 -26
- package/types/interfaces/ViewOptions.d.ts +0 -30
- package/types/interfaces/index.d.ts +0 -8
- package/types/middlewares/Authentication.d.ts +0 -16
- package/types/middlewares/CORS.d.ts +0 -16
- package/types/middlewares/Environment.d.ts +0 -17
- package/types/middlewares/ErrorHandling.d.ts +0 -16
- package/types/middlewares/Global.d.ts +0 -13
- package/types/middlewares/Http.d.ts +0 -16
- package/types/middlewares/Local.d.ts +0 -20
- package/types/middlewares/View.d.ts +0 -16
- package/types/middlewares/index.d.ts +0 -8
- package/types/mount.d.ts +0 -7
- package/types/package.d.ts +0 -91
- package/types/routing/Router.d.ts +0 -19
- package/types/routing/index.d.ts +0 -2
- package/types/services/AWSRekognitionClient.d.ts +0 -359
- package/types/services/Authentication.d.ts +0 -39
- package/types/services/RedisClient.d.ts +0 -80
- package/types/services/index.d.ts +0 -3
- package/types/utils/Types.d.ts +0 -16
- package/types/utils/index.d.ts +0 -2
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/
|
|
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, 'robin@example.com', 'password', 'Robin'),
|
|
296
296
|
(2, 'taylor@example.com', 'password', 'Taylor'),
|
|
297
|
-
(3, 'vivian@example.com', 'password', 'Vivian')
|
|
298
|
-
(4, 'harry@example.com', 'password', 'Harry'),
|
|
299
|
-
(5, 'eliza@example.com', 'password', 'Eliza'),
|
|
300
|
-
(6, 'nancy@example.com', 'password', 'Nancy'),
|
|
301
|
-
(7, 'melinda@example.com', 'password', 'Melinda'),
|
|
302
|
-
(8, 'harley@example.com', 'password', 'Harley');
|
|
297
|
+
(3, 'vivian@example.com', 'password', 'Vivian');
|
|
303
298
|
|
|
304
299
|
-- Add sample profile record
|
|
305
300
|
INSERT INTO `profile` (`userId`, `address`, `tel`) VALUES
|
|
306
301
|
(1, '777 Brockton Avenue, Abington MA 2351', '202-555-0105'),
|
|
307
302
|
(2, '30 Memorial Drive, Avon MA 2322', ''),
|
|
308
|
-
(3, '250 Hartford Avenue, Bellingham MA 2019', '202-555-0175')
|
|
309
|
-
(4, '700 Oak Street, Brockton MA 2301', '202-555-0167'),
|
|
310
|
-
(5, '66-4 Parkhurst Rd, Chelmsford MA 1824', '202-555-0154'),
|
|
311
|
-
(6, '591 Memorial Dr, Chicopee MA 1020', '202-555-0141'),
|
|
312
|
-
(7, '55 Brooksby Village Way, Danvers MA 1923', '202-555-0196'),
|
|
313
|
-
(8, '137 Teaticket Hwy, East Falmouth MA 2536', '202-555-0167');
|
|
303
|
+
(3, '250 Hartford Avenue, Bellingham MA 2019', '202-555-0175');
|
|
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, '
|
|
324
|
-
(1, '
|
|
325
|
-
(
|
|
326
|
-
(2, 'The Stars Tonight'),
|
|
327
|
-
(2, 'Why She Said Yes');</code></pre>
|
|
328
|
-
|
|
313
|
+
(1, 'When Im Gone'),
|
|
314
|
+
(1, 'Lose Yourself'),
|
|
315
|
+
(2, 'When Im Gone');</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: 'root',
|
|
351
338
|
password: null,
|
|
352
|
-
database: '
|
|
339
|
+
database: 'testdb',
|
|
353
340
|
host: 'localhost',
|
|
354
341
|
dialect: 'mariadb'
|
|
355
342
|
},
|
|
356
343
|
test: {
|
|
357
344
|
username: 'root',
|
|
358
345
|
password: null,
|
|
359
|
-
database: '
|
|
346
|
+
database: 'testdb',
|
|
360
347
|
host: 'localhost',
|
|
361
348
|
dialect: 'mariadb'
|
|
362
349
|
},
|
|
363
350
|
production: {
|
|
364
351
|
username: 'root',
|
|
365
352
|
password: null,
|
|
366
|
-
database: '
|
|
353
|
+
database: 'testdb',
|
|
367
354
|
host: 'localhost',
|
|
368
355
|
dialect: 'mariadb'
|
|
369
356
|
}
|
|
@@ -377,21 +364,21 @@ module.exports = {
|
|
|
377
364
|
development: {
|
|
378
365
|
username: 'root',
|
|
379
366
|
password: null,
|
|
380
|
-
database: '
|
|
367
|
+
database: 'testdb',
|
|
381
368
|
host: 'localhost',
|
|
382
369
|
dialect: 'mariadb'
|
|
383
370
|
},
|
|
384
371
|
test: {
|
|
385
372
|
username: 'root',
|
|
386
373
|
password: null,
|
|
387
|
-
database: '
|
|
374
|
+
database: 'testdb',
|
|
388
375
|
host: 'localhost',
|
|
389
376
|
dialect: 'mariadb'
|
|
390
377
|
},
|
|
391
378
|
production: {
|
|
392
379
|
username: 'root',
|
|
393
380
|
password: null,
|
|
394
|
-
database: '
|
|
381
|
+
database: 'testdb',
|
|
395
382
|
host: 'localhost',
|
|
396
383
|
dialect: 'mariadb'
|
|
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) => {
|
|
914
901
|
const UserModel = require('../models/UserModel');
|
|
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) => {
|
|
933
914
|
const UserModel = require('../models/UserModel');
|
|
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
|
-
|
|
949
|
-
|
|
925
|
+
<pre><code class="js">allow_unauthenticated: ['/api']</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) => Promise<{[key: string]: any}|null>}
|
|
1017
996
|
*/
|
|
1018
997
|
authenticate_user: async (username, password) => {
|
|
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) => Promise<{[key: string]: any}>}
|
|
1034
1007
|
*/
|
|
1035
1008
|
subscribe_user: async (id) => {
|
|
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: ['/api'],
|
|
1047
1017
|
|
|
@@ -1099,13 +1069,7 @@ module.exports = {
|
|
|
1099
1069
|
* @type {(username: string, password: string) => Promise<{[key: string]: any}|null>}
|
|
1100
1070
|
*/
|
|
1101
1071
|
authenticate_user: async (username, password) => {
|
|
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) => Promise<{[key: string]: any}>}
|
|
1117
1081
|
*/
|
|
1118
1082
|
subscribe_user: async (id) => {
|
|
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: ['/api'],
|
|
1130
1091
|
|
|
@@ -1216,38 +1177,32 @@ export default {
|
|
|
1216
1177
|
development: {
|
|
1217
1178
|
username: 'root',
|
|
1218
1179
|
password: null,
|
|
1219
|
-
database: '
|
|
1180
|
+
database: 'testdb',
|
|
1220
1181
|
host: 'localhost',
|
|
1221
|
-
port:
|
|
1182
|
+
port: 3306,
|
|
1222
1183
|
dialect: 'mariadb',
|
|
1223
1184
|
timezone: '+09:00',
|
|
1224
1185
|
logging: false
|
|
1225
|
-
//,timezone: 'Etc/GMT-9'
|
|
1226
|
-
//,dialectOptions: {useUTC: false, timezone: 'Etc/GMT-9'}
|
|
1227
1186
|
},
|
|
1228
1187
|
test: {
|
|
1229
1188
|
username: 'root',
|
|
1230
1189
|
password: null,
|
|
1231
|
-
database: '
|
|
1190
|
+
database: 'testdb',
|
|
1232
1191
|
host: 'localhost',
|
|
1233
|
-
port:
|
|
1192
|
+
port: 3306,
|
|
1234
1193
|
dialect: 'mariadb',
|
|
1235
1194
|
timezone: '+09:00',
|
|
1236
1195
|
logging: false
|
|
1237
|
-
//,timezone: 'Etc/GMT-9'
|
|
1238
|
-
//,dialectOptions: {useUTC: false, timezone: 'Etc/GMT-9'}
|
|
1239
1196
|
},
|
|
1240
1197
|
production: {
|
|
1241
1198
|
username: 'root',
|
|
1242
1199
|
password: null,
|
|
1243
|
-
database: '
|
|
1200
|
+
database: 'testdb',
|
|
1244
1201
|
host: 'localhost',
|
|
1245
|
-
port:
|
|
1202
|
+
port: 3306,
|
|
1246
1203
|
dialect: 'mariadb',
|
|
1247
1204
|
timezone: '+09:00',
|
|
1248
1205
|
logging: false
|
|
1249
|
-
//,timezone: 'Etc/GMT-9'
|
|
1250
|
-
//,dialectOptions: {useUTC: false, timezone: 'Etc/GMT-9'}
|
|
1251
1206
|
}
|
|
1252
1207
|
}</code></pre>
|
|
1253
1208
|
</div>
|
|
@@ -1259,38 +1214,32 @@ module.exports = {
|
|
|
1259
1214
|
development: {
|
|
1260
1215
|
username: 'root',
|
|
1261
1216
|
password: null,
|
|
1262
|
-
database: '
|
|
1217
|
+
database: 'testdb',
|
|
1263
1218
|
host: 'localhost',
|
|
1264
|
-
port:
|
|
1219
|
+
port: 3306,
|
|
1265
1220
|
dialect: 'mariadb',
|
|
1266
1221
|
timezone: '+09:00',
|
|
1267
1222
|
logging: false
|
|
1268
|
-
//,timezone: 'Etc/GMT-9'
|
|
1269
|
-
//,dialectOptions: {useUTC: false, timezone: 'Etc/GMT-9'}
|
|
1270
1223
|
},
|
|
1271
1224
|
test: {
|
|
1272
1225
|
username: 'root',
|
|
1273
1226
|
password: null,
|
|
1274
|
-
database: '
|
|
1227
|
+
database: 'testdb',
|
|
1275
1228
|
host: 'localhost',
|
|
1276
|
-
port:
|
|
1229
|
+
port: 3306,
|
|
1277
1230
|
dialect: 'mariadb',
|
|
1278
1231
|
timezone: '+09:00',
|
|
1279
1232
|
logging: false
|
|
1280
|
-
//,timezone: 'Etc/GMT-9'
|
|
1281
|
-
//,dialectOptions: {useUTC: false, timezone: 'Etc/GMT-9'}
|
|
1282
1233
|
},
|
|
1283
1234
|
production: {
|
|
1284
1235
|
username: 'root',
|
|
1285
1236
|
password: null,
|
|
1286
|
-
database: '
|
|
1237
|
+
database: 'testdb',
|
|
1287
1238
|
host: 'localhost',
|
|
1288
|
-
port:
|
|
1239
|
+
port: 3306,
|
|
1289
1240
|
dialect: 'mariadb',
|
|
1290
1241
|
timezone: '+09:00',
|
|
1291
1242
|
logging: false
|
|
1292
|
-
//,timezone: 'Etc/GMT-9'
|
|
1293
|
-
//,dialectOptions: {useUTC: false, timezone: 'Etc/GMT-9'}
|
|
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>
|
|
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
|
|
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
|
|
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"
|
|
1949
|
-
|
|
1901
|
+
<pre class="mb-0"><code class="js">// If the value is an array.
|
|
1902
|
+
let value = [5, 6];
|
|
1903
|
+
{{empty value}} => false
|
|
1950
1904
|
|
|
1951
|
-
{{#if (empty
|
|
1905
|
+
{{#if (empty value)}}
|
|
1952
1906
|
Hello
|
|
1953
|
-
{{/if}}
|
|
1907
|
+
{{/if}}
|
|
1908
|
+
|
|
1909
|
+
// If the value is a string.
|
|
1910
|
+
let value = 'Hello';
|
|
1911
|
+
{{empty value}} => false
|
|
1912
|
+
|
|
1913
|
+
let value = '';
|
|
1914
|
+
{{empty value}} => true
|
|
1915
|
+
|
|
1916
|
+
let value = ' ';
|
|
1917
|
+
{{empty value}} => 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}} => true
|
|
1939
|
+
|
|
1940
|
+
{{#if (not_empty value)}}
|
|
1941
|
+
Hello
|
|
1942
|
+
{{/if}}
|
|
1943
|
+
|
|
1944
|
+
// If the value is a string.
|
|
1945
|
+
let value = 'Hello';
|
|
1946
|
+
{{not_empty value}} => true
|
|
1947
|
+
|
|
1948
|
+
let value = '';
|
|
1949
|
+
{{not_empty value}} => false
|
|
1950
|
+
|
|
1951
|
+
let value = ' ';
|
|
1952
|
+
{{not_empty value}} => false</code></pre>
|
|
1954
1953
|
</td>
|
|
1955
1954
|
</tr>
|
|
1956
1955
|
<tr>
|
|
@@ -2196,9 +2195,8 @@ let value = '2'
|
|
|
2196
2195
|
<!--begin::Accessing Models-->
|
|
2197
2196
|
<h2 id="model-accessing">Accessing Models</h2>
|
|
2198
2197
|
<p>
|
|
2199
|
-
|
|
2200
|
-
|
|
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 = '2'
|
|
|
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
|
|
2212
|
+
<pre><code class="js">import BookModel from '../models/BookModel';
|
|
2215
2213
|
|
|
2216
|
-
// INSERT INTO
|
|
2217
|
-
await
|
|
2214
|
+
// INSERT INTO book (title) VALUES ('When Im Gone')
|
|
2215
|
+
await BookModel.create({title: 'When Im Gone'});
|
|
2218
2216
|
|
|
2219
|
-
// SELECT * FROM
|
|
2220
|
-
await
|
|
2217
|
+
// SELECT * FROM book
|
|
2218
|
+
await BookModel.findAll();
|
|
2221
2219
|
|
|
2222
|
-
// UPDATE
|
|
2223
|
-
await
|
|
2220
|
+
// UPDATE book SET title = 'When Im Gone' WHERE id= 1
|
|
2221
|
+
await BookModel.update({title: 'When Im Gone'}, {where: {id: 1}});
|
|
2224
2222
|
|
|
2225
|
-
// DELETE FROM
|
|
2226
|
-
await
|
|
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
|
|
2227
|
+
<pre><code class="js">const BookModel = require('../models/BookModel');
|
|
2230
2228
|
|
|
2231
|
-
// INSERT INTO
|
|
2232
|
-
await
|
|
2229
|
+
// INSERT INTO book (title) VALUES ('When Im Gone')
|
|
2230
|
+
await BookModel.create({title: 'When Im Gone'});
|
|
2233
2231
|
|
|
2234
|
-
// SELECT * FROM
|
|
2235
|
-
await
|
|
2232
|
+
// SELECT * FROM book
|
|
2233
|
+
await BookModel.findAll();
|
|
2236
2234
|
|
|
2237
|
-
// UPDATE
|
|
2238
|
-
await
|
|
2235
|
+
// UPDATE book SET title = 'When Im Gone' WHERE id= 1
|
|
2236
|
+
await BookModel.update({title: 'When Im Gone'}, {where: {id: 1}});
|
|
2239
2237
|
|
|
2240
|
-
// DELETE FROM
|
|
2241
|
-
await
|
|
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
|
|
2522
|
+
<pre><code class="js">import BookModel from '../models/BookModel';
|
|
2525
2523
|
|
|
2526
|
-
// SELECT * FROM
|
|
2527
|
-
|
|
2524
|
+
// SELECT * FROM book WHERE title = 'When Im Gone' AND genre = 'Nonfiction';
|
|
2525
|
+
BookModel.findOne({
|
|
2528
2526
|
where: {
|
|
2529
|
-
[
|
|
2530
|
-
{
|
|
2531
|
-
{
|
|
2527
|
+
[BookModel.Op.and]: [
|
|
2528
|
+
{title: 'When Im Gone'},
|
|
2529
|
+
{genre: 'Nonfiction'}
|
|
2532
2530
|
]
|
|
2533
2531
|
}
|
|
2534
2532
|
});
|
|
2535
2533
|
|
|
2536
|
-
// SELECT * FROM
|
|
2537
|
-
|
|
2534
|
+
// SELECT * FROM book WHERE title = 'When Im Gone' OR title = 'Lose Yourself';
|
|
2535
|
+
BookModel.findAll({
|
|
2538
2536
|
where: {
|
|
2539
|
-
[
|
|
2540
|
-
{
|
|
2541
|
-
{
|
|
2537
|
+
[BookModel.Op.or]: [
|
|
2538
|
+
{title: 'When Im Gone'},
|
|
2539
|
+
{title: 'Lose Yourself'}
|
|
2542
2540
|
]
|
|
2543
2541
|
}
|
|
2544
2542
|
});
|
|
2545
2543
|
|
|
2546
|
-
// DELETE FROM user WHERE name = '
|
|
2547
|
-
|
|
2544
|
+
// DELETE FROM user WHERE name = 'When Im Gone' OR name = 'Lose Yourself';
|
|
2545
|
+
BookModel.destroy({
|
|
2548
2546
|
where: {
|
|
2549
|
-
|
|
2550
|
-
[
|
|
2547
|
+
title: {
|
|
2548
|
+
[BookModel.Op.or]: ['When Im Gone', 'Lose Yourself']
|
|
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
|
|
2554
|
+
<pre><code class="js">const BookModel = require('../models/BookModel');
|
|
2557
2555
|
|
|
2558
|
-
// SELECT * FROM
|
|
2559
|
-
|
|
2556
|
+
// SELECT * FROM book WHERE title = 'When Im Gone' AND genre = 'Nonfiction';
|
|
2557
|
+
BookModel.findOne({
|
|
2560
2558
|
where: {
|
|
2561
|
-
[
|
|
2562
|
-
{
|
|
2563
|
-
{
|
|
2559
|
+
[BookModel.Op.and]: [
|
|
2560
|
+
{title: 'When Im Gone'},
|
|
2561
|
+
{genre: 'Nonfiction'}
|
|
2564
2562
|
]
|
|
2565
2563
|
}
|
|
2566
2564
|
});
|
|
2567
2565
|
|
|
2568
|
-
// SELECT * FROM
|
|
2569
|
-
|
|
2566
|
+
// SELECT * FROM book WHERE title = 'When Im Gone' OR title = 'Lose Yourself';
|
|
2567
|
+
BookModel.findAll({
|
|
2570
2568
|
where: {
|
|
2571
|
-
[
|
|
2572
|
-
{
|
|
2573
|
-
{
|
|
2569
|
+
[BookModel.Op.or]: [
|
|
2570
|
+
{title: 'When Im Gone'},
|
|
2571
|
+
{title: 'Lose Yourself'}
|
|
2574
2572
|
]
|
|
2575
2573
|
}
|
|
2576
2574
|
});
|
|
2577
2575
|
|
|
2578
|
-
// DELETE FROM user WHERE name = '
|
|
2579
|
-
|
|
2576
|
+
// DELETE FROM user WHERE name = 'When Im Gone' OR name = 'Lose Yourself';
|
|
2577
|
+
BookModel.destroy({
|
|
2580
2578
|
where: {
|
|
2581
|
-
|
|
2582
|
-
[
|
|
2579
|
+
title: {
|
|
2580
|
+
[BookModel.Op.or]: ['When Im Gone', 'Lose Yourself']
|
|
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
|
-
// {
|
|
2623
|
-
// {
|
|
2624
|
-
// {
|
|
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
|
-
// {
|
|
2641
|
-
// {
|
|
2642
|
-
// {
|
|
2638
|
+
// {title: 'MOBY DICK'},
|
|
2639
|
+
// {title: 'GET RICH REALLY FAST'},
|
|
2640
|
+
// {title: 'FINDING INNER PEACE'}
|
|
2643
2641
|
// ]
|
|
2644
2642
|
console.log('books=', books);</code></pre>
|
|
2645
2643
|
</div>
|
|
@@ -2691,9 +2689,8 @@ const books = await BookModel.findAll({
|
|
|
2691
2689
|
});
|
|
2692
2690
|
|
|
2693
2691
|
// Output: books= [
|
|
2694
|
-
// {
|
|
2695
|
-
// {
|
|
2696
|
-
// { id: 3, title: 'Finding Inner Peace', count: 0 }
|
|
2692
|
+
// {id: 1, title: 'When Im Gone', count: 2},
|
|
2693
|
+
// {id: 2, title: 'Lose Yourself', count: 1}
|
|
2697
2694
|
// ]
|
|
2698
2695
|
console.log('books=', books);</code></pre>
|
|
2699
2696
|
</div>
|
|
@@ -2716,9 +2713,8 @@ const books = await BookModel.findAll({
|
|
|
2716
2713
|
});
|
|
2717
2714
|
|
|
2718
2715
|
// Output: books= [
|
|
2719
|
-
// {
|
|
2720
|
-
// {
|
|
2721
|
-
// { id: 3, title: 'Finding Inner Peace', count: 0 }
|
|
2716
|
+
// {id: 1, title: 'When Im Gone', count: 2},
|
|
2717
|
+
// {id: 2, title: 'Lose Yourself', count: 1}
|
|
2722
2718
|
// ]
|
|
2723
2719
|
console.log('books=', books);</code></pre>
|
|
2724
2720
|
</div>
|
|
@@ -2734,7 +2730,7 @@ console.log('books=', 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 {
|
|
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= [
|
|
2760
|
+
// Output: books= [{title: 'When Im Gone'}]
|
|
2765
2761
|
console.log('books=', books);</code></pre>
|
|
2766
2762
|
</div>
|
|
2767
2763
|
<div class="tab-pane fade" id="model-where-cjs">
|
|
@@ -2777,13 +2773,33 @@ const books = await BookModel.findAll({
|
|
|
2777
2773
|
raw: true
|
|
2778
2774
|
});
|
|
2779
2775
|
|
|
2780
|
-
// Output: books= [
|
|
2776
|
+
// Output: books= [{title: 'When Im Gone'}]
|
|
2781
2777
|
console.log('books=', books);</code></pre>
|
|
2782
2778
|
</div>
|
|
2783
2779
|
</div>
|
|
2784
2780
|
</div>
|
|
2785
2781
|
</td>
|
|
2786
2782
|
</tr>
|
|
2783
|
+
<tr>
|
|
2784
|
+
<td class="min-w-300px text-primary fw-bolder">public static readonly QueryTypes: {[key: string]: string}</td>
|
|
2785
|
+
<td class="min-w-200px w-100">
|
|
2786
|
+
An enum of query types used by sequelize.query<br>
|
|
2787
|
+
See <a href="https://sequelize.org/master/variable/index.html#static-variable-QueryTypes" target="_blank">here</a> for details.
|
|
2788
|
+
</td>
|
|
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('../models/BookModel');
|
|
2797
|
+
BookModel.Transaction.ISOLATION_LEVELS.READ_UNCOMMITTED // "READ UNCOMMITTED"
|
|
2798
|
+
BookModel.Transaction.ISOLATION_LEVELS.READ_COMMITTED // "READ COMMITTED"
|
|
2799
|
+
BookModel.Transaction.ISOLATION_LEVELS.REPEATABLE_READ // "REPEATABLE READ"
|
|
2800
|
+
BookModel.Transaction.ISOLATION_LEVELS.SERIALIZABLE // "SERIALIZABLE"</code></pre>
|
|
2801
|
+
</td>
|
|
2802
|
+
</tr>
|
|
2787
2803
|
</tbody>
|
|
2788
2804
|
</table>
|
|
2789
2805
|
|
|
@@ -2852,13 +2868,17 @@ module.exports = class extends Model {
|
|
|
2852
2868
|
</td>
|
|
2853
2869
|
</tr>
|
|
2854
2870
|
<tr>
|
|
2855
|
-
<td class="min-w-300px text-primary fw-bolder">public static async begin(): Promise<<a href="https://sequelize.org/master/class/lib/transaction.js~Transaction.html" target="_blank">sequelize.Transaction</a>></td>
|
|
2871
|
+
<td class="min-w-300px text-primary fw-bolder">public static async begin(opts?: sequelize.TransactionOptions): Promise<<a href="https://sequelize.org/master/class/lib/transaction.js~Transaction.html" target="_blank">sequelize.Transaction</a>></td>
|
|
2856
2872
|
<td class="min-w-200px w-100">
|
|
2857
2873
|
<p>
|
|
2858
2874
|
Starts a transaction and returns a transaction object to identify the running transaction.<br>
|
|
2859
2875
|
This is an alias for the <code>"sequelize.Sequelize.transaction()"</code> method.<br>
|
|
2860
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.
|
|
2861
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>
|
|
2862
2882
|
<p class="fw-bolder mb-0">Return:</p>
|
|
2863
2883
|
<p>{Promise<sequelize.Transaction>} Returns a transaction object to identify the transaction being executed.</p>
|
|
2864
2884
|
<p class="fw-bolder mb-0">Example:</p>
|
|
@@ -2873,49 +2893,74 @@ module.exports = class extends Model {
|
|
|
2873
2893
|
</ul>
|
|
2874
2894
|
<div class="tab-content">
|
|
2875
2895
|
<div class="tab-pane fade show active" id="model-begin-esm">
|
|
2876
|
-
<pre><code class="js">import
|
|
2877
|
-
|
|
2896
|
+
<pre><code class="js">import BookModel from '../models/BookModel';
|
|
2897
|
+
|
|
2898
|
+
// Simple transaction usage example.
|
|
2878
2899
|
let transaction;
|
|
2879
2900
|
try {
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
// UPDATE `user` SET `name`=? WHERE `id` = ?
|
|
2888
|
-
await user.save({transaction});
|
|
2901
|
+
transaction = await BookModel.begin();
|
|
2902
|
+
const book = await BookModel.create({title: 'When Im Gone'}, {transaction});
|
|
2903
|
+
await transaction.commit();
|
|
2904
|
+
} catch(error) {
|
|
2905
|
+
if (transaction)
|
|
2906
|
+
await transaction.rollback();
|
|
2907
|
+
}
|
|
2889
2908
|
|
|
2890
|
-
|
|
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 = 'When Im Gone';
|
|
2918
|
+
await book.save({transaction});
|
|
2891
2919
|
await transaction.commit();
|
|
2892
|
-
|
|
2893
|
-
//
|
|
2894
|
-
|
|
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();
|
|
2895
2928
|
}</code></pre>
|
|
2896
2929
|
</div>
|
|
2897
2930
|
<div class="tab-pane fade" id="model-begin-cjs">
|
|
2898
|
-
<pre><code class="js">const
|
|
2931
|
+
<pre><code class="js">const BookModel = require('../models/BookModel');
|
|
2899
2932
|
|
|
2933
|
+
// Simple transaction usage example.
|
|
2900
2934
|
let transaction;
|
|
2901
2935
|
try {
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
// SELECT `id`, `email`, `password`, `name`, `created`, `modified` FROM `user` AS `user` WHERE `user`.`id` = 1;
|
|
2906
|
-
const user = await UserModel.findOne({where: {id: 1}}, {transaction});
|
|
2907
|
-
user.name = 'Jane';
|
|
2908
|
-
|
|
2909
|
-
// UPDATE `user` SET `name`=? WHERE `id` = ?
|
|
2910
|
-
await user.save({transaction});
|
|
2911
|
-
|
|
2912
|
-
// COMMIT;
|
|
2936
|
+
transaction = await BookModel.begin();
|
|
2937
|
+
const book = await BookModel.create({title: 'When Im Gone'}, {transaction});
|
|
2913
2938
|
await transaction.commit();
|
|
2914
|
-
} catch(
|
|
2915
|
-
|
|
2916
|
-
|
|
2939
|
+
} catch(error) {
|
|
2940
|
+
if (transaction)
|
|
2941
|
+
await transaction.rollback();
|
|
2917
2942
|
}
|
|
2918
|
-
|
|
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 = 'When Im Gone';
|
|
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>
|
|
2919
2964
|
</div>
|
|
2920
2965
|
</div>
|
|
2921
2966
|
</div>
|
|
@@ -2947,16 +2992,16 @@ try {
|
|
|
2947
2992
|
</ul>
|
|
2948
2993
|
<div class="tab-content">
|
|
2949
2994
|
<div class="tab-pane fade show active" id="model-create-esm">
|
|
2950
|
-
<pre><code class="js">import
|
|
2995
|
+
<pre><code class="js">import BookModel from '../models/BookModel';
|
|
2951
2996
|
|
|
2952
|
-
// INSERT INTO `
|
|
2953
|
-
await
|
|
2997
|
+
// INSERT INTO `book` (`id`,`title`) VALUES (DEFAULT,'When Im Gone');
|
|
2998
|
+
await BookModel.create({title: 'When Im Gone'});</code></pre>
|
|
2954
2999
|
</div>
|
|
2955
3000
|
<div class="tab-pane fade" id="model-create-cjs">
|
|
2956
|
-
<pre><code class="js">const
|
|
3001
|
+
<pre><code class="js">const BookModel = require('../models/BookModel');
|
|
2957
3002
|
|
|
2958
|
-
// INSERT INTO `
|
|
2959
|
-
await
|
|
3003
|
+
// INSERT INTO `book` (`id`,`title`) VALUES (DEFAULT,'When Im Gone');
|
|
3004
|
+
await BookModel.create({title: 'When Im Gone'});</code></pre>
|
|
2960
3005
|
</div>
|
|
2961
3006
|
</div>
|
|
2962
3007
|
</div>
|
|
@@ -2987,26 +3032,26 @@ await UserModel.create({email: 'ellen@example.com', password: 'pa
|
|
|
2987
3032
|
</ul>
|
|
2988
3033
|
<div class="tab-content">
|
|
2989
3034
|
<div class="tab-pane fade show active" id="model-save-esm">
|
|
2990
|
-
<pre><code class="js">import
|
|
3035
|
+
<pre><code class="js">import BookModel from '../models/BookModel';
|
|
2991
3036
|
|
|
2992
|
-
// INSERT INTO `
|
|
2993
|
-
const
|
|
2994
|
-
await
|
|
3037
|
+
// INSERT INTO `book` (`id`,`title`) VALUES (DEFAULT,'When Im Gone');
|
|
3038
|
+
const book = BookModel.build({title: 'When Im Gone'});
|
|
3039
|
+
await book.save();
|
|
2995
3040
|
|
|
2996
|
-
// UPDATE `
|
|
2997
|
-
|
|
2998
|
-
await
|
|
3041
|
+
// UPDATE `book` SET `title`='Lose Yourself' WHERE `id` = 1;
|
|
3042
|
+
book.title = 'Lose Yourself';
|
|
3043
|
+
await book.save();</code></pre>
|
|
2999
3044
|
</div>
|
|
3000
3045
|
<div class="tab-pane fade" id="model-save-cjs">
|
|
3001
|
-
<pre><code class="js">const
|
|
3046
|
+
<pre><code class="js">const BookModel = require('../models/BookModel');
|
|
3002
3047
|
|
|
3003
|
-
// INSERT INTO `
|
|
3004
|
-
const
|
|
3005
|
-
await
|
|
3048
|
+
// INSERT INTO `book` (`id`,`title`) VALUES (DEFAULT,'When Im Gone');
|
|
3049
|
+
const book = BookModel.build({title: 'When Im Gone'});
|
|
3050
|
+
await book.save();
|
|
3006
3051
|
|
|
3007
|
-
// UPDATE `
|
|
3008
|
-
|
|
3009
|
-
await
|
|
3052
|
+
// UPDATE `book` SET `title`='Lose Yourself' WHERE `id` = 1;
|
|
3053
|
+
book.title = 'Lose Yourself';
|
|
3054
|
+
await book.save();</code></pre>
|
|
3010
3055
|
</div>
|
|
3011
3056
|
</div>
|
|
3012
3057
|
</div>
|
|
@@ -3038,16 +3083,16 @@ await user.save();</code></pre>
|
|
|
3038
3083
|
</ul>
|
|
3039
3084
|
<div class="tab-content">
|
|
3040
3085
|
<div class="tab-pane fade show active" id="model-find-one-esm">
|
|
3041
|
-
<pre><code class="js">import
|
|
3086
|
+
<pre><code class="js">import BookModel from '../models/BookModel';
|
|
3042
3087
|
|
|
3043
|
-
// SELECT `id`, `
|
|
3044
|
-
await
|
|
3088
|
+
// SELECT `id`, `title`, `created`, `modified` FROM `book` AS `book` LIMIT 1;
|
|
3089
|
+
await BookModel.findOne();</code></pre>
|
|
3045
3090
|
</div>
|
|
3046
3091
|
<div class="tab-pane fade" id="model-find-one-cjs">
|
|
3047
|
-
<pre><code class="js">const
|
|
3092
|
+
<pre><code class="js">const BookModel = require('../models/BookModel');
|
|
3048
3093
|
|
|
3049
|
-
// SELECT `id`, `
|
|
3050
|
-
await
|
|
3094
|
+
// SELECT `id`, `title`, `created`, `modified` FROM `book` AS `book` LIMIT 1;
|
|
3095
|
+
await BookModel.findOne();</code></pre>
|
|
3051
3096
|
</div>
|
|
3052
3097
|
</div>
|
|
3053
3098
|
</div>
|
|
@@ -3078,25 +3123,25 @@ await UserModel.findOne();</code></pre>
|
|
|
3078
3123
|
</ul>
|
|
3079
3124
|
<div class="tab-content">
|
|
3080
3125
|
<div class="tab-pane fade show active" id="model-find-all-esm">
|
|
3081
|
-
<pre><code class="js">import
|
|
3126
|
+
<pre><code class="js">import BookModel from '../models/BookModel';
|
|
3082
3127
|
|
|
3083
|
-
// SELECT `id`, `
|
|
3084
|
-
|
|
3128
|
+
// SELECT `id`, `title`, `created`, `modified` FROM `book` AS `book` WHERE `book`.`title` LIKE 'When Im Gone%';
|
|
3129
|
+
await BookModel.findAll({
|
|
3085
3130
|
where: {
|
|
3086
|
-
|
|
3087
|
-
[
|
|
3131
|
+
title: {
|
|
3132
|
+
[BookModel.Op.like]: 'When Im Gone%'
|
|
3088
3133
|
}
|
|
3089
3134
|
}
|
|
3090
3135
|
});</code></pre>
|
|
3091
3136
|
</div>
|
|
3092
3137
|
<div class="tab-pane fade" id="model-find-all-cjs">
|
|
3093
|
-
<pre><code class="js">const
|
|
3138
|
+
<pre><code class="js">const BookModel = require('../models/BookModel');
|
|
3094
3139
|
|
|
3095
|
-
// SELECT `id`, `
|
|
3096
|
-
|
|
3140
|
+
// SELECT `id`, `title`, `created`, `modified` FROM `book` AS `book` WHERE `book`.`title` LIKE 'When Im Gone%';
|
|
3141
|
+
await BookModel.findAll({
|
|
3097
3142
|
where: {
|
|
3098
|
-
|
|
3099
|
-
[
|
|
3143
|
+
title: {
|
|
3144
|
+
[BookModel.Op.like]: 'When Im Gone%'
|
|
3100
3145
|
}
|
|
3101
3146
|
}
|
|
3102
3147
|
});</code></pre>
|
|
@@ -3130,16 +3175,16 @@ const users = await UserModel.findAll({
|
|
|
3130
3175
|
</ul>
|
|
3131
3176
|
<div class="tab-content">
|
|
3132
3177
|
<div class="tab-pane fade show active" id="model-count-esm">
|
|
3133
|
-
<pre><code class="js">import
|
|
3178
|
+
<pre><code class="js">import BookModel from '../models/BookModel';
|
|
3134
3179
|
|
|
3135
|
-
// SELECT count(*) AS `count` FROM `
|
|
3136
|
-
await
|
|
3180
|
+
// SELECT count(*) AS `count` FROM `book` AS `book`;
|
|
3181
|
+
await BookModel.count();</code></pre>
|
|
3137
3182
|
</div>
|
|
3138
3183
|
<div class="tab-pane fade" id="model-count-cjs">
|
|
3139
|
-
<pre><code class="js">const
|
|
3184
|
+
<pre><code class="js">const BookModel = require('../models/BookModel');
|
|
3140
3185
|
|
|
3141
|
-
// SELECT count(*) AS `count` FROM `
|
|
3142
|
-
await
|
|
3186
|
+
// SELECT count(*) AS `count` FROM `book` AS `book`;
|
|
3187
|
+
await BookModel.count();</code></pre>
|
|
3143
3188
|
</div>
|
|
3144
3189
|
</div>
|
|
3145
3190
|
</div>
|
|
@@ -3171,22 +3216,16 @@ await UserModel.count();</code></pre>
|
|
|
3171
3216
|
</ul>
|
|
3172
3217
|
<div class="tab-content">
|
|
3173
3218
|
<div class="tab-pane fade show active" id="model-update-esm">
|
|
3174
|
-
<pre><code class="js">import
|
|
3219
|
+
<pre><code class="js">import BookModel from '../models/BookModel';
|
|
3175
3220
|
|
|
3176
|
-
// UPDATE `
|
|
3177
|
-
await
|
|
3178
|
-
{name: 'Jane'},
|
|
3179
|
-
{where: {id: 1}}
|
|
3180
|
-
);</code></pre>
|
|
3221
|
+
// UPDATE `book` SET `title`='Lose Yourself' WHERE `id` = 1;
|
|
3222
|
+
await BookModel.update({title: 'Lose Yourself'}, {where: {id: 1}});</code></pre>
|
|
3181
3223
|
</div>
|
|
3182
3224
|
<div class="tab-pane fade" id="model-update-cjs">
|
|
3183
|
-
<pre><code class="js">const
|
|
3225
|
+
<pre><code class="js">const BookModel = require('../models/BookModel');
|
|
3184
3226
|
|
|
3185
|
-
// UPDATE `
|
|
3186
|
-
await
|
|
3187
|
-
{name: 'Jane'},
|
|
3188
|
-
{where: {id: 1}}
|
|
3189
|
-
);</code></pre>
|
|
3227
|
+
// UPDATE `book` SET `title`='Lose Yourself' WHERE `id` = 1;
|
|
3228
|
+
await BookModel.update({title: 'Lose Yourself'}, {where: {id: 1}});</code></pre>
|
|
3190
3229
|
</div>
|
|
3191
3230
|
</div>
|
|
3192
3231
|
</div>
|
|
@@ -3221,26 +3260,16 @@ await UserModel.update(
|
|
|
3221
3260
|
</ul>
|
|
3222
3261
|
<div class="tab-content">
|
|
3223
3262
|
<div class="tab-pane fade show active" id="model-upsert-esm">
|
|
3224
|
-
<pre><code class="js">import
|
|
3263
|
+
<pre><code class="js">import BookModel from '../models/BookModel';
|
|
3225
3264
|
|
|
3226
|
-
// INSERT INTO `
|
|
3227
|
-
|
|
3228
|
-
await UserModel.upsert({
|
|
3229
|
-
email: 'robin@example.com',
|
|
3230
|
-
password: 'password',
|
|
3231
|
-
name: 'Robin'
|
|
3232
|
-
});</code></pre>
|
|
3265
|
+
// INSERT INTO `book` (`title`) VALUES (?) ON DUPLICATE KEY UPDATE `title`=VALUES(`title`);
|
|
3266
|
+
await BookModel.upsert({title: 'Lose Yourself'});</code></pre>
|
|
3233
3267
|
</div>
|
|
3234
3268
|
<div class="tab-pane fade" id="model-upsert-cjs">
|
|
3235
|
-
<pre><code class="js">const
|
|
3269
|
+
<pre><code class="js">const BookModel = require('../models/BookModel');
|
|
3236
3270
|
|
|
3237
|
-
// INSERT INTO `
|
|
3238
|
-
|
|
3239
|
-
await UserModel.upsert({
|
|
3240
|
-
email: 'robin@example.com',
|
|
3241
|
-
password: 'password',
|
|
3242
|
-
name: 'Robin'
|
|
3243
|
-
});</code></pre>
|
|
3271
|
+
// INSERT INTO `book` (`title`) VALUES (?) ON DUPLICATE KEY UPDATE `title`=VALUES(`title`);
|
|
3272
|
+
await BookModel.upsert({title: 'Lose Yourself'});</code></pre>
|
|
3244
3273
|
</div>
|
|
3245
3274
|
</div>
|
|
3246
3275
|
</div>
|
|
@@ -3271,16 +3300,16 @@ await UserModel.upsert({
|
|
|
3271
3300
|
</ul>
|
|
3272
3301
|
<div class="tab-content">
|
|
3273
3302
|
<div class="tab-pane fade show active" id="model-destroy-esm">
|
|
3274
|
-
<pre><code class="js">import
|
|
3303
|
+
<pre><code class="js">import BookModel from '../models/BookModel';
|
|
3275
3304
|
|
|
3276
3305
|
// DELETE FROM `user` WHERE `id` = 1;
|
|
3277
|
-
await
|
|
3306
|
+
await BookModel.destroy({where: {id :1}});</code></pre>
|
|
3278
3307
|
</div>
|
|
3279
3308
|
<div class="tab-pane fade" id="model-destroy-cjs">
|
|
3280
|
-
<pre><code class="js">const
|
|
3309
|
+
<pre><code class="js">const BookModel = require('../models/BookModel');
|
|
3281
3310
|
|
|
3282
3311
|
// DELETE FROM `user` WHERE `id` = 1;
|
|
3283
|
-
await
|
|
3312
|
+
await BookModel.destroy({where: {id :1}});</code></pre>
|
|
3284
3313
|
</div>
|
|
3285
3314
|
</div>
|
|
3286
3315
|
</div>
|
|
@@ -3856,11 +3885,11 @@ module.exports = class extends Model {
|
|
|
3856
3885
|
// "books": [
|
|
3857
3886
|
// {
|
|
3858
3887
|
// "userId": 1,
|
|
3859
|
-
// "title": "
|
|
3888
|
+
// "title": "When Im Gone"
|
|
3860
3889
|
// },
|
|
3861
3890
|
// {
|
|
3862
3891
|
// "userId": 1,
|
|
3863
|
-
// "title": "
|
|
3892
|
+
// "title": "Lose Yourself"
|
|
3864
3893
|
// }
|
|
3865
3894
|
// ]
|
|
3866
3895
|
// }
|
|
@@ -3893,11 +3922,11 @@ await UserModel.findAll({
|
|
|
3893
3922
|
// "books": [
|
|
3894
3923
|
// {
|
|
3895
3924
|
// "userId": 1,
|
|
3896
|
-
// "title": "
|
|
3925
|
+
// "title": "When Im Gone"
|
|
3897
3926
|
// },
|
|
3898
3927
|
// {
|
|
3899
3928
|
// "userId": 1,
|
|
3900
|
-
// "title": "
|
|
3929
|
+
// "title": "Lose Yourself"
|
|
3901
3930
|
// }
|
|
3902
3931
|
// ]
|
|
3903
3932
|
// }
|
|
@@ -3914,6 +3943,27 @@ await UserModel.findAll({
|
|
|
3914
3943
|
</div>
|
|
3915
3944
|
</td>
|
|
3916
3945
|
</tr>
|
|
3946
|
+
<tr>
|
|
3947
|
+
<td class="min-w-300px text-primary fw-bolder">public static async query(sql: string, opts: object): Promise<any></td>
|
|
3948
|
+
<td class="min-w-200px w-100">
|
|
3949
|
+
<p>Raw Queries.<br>As there are often use cases in which it is just easier to execute raw / already prepared SQL queries, you can use the Model.query method.</p>
|
|
3950
|
+
<p class="fw-bolder mb-0">Params:</p>
|
|
3951
|
+
<ul>
|
|
3952
|
+
<li>{string} sql SQL string.</li>
|
|
3953
|
+
<li>{object} opts Query options.</li>
|
|
3954
|
+
</ul>
|
|
3955
|
+
<p class="fw-bolder mb-0">Return:</p>
|
|
3956
|
+
<p>{Promise<any>} By default, the function will return two arguments: an array of results, and a metadata object, containing number of affected rows etc. If you are running a type of query where you don't need the metadata, for example a SELECT query, you can pass in a query type to make sequelize format the results:</p>
|
|
3957
|
+
<p class="fw-bolder mb-0">Example:</p>
|
|
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).
|
|
3959
|
+
// Note that since this is a raw query, the metadata are dialect specific.
|
|
3960
|
+
const [results, metadata] = await BookModel.query("UPDATE book SET title = 'Lose Yourself' WHERE id = 1");
|
|
3961
|
+
|
|
3962
|
+
// In cases where you don'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:
|
|
3963
|
+
// We didn't need to destructure the result here - the results were returned directly
|
|
3964
|
+
await BookModel.query("SELECT * FROM book", {type: BookModel.QueryTypes.SELECT});</code></pre>
|
|
3965
|
+
</td>
|
|
3966
|
+
</tr>
|
|
3917
3967
|
</tbody>
|
|
3918
3968
|
</table>
|
|
3919
3969
|
<!--end::Class Model-->
|
|
@@ -4406,11 +4456,11 @@ const client = new sweet.services.AWSRekognitionClient({
|
|
|
4406
4456
|
try {
|
|
4407
4457
|
// Creates a collection.
|
|
4408
4458
|
await client.createCollection('MyCollection');
|
|
4409
|
-
} catch
|
|
4459
|
+
} catch(err) {
|
|
4410
4460
|
// You can get the resulting HTTP status code from the exception.
|
|
4411
|
-
console.log(`name: ${
|
|
4412
|
-
console.log(`statusCode: ${
|
|
4413
|
-
console.log(`message: ${
|
|
4461
|
+
console.log(`name: ${err.name}`);
|
|
4462
|
+
console.log(`statusCode: ${err.statusCode}`);
|
|
4463
|
+
console.log(`message: ${err.message}`);
|
|
4414
4464
|
}</code></pre>
|
|
4415
4465
|
</div>
|
|
4416
4466
|
<div class="tab-pane fade" id="rekog-method-create-collection-cjs">
|
|
@@ -4425,11 +4475,11 @@ const client = new AWSRekognitionClient({
|
|
|
4425
4475
|
try {
|
|
4426
4476
|
// Creates a collection.
|
|
4427
4477
|
await client.createCollection('MyCollection');
|
|
4428
|
-
} catch
|
|
4478
|
+
} catch(err) {
|
|
4429
4479
|
// You can get the resulting HTTP status code from the exception.
|
|
4430
|
-
console.log(`name: ${
|
|
4431
|
-
console.log(`statusCode: ${
|
|
4432
|
-
console.log(`message: ${
|
|
4480
|
+
console.log(`name: ${err.name}`);
|
|
4481
|
+
console.log(`statusCode: ${err.statusCode}`);
|
|
4482
|
+
console.log(`message: ${err.message}`);
|
|
4433
4483
|
}</code></pre>
|
|
4434
4484
|
</div>
|
|
4435
4485
|
</div>
|
|
@@ -4605,11 +4655,11 @@ const faceId = await client.indexFace('MyCollection', fs.readFileSync(
|
|
|
4605
4655
|
// message: No face was found in the image
|
|
4606
4656
|
try {
|
|
4607
4657
|
await client.indexFace('MyCollection', 'img.jpg');
|
|
4608
|
-
} catch
|
|
4658
|
+
} catch(err) {
|
|
4609
4659
|
// You can get the resulting HTTP status code from the exception.
|
|
4610
|
-
console.log(`name: ${
|
|
4611
|
-
console.log(`statusCode: ${
|
|
4612
|
-
console.log(`message: ${
|
|
4660
|
+
console.log(`name: ${err.name}`);
|
|
4661
|
+
console.log(`statusCode: ${err.statusCode}`);
|
|
4662
|
+
console.log(`message: ${err.message}`);
|
|
4613
4663
|
}
|
|
4614
4664
|
|
|
4615
4665
|
// If multiple faces are found in the image, throw an error.
|
|
@@ -4618,11 +4668,11 @@ try {
|
|
|
4618
4668
|
// message: Multiple faces found in the image
|
|
4619
4669
|
try {
|
|
4620
4670
|
await client.indexFace('MyCollection', 'img.jpg');
|
|
4621
|
-
} catch
|
|
4671
|
+
} catch(err) {
|
|
4622
4672
|
// You can get the resulting HTTP status code from the exception.
|
|
4623
|
-
console.log(`name: ${
|
|
4624
|
-
console.log(`statusCode: ${
|
|
4625
|
-
console.log(`message: ${
|
|
4673
|
+
console.log(`name: ${err.name}`);
|
|
4674
|
+
console.log(`statusCode: ${err.statusCode}`);
|
|
4675
|
+
console.log(`message: ${err.message}`);
|
|
4626
4676
|
}</code></pre>
|
|
4627
4677
|
</div>
|
|
4628
4678
|
<div class="tab-pane fade" id="rekog-method-index-face-cjs">
|
|
@@ -4650,11 +4700,11 @@ const faceId = await client.indexFace('MyCollection', fs.readFileSync(
|
|
|
4650
4700
|
// message: No face was found in the image
|
|
4651
4701
|
try {
|
|
4652
4702
|
await client.indexFace('MyCollection', 'img.jpg');
|
|
4653
|
-
} catch
|
|
4703
|
+
} catch(err) {
|
|
4654
4704
|
// You can get the resulting HTTP status code from the exception.
|
|
4655
|
-
console.log(`name: ${
|
|
4656
|
-
console.log(`statusCode: ${
|
|
4657
|
-
console.log(`message: ${
|
|
4705
|
+
console.log(`name: ${err.name}`);
|
|
4706
|
+
console.log(`statusCode: ${err.statusCode}`);
|
|
4707
|
+
console.log(`message: ${err.message}`);
|
|
4658
4708
|
}
|
|
4659
4709
|
|
|
4660
4710
|
// If multiple faces are found in the image, throw an error.
|
|
@@ -4663,11 +4713,11 @@ try {
|
|
|
4663
4713
|
// message: Multiple faces found in the image
|
|
4664
4714
|
try {
|
|
4665
4715
|
await client.indexFace('MyCollection', 'img.jpg');
|
|
4666
|
-
} catch
|
|
4716
|
+
} catch(err) {
|
|
4667
4717
|
// You can get the resulting HTTP status code from the exception.
|
|
4668
|
-
console.log(`name: ${
|
|
4669
|
-
console.log(`statusCode: ${
|
|
4670
|
-
console.log(`message: ${
|
|
4718
|
+
console.log(`name: ${err.name}`);
|
|
4719
|
+
console.log(`statusCode: ${err.statusCode}`);
|
|
4720
|
+
console.log(`message: ${err.message}`);
|
|
4671
4721
|
}</code></pre>
|
|
4672
4722
|
</div>
|
|
4673
4723
|
</div>
|
|
@@ -5035,7 +5085,7 @@ await client.deleteFaces('MyCollection', ['f7befa24-3b83-43cc-b21
|
|
|
5035
5085
|
|
|
5036
5086
|
<script src="https://code.jquery.com/jquery-3.6.0.slim.min.js" integrity="sha256-u7e5khyithlIdTpu22PHhENmPcRdFiHRjhAuHcs05RI=" crossorigin="anonymous"></script>
|
|
5037
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>
|
|
5038
|
-
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/
|
|
5088
|
+
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.3.1/highlight.min.js"></script>
|
|
5039
5089
|
<script src="scripts/docs.js"></script>
|
|
5040
5090
|
</body>
|
|
5041
5091
|
</html>
|