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/CHANGELOG.md +87 -5
- package/dist/build.common.js +3 -3
- package/dist/build.esm.js +3 -3
- package/docs/index.html +319 -297
- package/docs/styles/docs.css +5 -10
- package/package.json +1 -1
- package/types/database/Model.d.ts +51 -20
- package/types/handlebars_helpers/comparison.d.ts +48 -7
- package/types/interfaces/AuthenticationOptions.d.ts +2 -2
- package/types/services/AWSRekognitionClient.d.ts +12 -12
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,7 +2773,7 @@ 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>
|
|
@@ -2791,6 +2787,19 @@ console.log('books=', 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('../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>
|
|
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<<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>
|
|
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<sequelize.Transaction>} 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
|
|
2884
|
-
|
|
2896
|
+
<pre><code class="js">import BookModel from '../models/BookModel';
|
|
2897
|
+
|
|
2898
|
+
// Simple transaction usage example.
|
|
2885
2899
|
let transaction;
|
|
2886
2900
|
try {
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
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: 'When Im Gone'}, {transaction});
|
|
2903
|
+
await transaction.commit();
|
|
2904
|
+
} catch(error) {
|
|
2905
|
+
if (transaction)
|
|
2906
|
+
await transaction.rollback();
|
|
2907
|
+
}
|
|
2896
2908
|
|
|
2897
|
-
|
|
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});
|
|
2898
2919
|
await transaction.commit();
|
|
2899
|
-
|
|
2900
|
-
//
|
|
2901
|
-
|
|
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
|
|
2931
|
+
<pre><code class="js">const BookModel = require('../models/BookModel');
|
|
2906
2932
|
|
|
2933
|
+
// Simple transaction usage example.
|
|
2907
2934
|
let transaction;
|
|
2908
2935
|
try {
|
|
2909
|
-
|
|
2910
|
-
|
|
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 = 'Jane';
|
|
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: 'When Im Gone'}, {transaction});
|
|
2920
2938
|
await transaction.commit();
|
|
2921
|
-
} catch(
|
|
2922
|
-
|
|
2923
|
-
|
|
2939
|
+
} catch(error) {
|
|
2940
|
+
if (transaction)
|
|
2941
|
+
await transaction.rollback();
|
|
2924
2942
|
}
|
|
2925
|
-
|
|
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>
|
|
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
|
|
2995
|
+
<pre><code class="js">import BookModel from '../models/BookModel';
|
|
2958
2996
|
|
|
2959
|
-
// INSERT INTO `
|
|
2960
|
-
await
|
|
2997
|
+
// INSERT INTO `book` (`id`,`title`) VALUES (DEFAULT,'When Im Gone');
|
|
2998
|
+
await BookModel.create({title: 'When Im Gone'});</code></pre>
|
|
2961
2999
|
</div>
|
|
2962
3000
|
<div class="tab-pane fade" id="model-create-cjs">
|
|
2963
|
-
<pre><code class="js">const
|
|
3001
|
+
<pre><code class="js">const BookModel = require('../models/BookModel');
|
|
2964
3002
|
|
|
2965
|
-
// INSERT INTO `
|
|
2966
|
-
await
|
|
3003
|
+
// INSERT INTO `book` (`id`,`title`) VALUES (DEFAULT,'When Im Gone');
|
|
3004
|
+
await BookModel.create({title: 'When Im Gone'});</code></pre>
|
|
2967
3005
|
</div>
|
|
2968
3006
|
</div>
|
|
2969
3007
|
</div>
|
|
@@ -2994,26 +3032,26 @@ await UserModel.create({email: 'ellen@example.com', password: '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
|
|
3035
|
+
<pre><code class="js">import BookModel from '../models/BookModel';
|
|
2998
3036
|
|
|
2999
|
-
// INSERT INTO `
|
|
3000
|
-
const
|
|
3001
|
-
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();
|
|
3002
3040
|
|
|
3003
|
-
// UPDATE `
|
|
3004
|
-
|
|
3005
|
-
await
|
|
3041
|
+
// UPDATE `book` SET `title`='Lose Yourself' WHERE `id` = 1;
|
|
3042
|
+
book.title = 'Lose Yourself';
|
|
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
|
|
3046
|
+
<pre><code class="js">const BookModel = require('../models/BookModel');
|
|
3009
3047
|
|
|
3010
|
-
// INSERT INTO `
|
|
3011
|
-
const
|
|
3012
|
-
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();
|
|
3013
3051
|
|
|
3014
|
-
// UPDATE `
|
|
3015
|
-
|
|
3016
|
-
await
|
|
3052
|
+
// UPDATE `book` SET `title`='Lose Yourself' WHERE `id` = 1;
|
|
3053
|
+
book.title = 'Lose Yourself';
|
|
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
|
|
3086
|
+
<pre><code class="js">import BookModel from '../models/BookModel';
|
|
3049
3087
|
|
|
3050
|
-
// SELECT `id`, `
|
|
3051
|
-
await
|
|
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
|
|
3092
|
+
<pre><code class="js">const BookModel = require('../models/BookModel');
|
|
3055
3093
|
|
|
3056
|
-
// SELECT `id`, `
|
|
3057
|
-
await
|
|
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
|
|
3126
|
+
<pre><code class="js">import BookModel from '../models/BookModel';
|
|
3089
3127
|
|
|
3090
|
-
// SELECT `id`, `
|
|
3091
|
-
|
|
3128
|
+
// SELECT `id`, `title`, `created`, `modified` FROM `book` AS `book` WHERE `book`.`title` LIKE 'When Im Gone%';
|
|
3129
|
+
await BookModel.findAll({
|
|
3092
3130
|
where: {
|
|
3093
|
-
|
|
3094
|
-
[
|
|
3131
|
+
title: {
|
|
3132
|
+
[BookModel.Op.like]: 'When Im Gone%'
|
|
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
|
|
3138
|
+
<pre><code class="js">const BookModel = require('../models/BookModel');
|
|
3101
3139
|
|
|
3102
|
-
// SELECT `id`, `
|
|
3103
|
-
|
|
3140
|
+
// SELECT `id`, `title`, `created`, `modified` FROM `book` AS `book` WHERE `book`.`title` LIKE 'When Im Gone%';
|
|
3141
|
+
await BookModel.findAll({
|
|
3104
3142
|
where: {
|
|
3105
|
-
|
|
3106
|
-
[
|
|
3143
|
+
title: {
|
|
3144
|
+
[BookModel.Op.like]: 'When Im Gone%'
|
|
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
|
|
3178
|
+
<pre><code class="js">import BookModel from '../models/BookModel';
|
|
3141
3179
|
|
|
3142
|
-
// SELECT count(*) AS `count` FROM `
|
|
3143
|
-
await
|
|
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
|
|
3184
|
+
<pre><code class="js">const BookModel = require('../models/BookModel');
|
|
3147
3185
|
|
|
3148
|
-
// SELECT count(*) AS `count` FROM `
|
|
3149
|
-
await
|
|
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
|
|
3219
|
+
<pre><code class="js">import BookModel from '../models/BookModel';
|
|
3182
3220
|
|
|
3183
|
-
// UPDATE `
|
|
3184
|
-
await
|
|
3185
|
-
{name: 'Jane'},
|
|
3186
|
-
{where: {id: 1}}
|
|
3187
|
-
);</code></pre>
|
|
3221
|
+
// UPDATE `book` SET `title`='Lose Yourself' WHERE `id` = 1;
|
|
3222
|
+
await BookModel.update({title: 'Lose Yourself'}, {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
|
|
3225
|
+
<pre><code class="js">const BookModel = require('../models/BookModel');
|
|
3191
3226
|
|
|
3192
|
-
// UPDATE `
|
|
3193
|
-
await
|
|
3194
|
-
{name: 'Jane'},
|
|
3195
|
-
{where: {id: 1}}
|
|
3196
|
-
);</code></pre>
|
|
3227
|
+
// UPDATE `book` SET `title`='Lose Yourself' WHERE `id` = 1;
|
|
3228
|
+
await BookModel.update({title: 'Lose Yourself'}, {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
|
|
3263
|
+
<pre><code class="js">import BookModel from '../models/BookModel';
|
|
3232
3264
|
|
|
3233
|
-
// INSERT INTO `
|
|
3234
|
-
|
|
3235
|
-
await UserModel.upsert({
|
|
3236
|
-
email: 'robin@example.com',
|
|
3237
|
-
password: 'password',
|
|
3238
|
-
name: 'Robin'
|
|
3239
|
-
});</code></pre>
|
|
3265
|
+
// INSERT INTO `book` (`title`) VALUES (?) ON DUPLICATE KEY UPDATE `title`=VALUES(`title`);
|
|
3266
|
+
await BookModel.upsert({title: 'Lose Yourself'});</code></pre>
|
|
3240
3267
|
</div>
|
|
3241
3268
|
<div class="tab-pane fade" id="model-upsert-cjs">
|
|
3242
|
-
<pre><code class="js">const
|
|
3269
|
+
<pre><code class="js">const BookModel = require('../models/BookModel');
|
|
3243
3270
|
|
|
3244
|
-
// INSERT INTO `
|
|
3245
|
-
|
|
3246
|
-
await UserModel.upsert({
|
|
3247
|
-
email: 'robin@example.com',
|
|
3248
|
-
password: 'password',
|
|
3249
|
-
name: 'Robin'
|
|
3250
|
-
});</code></pre>
|
|
3271
|
+
// INSERT INTO `book` (`title`) VALUES (?) ON DUPLICATE KEY UPDATE `title`=VALUES(`title`);
|
|
3272
|
+
await BookModel.upsert({title: 'Lose Yourself'});</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
|
|
3303
|
+
<pre><code class="js">import BookModel from '../models/BookModel';
|
|
3282
3304
|
|
|
3283
3305
|
// DELETE FROM `user` WHERE `id` = 1;
|
|
3284
|
-
await
|
|
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
|
|
3309
|
+
<pre><code class="js">const BookModel = require('../models/BookModel');
|
|
3288
3310
|
|
|
3289
3311
|
// DELETE FROM `user` WHERE `id` = 1;
|
|
3290
|
-
await
|
|
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": "
|
|
3888
|
+
// "title": "When Im Gone"
|
|
3867
3889
|
// },
|
|
3868
3890
|
// {
|
|
3869
3891
|
// "userId": 1,
|
|
3870
|
-
// "title": "
|
|
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": "
|
|
3925
|
+
// "title": "When Im Gone"
|
|
3904
3926
|
// },
|
|
3905
3927
|
// {
|
|
3906
3928
|
// "userId": 1,
|
|
3907
|
-
// "title": "
|
|
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
|
|
3960
|
+
const [results, metadata] = await BookModel.query("UPDATE book SET title = 'Lose Yourself' WHERE id = 1");
|
|
3939
3961
|
|
|
3940
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:
|
|
3941
3963
|
// We didn't need to destructure the result here - the results were returned directly
|
|
3942
|
-
|
|
3964
|
+
await BookModel.query("SELECT * FROM book", {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('MyCollection');
|
|
4437
|
-
} catch
|
|
4459
|
+
} catch(err) {
|
|
4438
4460
|
// You can get the resulting HTTP status code from the exception.
|
|
4439
|
-
console.log(`name: ${
|
|
4440
|
-
console.log(`statusCode: ${
|
|
4441
|
-
console.log(`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('MyCollection');
|
|
4456
|
-
} catch
|
|
4478
|
+
} catch(err) {
|
|
4457
4479
|
// You can get the resulting HTTP status code from the exception.
|
|
4458
|
-
console.log(`name: ${
|
|
4459
|
-
console.log(`statusCode: ${
|
|
4460
|
-
console.log(`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('MyCollection', fs.readFileSync(
|
|
|
4633
4655
|
// message: No face was found in the image
|
|
4634
4656
|
try {
|
|
4635
4657
|
await client.indexFace('MyCollection', 'img.jpg');
|
|
4636
|
-
} catch
|
|
4658
|
+
} catch(err) {
|
|
4637
4659
|
// You can get the resulting HTTP status code from the exception.
|
|
4638
|
-
console.log(`name: ${
|
|
4639
|
-
console.log(`statusCode: ${
|
|
4640
|
-
console.log(`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('MyCollection', 'img.jpg');
|
|
4649
|
-
} catch
|
|
4671
|
+
} catch(err) {
|
|
4650
4672
|
// You can get the resulting HTTP status code from the exception.
|
|
4651
|
-
console.log(`name: ${
|
|
4652
|
-
console.log(`statusCode: ${
|
|
4653
|
-
console.log(`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('MyCollection', fs.readFileSync(
|
|
|
4678
4700
|
// message: No face was found in the image
|
|
4679
4701
|
try {
|
|
4680
4702
|
await client.indexFace('MyCollection', 'img.jpg');
|
|
4681
|
-
} catch
|
|
4703
|
+
} catch(err) {
|
|
4682
4704
|
// You can get the resulting HTTP status code from the exception.
|
|
4683
|
-
console.log(`name: ${
|
|
4684
|
-
console.log(`statusCode: ${
|
|
4685
|
-
console.log(`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('MyCollection', 'img.jpg');
|
|
4694
|
-
} catch
|
|
4716
|
+
} catch(err) {
|
|
4695
4717
|
// You can get the resulting HTTP status code from the exception.
|
|
4696
|
-
console.log(`name: ${
|
|
4697
|
-
console.log(`statusCode: ${
|
|
4698
|
-
console.log(`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('MyCollection', ['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/
|
|
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>
|