express-sweet 1.0.12 → 1.0.13
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 +28 -2
- package/dist/build.common.js +2 -2
- package/dist/build.esm.js +2 -2
- package/docs/index.html +257 -288
- package/docs/styles/docs.css +5 -10
- package/package.json +1 -1
- package/types/database/Model.d.ts +51 -20
- 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,7 @@ 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
|
-
'/api'
|
|
949
|
-
]</code></pre>
|
|
925
|
+
<pre><code class="js">allow_unauthenticated: ['/api']</code></pre>
|
|
950
926
|
</td>
|
|
951
927
|
</tr>
|
|
952
928
|
<tr>
|
|
@@ -1016,13 +992,7 @@ export default {
|
|
|
1016
992
|
* @type {(username: string, password: string) => Promise<{[key: string]: any}|null>}
|
|
1017
993
|
*/
|
|
1018
994
|
authenticate_user: async (username, password) => {
|
|
1019
|
-
return UserModel.findOne({
|
|
1020
|
-
where: {
|
|
1021
|
-
email: username,
|
|
1022
|
-
password: password
|
|
1023
|
-
},
|
|
1024
|
-
raw: true
|
|
1025
|
-
});
|
|
995
|
+
return UserModel.findOne({where: {email: username, password: password}, raw: true});
|
|
1026
996
|
},
|
|
1027
997
|
|
|
1028
998
|
/**
|
|
@@ -1033,10 +1003,7 @@ export default {
|
|
|
1033
1003
|
* @type {(id: number|string) => Promise<{[key: string]: any}>}
|
|
1034
1004
|
*/
|
|
1035
1005
|
subscribe_user: async (id) => {
|
|
1036
|
-
return UserModel.findOne({
|
|
1037
|
-
where: {id},
|
|
1038
|
-
raw: true
|
|
1039
|
-
});
|
|
1006
|
+
return UserModel.findOne({where: {id}, raw: true});
|
|
1040
1007
|
},
|
|
1041
1008
|
|
|
1042
1009
|
/**
|
|
@@ -1099,13 +1066,7 @@ module.exports = {
|
|
|
1099
1066
|
* @type {(username: string, password: string) => Promise<{[key: string]: any}|null>}
|
|
1100
1067
|
*/
|
|
1101
1068
|
authenticate_user: async (username, password) => {
|
|
1102
|
-
return UserModel.findOne({
|
|
1103
|
-
where: {
|
|
1104
|
-
email: username,
|
|
1105
|
-
password: password
|
|
1106
|
-
},
|
|
1107
|
-
raw: true
|
|
1108
|
-
});
|
|
1069
|
+
return UserModel.findOne({where: {email: username, password: password}, raw: true});
|
|
1109
1070
|
},
|
|
1110
1071
|
|
|
1111
1072
|
/**
|
|
@@ -1116,10 +1077,7 @@ module.exports = {
|
|
|
1116
1077
|
* @type {(id: number|string) => Promise<{[key: string]: any}>}
|
|
1117
1078
|
*/
|
|
1118
1079
|
subscribe_user: async (id) => {
|
|
1119
|
-
return UserModel.findOne({
|
|
1120
|
-
where: {id},
|
|
1121
|
-
raw: true
|
|
1122
|
-
});
|
|
1080
|
+
return UserModel.findOne({where: {id}, raw: true});
|
|
1123
1081
|
},
|
|
1124
1082
|
|
|
1125
1083
|
/**
|
|
@@ -1216,38 +1174,32 @@ export default {
|
|
|
1216
1174
|
development: {
|
|
1217
1175
|
username: 'root',
|
|
1218
1176
|
password: null,
|
|
1219
|
-
database: '
|
|
1177
|
+
database: 'testdb',
|
|
1220
1178
|
host: 'localhost',
|
|
1221
|
-
port:
|
|
1179
|
+
port: 3306,
|
|
1222
1180
|
dialect: 'mariadb',
|
|
1223
1181
|
timezone: '+09:00',
|
|
1224
1182
|
logging: false
|
|
1225
|
-
//,timezone: 'Etc/GMT-9'
|
|
1226
|
-
//,dialectOptions: {useUTC: false, timezone: 'Etc/GMT-9'}
|
|
1227
1183
|
},
|
|
1228
1184
|
test: {
|
|
1229
1185
|
username: 'root',
|
|
1230
1186
|
password: null,
|
|
1231
|
-
database: '
|
|
1187
|
+
database: 'testdb',
|
|
1232
1188
|
host: 'localhost',
|
|
1233
|
-
port:
|
|
1189
|
+
port: 3306,
|
|
1234
1190
|
dialect: 'mariadb',
|
|
1235
1191
|
timezone: '+09:00',
|
|
1236
1192
|
logging: false
|
|
1237
|
-
//,timezone: 'Etc/GMT-9'
|
|
1238
|
-
//,dialectOptions: {useUTC: false, timezone: 'Etc/GMT-9'}
|
|
1239
1193
|
},
|
|
1240
1194
|
production: {
|
|
1241
1195
|
username: 'root',
|
|
1242
1196
|
password: null,
|
|
1243
|
-
database: '
|
|
1197
|
+
database: 'testdb',
|
|
1244
1198
|
host: 'localhost',
|
|
1245
|
-
port:
|
|
1199
|
+
port: 3306,
|
|
1246
1200
|
dialect: 'mariadb',
|
|
1247
1201
|
timezone: '+09:00',
|
|
1248
1202
|
logging: false
|
|
1249
|
-
//,timezone: 'Etc/GMT-9'
|
|
1250
|
-
//,dialectOptions: {useUTC: false, timezone: 'Etc/GMT-9'}
|
|
1251
1203
|
}
|
|
1252
1204
|
}</code></pre>
|
|
1253
1205
|
</div>
|
|
@@ -1259,38 +1211,32 @@ module.exports = {
|
|
|
1259
1211
|
development: {
|
|
1260
1212
|
username: 'root',
|
|
1261
1213
|
password: null,
|
|
1262
|
-
database: '
|
|
1214
|
+
database: 'testdb',
|
|
1263
1215
|
host: 'localhost',
|
|
1264
|
-
port:
|
|
1216
|
+
port: 3306,
|
|
1265
1217
|
dialect: 'mariadb',
|
|
1266
1218
|
timezone: '+09:00',
|
|
1267
1219
|
logging: false
|
|
1268
|
-
//,timezone: 'Etc/GMT-9'
|
|
1269
|
-
//,dialectOptions: {useUTC: false, timezone: 'Etc/GMT-9'}
|
|
1270
1220
|
},
|
|
1271
1221
|
test: {
|
|
1272
1222
|
username: 'root',
|
|
1273
1223
|
password: null,
|
|
1274
|
-
database: '
|
|
1224
|
+
database: 'testdb',
|
|
1275
1225
|
host: 'localhost',
|
|
1276
|
-
port:
|
|
1226
|
+
port: 3306,
|
|
1277
1227
|
dialect: 'mariadb',
|
|
1278
1228
|
timezone: '+09:00',
|
|
1279
1229
|
logging: false
|
|
1280
|
-
//,timezone: 'Etc/GMT-9'
|
|
1281
|
-
//,dialectOptions: {useUTC: false, timezone: 'Etc/GMT-9'}
|
|
1282
1230
|
},
|
|
1283
1231
|
production: {
|
|
1284
1232
|
username: 'root',
|
|
1285
1233
|
password: null,
|
|
1286
|
-
database: '
|
|
1234
|
+
database: 'testdb',
|
|
1287
1235
|
host: 'localhost',
|
|
1288
|
-
port:
|
|
1236
|
+
port: 3306,
|
|
1289
1237
|
dialect: 'mariadb',
|
|
1290
1238
|
timezone: '+09:00',
|
|
1291
1239
|
logging: false
|
|
1292
|
-
//,timezone: 'Etc/GMT-9'
|
|
1293
|
-
//,dialectOptions: {useUTC: false, timezone: 'Etc/GMT-9'}
|
|
1294
1240
|
}
|
|
1295
1241
|
}</code></pre>
|
|
1296
1242
|
</div>
|
|
@@ -2196,9 +2142,8 @@ let value = '2'
|
|
|
2196
2142
|
<!--begin::Accessing Models-->
|
|
2197
2143
|
<h2 id="model-accessing">Accessing Models</h2>
|
|
2198
2144
|
<p>
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
In the following example, "routes/users.js" loads "models/UserModel.js" and tries CRUD to the user table.
|
|
2145
|
+
Place the model in the "models" directory of the root directory.<br>
|
|
2146
|
+
When you load the model, you have immediate access to the model's functions for working with the database.
|
|
2202
2147
|
</p>
|
|
2203
2148
|
<div class="example">
|
|
2204
2149
|
<ul class="nav nav-tabs">
|
|
@@ -2211,34 +2156,34 @@ let value = '2'
|
|
|
2211
2156
|
</ul>
|
|
2212
2157
|
<div class="tab-content">
|
|
2213
2158
|
<div class="tab-pane fade show active" id="model-accessing-esm">
|
|
2214
|
-
<pre><code class="js">import
|
|
2159
|
+
<pre><code class="js">import BookModel from '../models/BookModel';
|
|
2215
2160
|
|
|
2216
|
-
// INSERT INTO
|
|
2217
|
-
await
|
|
2161
|
+
// INSERT INTO book (title) VALUES ('When Im Gone')
|
|
2162
|
+
await BookModel.create({title: 'When Im Gone'});
|
|
2218
2163
|
|
|
2219
|
-
// SELECT * FROM
|
|
2220
|
-
await
|
|
2164
|
+
// SELECT * FROM book
|
|
2165
|
+
await BookModel.findAll();
|
|
2221
2166
|
|
|
2222
|
-
// UPDATE
|
|
2223
|
-
await
|
|
2167
|
+
// UPDATE book SET title = 'When Im Gone' WHERE id= 1
|
|
2168
|
+
await BookModel.update({title: 'When Im Gone'}, {where: {id: 1}});
|
|
2224
2169
|
|
|
2225
|
-
// DELETE FROM
|
|
2226
|
-
await
|
|
2170
|
+
// DELETE FROM book WHERE id= 1
|
|
2171
|
+
await BookModel.destroy({where: {id: 1}});</code></pre>
|
|
2227
2172
|
</div>
|
|
2228
2173
|
<div class="tab-pane fade" id="model-accessing-cjs">
|
|
2229
|
-
<pre><code class="js">const
|
|
2174
|
+
<pre><code class="js">const BookModel = require('../models/BookModel');
|
|
2230
2175
|
|
|
2231
|
-
// INSERT INTO
|
|
2232
|
-
await
|
|
2176
|
+
// INSERT INTO book (title) VALUES ('When Im Gone')
|
|
2177
|
+
await BookModel.create({title: 'When Im Gone'});
|
|
2233
2178
|
|
|
2234
|
-
// SELECT * FROM
|
|
2235
|
-
await
|
|
2179
|
+
// SELECT * FROM book
|
|
2180
|
+
await BookModel.findAll();
|
|
2236
2181
|
|
|
2237
|
-
// UPDATE
|
|
2238
|
-
await
|
|
2182
|
+
// UPDATE book SET title = 'When Im Gone' WHERE id= 1
|
|
2183
|
+
await BookModel.update({title: 'When Im Gone'}, {where: {id: 1}});
|
|
2239
2184
|
|
|
2240
|
-
// DELETE FROM
|
|
2241
|
-
await
|
|
2185
|
+
// DELETE FROM book WHERE id= 1
|
|
2186
|
+
await BookModel.destroy({where: {id: 1}});</code></pre>
|
|
2242
2187
|
</div>
|
|
2243
2188
|
</div>
|
|
2244
2189
|
</div>
|
|
@@ -2521,65 +2466,65 @@ module.exports = class extends Model {
|
|
|
2521
2466
|
</ul>
|
|
2522
2467
|
<div class="tab-content">
|
|
2523
2468
|
<div class="tab-pane fade show active" id="model-op-esm">
|
|
2524
|
-
<pre><code class="js">import
|
|
2469
|
+
<pre><code class="js">import BookModel from '../models/BookModel';
|
|
2525
2470
|
|
|
2526
|
-
// SELECT * FROM
|
|
2527
|
-
|
|
2471
|
+
// SELECT * FROM book WHERE title = 'When Im Gone' AND genre = 'Nonfiction';
|
|
2472
|
+
BookModel.findOne({
|
|
2528
2473
|
where: {
|
|
2529
|
-
[
|
|
2530
|
-
{
|
|
2531
|
-
{
|
|
2474
|
+
[BookModel.Op.and]: [
|
|
2475
|
+
{title: 'When Im Gone'},
|
|
2476
|
+
{genre: 'Nonfiction'}
|
|
2532
2477
|
]
|
|
2533
2478
|
}
|
|
2534
2479
|
});
|
|
2535
2480
|
|
|
2536
|
-
// SELECT * FROM
|
|
2537
|
-
|
|
2481
|
+
// SELECT * FROM book WHERE title = 'When Im Gone' OR title = 'Lose Yourself';
|
|
2482
|
+
BookModel.findAll({
|
|
2538
2483
|
where: {
|
|
2539
|
-
[
|
|
2540
|
-
{
|
|
2541
|
-
{
|
|
2484
|
+
[BookModel.Op.or]: [
|
|
2485
|
+
{title: 'When Im Gone'},
|
|
2486
|
+
{title: 'Lose Yourself'}
|
|
2542
2487
|
]
|
|
2543
2488
|
}
|
|
2544
2489
|
});
|
|
2545
2490
|
|
|
2546
|
-
// DELETE FROM user WHERE name = '
|
|
2547
|
-
|
|
2491
|
+
// DELETE FROM user WHERE name = 'When Im Gone' OR name = 'Lose Yourself';
|
|
2492
|
+
BookModel.destroy({
|
|
2548
2493
|
where: {
|
|
2549
|
-
|
|
2550
|
-
[
|
|
2494
|
+
title: {
|
|
2495
|
+
[BookModel.Op.or]: ['When Im Gone', 'Lose Yourself']
|
|
2551
2496
|
}
|
|
2552
2497
|
}
|
|
2553
2498
|
});</code></pre>
|
|
2554
2499
|
</div>
|
|
2555
2500
|
<div class="tab-pane fade" id="model-op-cjs">
|
|
2556
|
-
<pre><code class="js">const
|
|
2501
|
+
<pre><code class="js">const BookModel = require('../models/BookModel');
|
|
2557
2502
|
|
|
2558
|
-
// SELECT * FROM
|
|
2559
|
-
|
|
2503
|
+
// SELECT * FROM book WHERE title = 'When Im Gone' AND genre = 'Nonfiction';
|
|
2504
|
+
BookModel.findOne({
|
|
2560
2505
|
where: {
|
|
2561
|
-
[
|
|
2562
|
-
{
|
|
2563
|
-
{
|
|
2506
|
+
[BookModel.Op.and]: [
|
|
2507
|
+
{title: 'When Im Gone'},
|
|
2508
|
+
{genre: 'Nonfiction'}
|
|
2564
2509
|
]
|
|
2565
2510
|
}
|
|
2566
2511
|
});
|
|
2567
2512
|
|
|
2568
|
-
// SELECT * FROM
|
|
2569
|
-
|
|
2513
|
+
// SELECT * FROM book WHERE title = 'When Im Gone' OR title = 'Lose Yourself';
|
|
2514
|
+
BookModel.findAll({
|
|
2570
2515
|
where: {
|
|
2571
|
-
[
|
|
2572
|
-
{
|
|
2573
|
-
{
|
|
2516
|
+
[BookModel.Op.or]: [
|
|
2517
|
+
{title: 'When Im Gone'},
|
|
2518
|
+
{title: 'Lose Yourself'}
|
|
2574
2519
|
]
|
|
2575
2520
|
}
|
|
2576
2521
|
});
|
|
2577
2522
|
|
|
2578
|
-
// DELETE FROM user WHERE name = '
|
|
2579
|
-
|
|
2523
|
+
// DELETE FROM user WHERE name = 'When Im Gone' OR name = 'Lose Yourself';
|
|
2524
|
+
BookModel.destroy({
|
|
2580
2525
|
where: {
|
|
2581
|
-
|
|
2582
|
-
[
|
|
2526
|
+
title: {
|
|
2527
|
+
[BookModel.Op.or]: ['When Im Gone', 'Lose Yourself']
|
|
2583
2528
|
}
|
|
2584
2529
|
}
|
|
2585
2530
|
});</code></pre>
|
|
@@ -2619,9 +2564,9 @@ const books = await BookModel.findAll({
|
|
|
2619
2564
|
});
|
|
2620
2565
|
|
|
2621
2566
|
// Output: books= [
|
|
2622
|
-
// {
|
|
2623
|
-
// {
|
|
2624
|
-
// {
|
|
2567
|
+
// {title: 'MOBY DICK'},
|
|
2568
|
+
// {title: 'GET RICH REALLY FAST'},
|
|
2569
|
+
// {title: 'FINDING INNER PEACE'}
|
|
2625
2570
|
// ]
|
|
2626
2571
|
console.log('books=', books);</code></pre>
|
|
2627
2572
|
</div>
|
|
@@ -2637,9 +2582,9 @@ const books = await BookModel.findAll({
|
|
|
2637
2582
|
});
|
|
2638
2583
|
|
|
2639
2584
|
// Output: books= [
|
|
2640
|
-
// {
|
|
2641
|
-
// {
|
|
2642
|
-
// {
|
|
2585
|
+
// {title: 'MOBY DICK'},
|
|
2586
|
+
// {title: 'GET RICH REALLY FAST'},
|
|
2587
|
+
// {title: 'FINDING INNER PEACE'}
|
|
2643
2588
|
// ]
|
|
2644
2589
|
console.log('books=', books);</code></pre>
|
|
2645
2590
|
</div>
|
|
@@ -2691,9 +2636,8 @@ const books = await BookModel.findAll({
|
|
|
2691
2636
|
});
|
|
2692
2637
|
|
|
2693
2638
|
// Output: books= [
|
|
2694
|
-
// {
|
|
2695
|
-
// {
|
|
2696
|
-
// { id: 3, title: 'Finding Inner Peace', count: 0 }
|
|
2639
|
+
// {id: 1, title: 'When Im Gone', count: 2},
|
|
2640
|
+
// {id: 2, title: 'Lose Yourself', count: 1}
|
|
2697
2641
|
// ]
|
|
2698
2642
|
console.log('books=', books);</code></pre>
|
|
2699
2643
|
</div>
|
|
@@ -2716,9 +2660,8 @@ const books = await BookModel.findAll({
|
|
|
2716
2660
|
});
|
|
2717
2661
|
|
|
2718
2662
|
// Output: books= [
|
|
2719
|
-
// {
|
|
2720
|
-
// {
|
|
2721
|
-
// { id: 3, title: 'Finding Inner Peace', count: 0 }
|
|
2663
|
+
// {id: 1, title: 'When Im Gone', count: 2},
|
|
2664
|
+
// {id: 2, title: 'Lose Yourself', count: 1}
|
|
2722
2665
|
// ]
|
|
2723
2666
|
console.log('books=', books);</code></pre>
|
|
2724
2667
|
</div>
|
|
@@ -2734,7 +2677,7 @@ console.log('books=', books);</code></pre>
|
|
|
2734
2677
|
The attr can either be an object taken from Model.rawAttributes (for example Model.rawAttributes.id or Model.rawAttributes.name).<br>
|
|
2735
2678
|
The attribute should be defined in your model definition.<br>
|
|
2736
2679
|
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 {
|
|
2680
|
+
For string attributes, use the regular {where: {attr: something}} syntax.<br>
|
|
2738
2681
|
If you don't want your string to be escaped, use sequelize.literal.<br>
|
|
2739
2682
|
See <a href="https://sequelize.org/master/class/lib/sequelize.js~Sequelize.html#static-method-where" target="_blank">here</a> for details.
|
|
2740
2683
|
</p>
|
|
@@ -2761,7 +2704,7 @@ const books = await BookModel.findAll({
|
|
|
2761
2704
|
raw: true
|
|
2762
2705
|
});
|
|
2763
2706
|
|
|
2764
|
-
// Output: books= [
|
|
2707
|
+
// Output: books= [{title: 'When Im Gone'}]
|
|
2765
2708
|
console.log('books=', books);</code></pre>
|
|
2766
2709
|
</div>
|
|
2767
2710
|
<div class="tab-pane fade" id="model-where-cjs">
|
|
@@ -2777,7 +2720,7 @@ const books = await BookModel.findAll({
|
|
|
2777
2720
|
raw: true
|
|
2778
2721
|
});
|
|
2779
2722
|
|
|
2780
|
-
// Output: books= [
|
|
2723
|
+
// Output: books= [{title: 'When Im Gone'}]
|
|
2781
2724
|
console.log('books=', books);</code></pre>
|
|
2782
2725
|
</div>
|
|
2783
2726
|
</div>
|
|
@@ -2791,6 +2734,19 @@ console.log('books=', books);</code></pre>
|
|
|
2791
2734
|
See <a href="https://sequelize.org/master/variable/index.html#static-variable-QueryTypes" target="_blank">here</a> for details.
|
|
2792
2735
|
</td>
|
|
2793
2736
|
</tr>
|
|
2737
|
+
<tr>
|
|
2738
|
+
<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>
|
|
2739
|
+
<td class="min-w-200px w-100">
|
|
2740
|
+
Reference to <a href="https://sequelize.org/master/class/lib/transaction.js~Transaction.html" target="_blank">sequelize.Transaction</a>.<br>
|
|
2741
|
+
This includes properties such as isolation level enums used with the transaction option.<br>
|
|
2742
|
+
See <a href="https://sequelize.org/master/class/lib/transaction.js~Transaction.html" target="_blank">here</a> for details.
|
|
2743
|
+
<pre><code class="js">const BookModel = require('../models/BookModel');
|
|
2744
|
+
BookModel.Transaction.ISOLATION_LEVELS.READ_UNCOMMITTED // "READ UNCOMMITTED"
|
|
2745
|
+
BookModel.Transaction.ISOLATION_LEVELS.READ_COMMITTED // "READ COMMITTED"
|
|
2746
|
+
BookModel.Transaction.ISOLATION_LEVELS.REPEATABLE_READ // "REPEATABLE READ"
|
|
2747
|
+
BookModel.Transaction.ISOLATION_LEVELS.SERIALIZABLE // "SERIALIZABLE"</code></pre>
|
|
2748
|
+
</td>
|
|
2749
|
+
</tr>
|
|
2794
2750
|
</tbody>
|
|
2795
2751
|
</table>
|
|
2796
2752
|
|
|
@@ -2859,13 +2815,17 @@ module.exports = class extends Model {
|
|
|
2859
2815
|
</td>
|
|
2860
2816
|
</tr>
|
|
2861
2817
|
<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>
|
|
2818
|
+
<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
2819
|
<td class="min-w-200px w-100">
|
|
2864
2820
|
<p>
|
|
2865
2821
|
Starts a transaction and returns a transaction object to identify the running transaction.<br>
|
|
2866
2822
|
This is an alias for the <code>"sequelize.Sequelize.transaction()"</code> method.<br>
|
|
2867
2823
|
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
2824
|
</p>
|
|
2825
|
+
<p class="fw-bolder mb-0">Params:</p>
|
|
2826
|
+
<ul>
|
|
2827
|
+
<li>{sequelize.TransactionOptions} opts? Options provided when the transaction is created..</li>
|
|
2828
|
+
</ul>
|
|
2869
2829
|
<p class="fw-bolder mb-0">Return:</p>
|
|
2870
2830
|
<p>{Promise<sequelize.Transaction>} Returns a transaction object to identify the transaction being executed.</p>
|
|
2871
2831
|
<p class="fw-bolder mb-0">Example:</p>
|
|
@@ -2880,49 +2840,74 @@ module.exports = class extends Model {
|
|
|
2880
2840
|
</ul>
|
|
2881
2841
|
<div class="tab-content">
|
|
2882
2842
|
<div class="tab-pane fade show active" id="model-begin-esm">
|
|
2883
|
-
<pre><code class="js">import
|
|
2884
|
-
|
|
2843
|
+
<pre><code class="js">import BookModel from '../models/BookModel';
|
|
2844
|
+
|
|
2845
|
+
// Simple transaction usage example.
|
|
2885
2846
|
let transaction;
|
|
2886
2847
|
try {
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
// UPDATE `user` SET `name`=? WHERE `id` = ?
|
|
2895
|
-
await user.save({transaction});
|
|
2848
|
+
transaction = await BookModel.begin();
|
|
2849
|
+
const book = await BookModel.create({title: 'When Im Gone'}, {transaction});
|
|
2850
|
+
await transaction.commit();
|
|
2851
|
+
} catch(error) {
|
|
2852
|
+
if (transaction)
|
|
2853
|
+
await transaction.rollback();
|
|
2854
|
+
}
|
|
2896
2855
|
|
|
2897
|
-
|
|
2856
|
+
// You can also use transaction options.
|
|
2857
|
+
let transaction;
|
|
2858
|
+
try {
|
|
2859
|
+
transaction = await BookModel.begin({
|
|
2860
|
+
isolationLevel: BookModel.Transaction.ISOLATION_LEVELS.REPEATABLE_READ,
|
|
2861
|
+
type: BookModel.Transaction.TYPES.DEFERRED,
|
|
2862
|
+
});
|
|
2863
|
+
const book = await BookModel.findOne({where: {id: 1}}, {transaction});
|
|
2864
|
+
book.title = 'When Im Gone';
|
|
2865
|
+
await book.save({transaction});
|
|
2898
2866
|
await transaction.commit();
|
|
2899
|
-
|
|
2900
|
-
//
|
|
2901
|
-
|
|
2867
|
+
|
|
2868
|
+
// Check the update result.
|
|
2869
|
+
// Output: New title of book: When Im Gone
|
|
2870
|
+
await book.reload();
|
|
2871
|
+
console.log(`New title of book: ${book.title}`);
|
|
2872
|
+
} catch (err) {
|
|
2873
|
+
if (transaction)
|
|
2874
|
+
await transaction.rollback();
|
|
2902
2875
|
}</code></pre>
|
|
2903
2876
|
</div>
|
|
2904
2877
|
<div class="tab-pane fade" id="model-begin-cjs">
|
|
2905
|
-
<pre><code class="js">const
|
|
2878
|
+
<pre><code class="js">const BookModel = require('../models/BookModel');
|
|
2906
2879
|
|
|
2880
|
+
// Simple transaction usage example.
|
|
2907
2881
|
let transaction;
|
|
2908
2882
|
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;
|
|
2883
|
+
transaction = await BookModel.begin();
|
|
2884
|
+
const book = await BookModel.create({title: 'When Im Gone'}, {transaction});
|
|
2920
2885
|
await transaction.commit();
|
|
2921
|
-
} catch(
|
|
2922
|
-
|
|
2923
|
-
|
|
2886
|
+
} catch(error) {
|
|
2887
|
+
if (transaction)
|
|
2888
|
+
await transaction.rollback();
|
|
2924
2889
|
}
|
|
2925
|
-
|
|
2890
|
+
|
|
2891
|
+
// You can also use transaction options.
|
|
2892
|
+
let transaction;
|
|
2893
|
+
try {
|
|
2894
|
+
transaction = await BookModel.begin({
|
|
2895
|
+
isolationLevel: BookModel.Transaction.ISOLATION_LEVELS.REPEATABLE_READ,
|
|
2896
|
+
type: BookModel.Transaction.TYPES.DEFERRED,
|
|
2897
|
+
});
|
|
2898
|
+
const book = await BookModel.findOne({where: {id: 1}}, {transaction});
|
|
2899
|
+
book.title = 'When Im Gone';
|
|
2900
|
+
await book.save({transaction});
|
|
2901
|
+
await transaction.commit();
|
|
2902
|
+
|
|
2903
|
+
// Check the update result.
|
|
2904
|
+
// Output: New title of book: When Im Gone
|
|
2905
|
+
await book.reload();
|
|
2906
|
+
console.log(`New title of book: ${book.title}`);
|
|
2907
|
+
} catch (err) {
|
|
2908
|
+
if (transaction)
|
|
2909
|
+
await transaction.rollback();
|
|
2910
|
+
}</code></pre>
|
|
2926
2911
|
</div>
|
|
2927
2912
|
</div>
|
|
2928
2913
|
</div>
|
|
@@ -2954,16 +2939,16 @@ try {
|
|
|
2954
2939
|
</ul>
|
|
2955
2940
|
<div class="tab-content">
|
|
2956
2941
|
<div class="tab-pane fade show active" id="model-create-esm">
|
|
2957
|
-
<pre><code class="js">import
|
|
2942
|
+
<pre><code class="js">import BookModel from '../models/BookModel';
|
|
2958
2943
|
|
|
2959
|
-
// INSERT INTO `
|
|
2960
|
-
await
|
|
2944
|
+
// INSERT INTO `book` (`id`,`title`) VALUES (DEFAULT,'When Im Gone');
|
|
2945
|
+
await BookModel.create({title: 'When Im Gone'});</code></pre>
|
|
2961
2946
|
</div>
|
|
2962
2947
|
<div class="tab-pane fade" id="model-create-cjs">
|
|
2963
|
-
<pre><code class="js">const
|
|
2948
|
+
<pre><code class="js">const BookModel = require('../models/BookModel');
|
|
2964
2949
|
|
|
2965
|
-
// INSERT INTO `
|
|
2966
|
-
await
|
|
2950
|
+
// INSERT INTO `book` (`id`,`title`) VALUES (DEFAULT,'When Im Gone');
|
|
2951
|
+
await BookModel.create({title: 'When Im Gone'});</code></pre>
|
|
2967
2952
|
</div>
|
|
2968
2953
|
</div>
|
|
2969
2954
|
</div>
|
|
@@ -2994,26 +2979,26 @@ await UserModel.create({email: 'ellen@example.com', password: 'pa
|
|
|
2994
2979
|
</ul>
|
|
2995
2980
|
<div class="tab-content">
|
|
2996
2981
|
<div class="tab-pane fade show active" id="model-save-esm">
|
|
2997
|
-
<pre><code class="js">import
|
|
2982
|
+
<pre><code class="js">import BookModel from '../models/BookModel';
|
|
2998
2983
|
|
|
2999
|
-
// INSERT INTO `
|
|
3000
|
-
const
|
|
3001
|
-
await
|
|
2984
|
+
// INSERT INTO `book` (`id`,`title`) VALUES (DEFAULT,'When Im Gone');
|
|
2985
|
+
const book = BookModel.build({title: 'When Im Gone'});
|
|
2986
|
+
await book.save();
|
|
3002
2987
|
|
|
3003
|
-
// UPDATE `
|
|
3004
|
-
|
|
3005
|
-
await
|
|
2988
|
+
// UPDATE `book` SET `title`='Lose Yourself' WHERE `id` = 1;
|
|
2989
|
+
book.title = 'Lose Yourself';
|
|
2990
|
+
await book.save();</code></pre>
|
|
3006
2991
|
</div>
|
|
3007
2992
|
<div class="tab-pane fade" id="model-save-cjs">
|
|
3008
|
-
<pre><code class="js">const
|
|
2993
|
+
<pre><code class="js">const BookModel = require('../models/BookModel');
|
|
3009
2994
|
|
|
3010
|
-
// INSERT INTO `
|
|
3011
|
-
const
|
|
3012
|
-
await
|
|
2995
|
+
// INSERT INTO `book` (`id`,`title`) VALUES (DEFAULT,'When Im Gone');
|
|
2996
|
+
const book = BookModel.build({title: 'When Im Gone'});
|
|
2997
|
+
await book.save();
|
|
3013
2998
|
|
|
3014
|
-
// UPDATE `
|
|
3015
|
-
|
|
3016
|
-
await
|
|
2999
|
+
// UPDATE `book` SET `title`='Lose Yourself' WHERE `id` = 1;
|
|
3000
|
+
book.title = 'Lose Yourself';
|
|
3001
|
+
await book.save();</code></pre>
|
|
3017
3002
|
</div>
|
|
3018
3003
|
</div>
|
|
3019
3004
|
</div>
|
|
@@ -3045,16 +3030,16 @@ await user.save();</code></pre>
|
|
|
3045
3030
|
</ul>
|
|
3046
3031
|
<div class="tab-content">
|
|
3047
3032
|
<div class="tab-pane fade show active" id="model-find-one-esm">
|
|
3048
|
-
<pre><code class="js">import
|
|
3033
|
+
<pre><code class="js">import BookModel from '../models/BookModel';
|
|
3049
3034
|
|
|
3050
|
-
// SELECT `id`, `
|
|
3051
|
-
await
|
|
3035
|
+
// SELECT `id`, `title`, `created`, `modified` FROM `book` AS `book` LIMIT 1;
|
|
3036
|
+
await BookModel.findOne();</code></pre>
|
|
3052
3037
|
</div>
|
|
3053
3038
|
<div class="tab-pane fade" id="model-find-one-cjs">
|
|
3054
|
-
<pre><code class="js">const
|
|
3039
|
+
<pre><code class="js">const BookModel = require('../models/BookModel');
|
|
3055
3040
|
|
|
3056
|
-
// SELECT `id`, `
|
|
3057
|
-
await
|
|
3041
|
+
// SELECT `id`, `title`, `created`, `modified` FROM `book` AS `book` LIMIT 1;
|
|
3042
|
+
await BookModel.findOne();</code></pre>
|
|
3058
3043
|
</div>
|
|
3059
3044
|
</div>
|
|
3060
3045
|
</div>
|
|
@@ -3085,25 +3070,25 @@ await UserModel.findOne();</code></pre>
|
|
|
3085
3070
|
</ul>
|
|
3086
3071
|
<div class="tab-content">
|
|
3087
3072
|
<div class="tab-pane fade show active" id="model-find-all-esm">
|
|
3088
|
-
<pre><code class="js">import
|
|
3073
|
+
<pre><code class="js">import BookModel from '../models/BookModel';
|
|
3089
3074
|
|
|
3090
|
-
// SELECT `id`, `
|
|
3091
|
-
|
|
3075
|
+
// SELECT `id`, `title`, `created`, `modified` FROM `book` AS `book` WHERE `book`.`title` LIKE 'When Im Gone%';
|
|
3076
|
+
await BookModel.findAll({
|
|
3092
3077
|
where: {
|
|
3093
|
-
|
|
3094
|
-
[
|
|
3078
|
+
title: {
|
|
3079
|
+
[BookModel.Op.like]: 'When Im Gone%'
|
|
3095
3080
|
}
|
|
3096
3081
|
}
|
|
3097
3082
|
});</code></pre>
|
|
3098
3083
|
</div>
|
|
3099
3084
|
<div class="tab-pane fade" id="model-find-all-cjs">
|
|
3100
|
-
<pre><code class="js">const
|
|
3085
|
+
<pre><code class="js">const BookModel = require('../models/BookModel');
|
|
3101
3086
|
|
|
3102
|
-
// SELECT `id`, `
|
|
3103
|
-
|
|
3087
|
+
// SELECT `id`, `title`, `created`, `modified` FROM `book` AS `book` WHERE `book`.`title` LIKE 'When Im Gone%';
|
|
3088
|
+
await BookModel.findAll({
|
|
3104
3089
|
where: {
|
|
3105
|
-
|
|
3106
|
-
[
|
|
3090
|
+
title: {
|
|
3091
|
+
[BookModel.Op.like]: 'When Im Gone%'
|
|
3107
3092
|
}
|
|
3108
3093
|
}
|
|
3109
3094
|
});</code></pre>
|
|
@@ -3137,16 +3122,16 @@ const users = await UserModel.findAll({
|
|
|
3137
3122
|
</ul>
|
|
3138
3123
|
<div class="tab-content">
|
|
3139
3124
|
<div class="tab-pane fade show active" id="model-count-esm">
|
|
3140
|
-
<pre><code class="js">import
|
|
3125
|
+
<pre><code class="js">import BookModel from '../models/BookModel';
|
|
3141
3126
|
|
|
3142
|
-
// SELECT count(*) AS `count` FROM `
|
|
3143
|
-
await
|
|
3127
|
+
// SELECT count(*) AS `count` FROM `book` AS `book`;
|
|
3128
|
+
await BookModel.count();</code></pre>
|
|
3144
3129
|
</div>
|
|
3145
3130
|
<div class="tab-pane fade" id="model-count-cjs">
|
|
3146
|
-
<pre><code class="js">const
|
|
3131
|
+
<pre><code class="js">const BookModel = require('../models/BookModel');
|
|
3147
3132
|
|
|
3148
|
-
// SELECT count(*) AS `count` FROM `
|
|
3149
|
-
await
|
|
3133
|
+
// SELECT count(*) AS `count` FROM `book` AS `book`;
|
|
3134
|
+
await BookModel.count();</code></pre>
|
|
3150
3135
|
</div>
|
|
3151
3136
|
</div>
|
|
3152
3137
|
</div>
|
|
@@ -3178,22 +3163,16 @@ await UserModel.count();</code></pre>
|
|
|
3178
3163
|
</ul>
|
|
3179
3164
|
<div class="tab-content">
|
|
3180
3165
|
<div class="tab-pane fade show active" id="model-update-esm">
|
|
3181
|
-
<pre><code class="js">import
|
|
3166
|
+
<pre><code class="js">import BookModel from '../models/BookModel';
|
|
3182
3167
|
|
|
3183
|
-
// UPDATE `
|
|
3184
|
-
await
|
|
3185
|
-
{name: 'Jane'},
|
|
3186
|
-
{where: {id: 1}}
|
|
3187
|
-
);</code></pre>
|
|
3168
|
+
// UPDATE `book` SET `title`='Lose Yourself' WHERE `id` = 1;
|
|
3169
|
+
await BookModel.update({title: 'Lose Yourself'}, {where: {id: 1}});</code></pre>
|
|
3188
3170
|
</div>
|
|
3189
3171
|
<div class="tab-pane fade" id="model-update-cjs">
|
|
3190
|
-
<pre><code class="js">const
|
|
3172
|
+
<pre><code class="js">const BookModel = require('../models/BookModel');
|
|
3191
3173
|
|
|
3192
|
-
// UPDATE `
|
|
3193
|
-
await
|
|
3194
|
-
{name: 'Jane'},
|
|
3195
|
-
{where: {id: 1}}
|
|
3196
|
-
);</code></pre>
|
|
3174
|
+
// UPDATE `book` SET `title`='Lose Yourself' WHERE `id` = 1;
|
|
3175
|
+
await BookModel.update({title: 'Lose Yourself'}, {where: {id: 1}});</code></pre>
|
|
3197
3176
|
</div>
|
|
3198
3177
|
</div>
|
|
3199
3178
|
</div>
|
|
@@ -3228,26 +3207,16 @@ await UserModel.update(
|
|
|
3228
3207
|
</ul>
|
|
3229
3208
|
<div class="tab-content">
|
|
3230
3209
|
<div class="tab-pane fade show active" id="model-upsert-esm">
|
|
3231
|
-
<pre><code class="js">import
|
|
3210
|
+
<pre><code class="js">import BookModel from '../models/BookModel';
|
|
3232
3211
|
|
|
3233
|
-
// INSERT INTO `
|
|
3234
|
-
|
|
3235
|
-
await UserModel.upsert({
|
|
3236
|
-
email: 'robin@example.com',
|
|
3237
|
-
password: 'password',
|
|
3238
|
-
name: 'Robin'
|
|
3239
|
-
});</code></pre>
|
|
3212
|
+
// INSERT INTO `book` (`title`) VALUES (?) ON DUPLICATE KEY UPDATE `title`=VALUES(`title`);
|
|
3213
|
+
await BookModel.upsert({title: 'Lose Yourself'});</code></pre>
|
|
3240
3214
|
</div>
|
|
3241
3215
|
<div class="tab-pane fade" id="model-upsert-cjs">
|
|
3242
|
-
<pre><code class="js">const
|
|
3216
|
+
<pre><code class="js">const BookModel = require('../models/BookModel');
|
|
3243
3217
|
|
|
3244
|
-
// INSERT INTO `
|
|
3245
|
-
|
|
3246
|
-
await UserModel.upsert({
|
|
3247
|
-
email: 'robin@example.com',
|
|
3248
|
-
password: 'password',
|
|
3249
|
-
name: 'Robin'
|
|
3250
|
-
});</code></pre>
|
|
3218
|
+
// INSERT INTO `book` (`title`) VALUES (?) ON DUPLICATE KEY UPDATE `title`=VALUES(`title`);
|
|
3219
|
+
await BookModel.upsert({title: 'Lose Yourself'});</code></pre>
|
|
3251
3220
|
</div>
|
|
3252
3221
|
</div>
|
|
3253
3222
|
</div>
|
|
@@ -3278,16 +3247,16 @@ await UserModel.upsert({
|
|
|
3278
3247
|
</ul>
|
|
3279
3248
|
<div class="tab-content">
|
|
3280
3249
|
<div class="tab-pane fade show active" id="model-destroy-esm">
|
|
3281
|
-
<pre><code class="js">import
|
|
3250
|
+
<pre><code class="js">import BookModel from '../models/BookModel';
|
|
3282
3251
|
|
|
3283
3252
|
// DELETE FROM `user` WHERE `id` = 1;
|
|
3284
|
-
await
|
|
3253
|
+
await BookModel.destroy({where: {id :1}});</code></pre>
|
|
3285
3254
|
</div>
|
|
3286
3255
|
<div class="tab-pane fade" id="model-destroy-cjs">
|
|
3287
|
-
<pre><code class="js">const
|
|
3256
|
+
<pre><code class="js">const BookModel = require('../models/BookModel');
|
|
3288
3257
|
|
|
3289
3258
|
// DELETE FROM `user` WHERE `id` = 1;
|
|
3290
|
-
await
|
|
3259
|
+
await BookModel.destroy({where: {id :1}});</code></pre>
|
|
3291
3260
|
</div>
|
|
3292
3261
|
</div>
|
|
3293
3262
|
</div>
|
|
@@ -3863,11 +3832,11 @@ module.exports = class extends Model {
|
|
|
3863
3832
|
// "books": [
|
|
3864
3833
|
// {
|
|
3865
3834
|
// "userId": 1,
|
|
3866
|
-
// "title": "
|
|
3835
|
+
// "title": "When Im Gone"
|
|
3867
3836
|
// },
|
|
3868
3837
|
// {
|
|
3869
3838
|
// "userId": 1,
|
|
3870
|
-
// "title": "
|
|
3839
|
+
// "title": "Lose Yourself"
|
|
3871
3840
|
// }
|
|
3872
3841
|
// ]
|
|
3873
3842
|
// }
|
|
@@ -3900,11 +3869,11 @@ await UserModel.findAll({
|
|
|
3900
3869
|
// "books": [
|
|
3901
3870
|
// {
|
|
3902
3871
|
// "userId": 1,
|
|
3903
|
-
// "title": "
|
|
3872
|
+
// "title": "When Im Gone"
|
|
3904
3873
|
// },
|
|
3905
3874
|
// {
|
|
3906
3875
|
// "userId": 1,
|
|
3907
|
-
// "title": "
|
|
3876
|
+
// "title": "Lose Yourself"
|
|
3908
3877
|
// }
|
|
3909
3878
|
// ]
|
|
3910
3879
|
// }
|
|
@@ -3935,11 +3904,11 @@ await UserModel.findAll({
|
|
|
3935
3904
|
<p class="fw-bolder mb-0">Example:</p>
|
|
3936
3905
|
<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
3906
|
// Note that since this is a raw query, the metadata are dialect specific.
|
|
3938
|
-
const [results, metadata] = await
|
|
3907
|
+
const [results, metadata] = await BookModel.query("UPDATE book SET title = 'Lose Yourself' WHERE id = 1");
|
|
3939
3908
|
|
|
3940
3909
|
// 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
3910
|
// We didn't need to destructure the result here - the results were returned directly
|
|
3942
|
-
|
|
3911
|
+
await BookModel.query("SELECT * FROM book", {type: BookModel.QueryTypes.SELECT});</code></pre>
|
|
3943
3912
|
</td>
|
|
3944
3913
|
</tr>
|
|
3945
3914
|
</tbody>
|
|
@@ -4434,11 +4403,11 @@ const client = new sweet.services.AWSRekognitionClient({
|
|
|
4434
4403
|
try {
|
|
4435
4404
|
// Creates a collection.
|
|
4436
4405
|
await client.createCollection('MyCollection');
|
|
4437
|
-
} catch
|
|
4406
|
+
} catch(err) {
|
|
4438
4407
|
// You can get the resulting HTTP status code from the exception.
|
|
4439
|
-
console.log(`name: ${
|
|
4440
|
-
console.log(`statusCode: ${
|
|
4441
|
-
console.log(`message: ${
|
|
4408
|
+
console.log(`name: ${err.name}`);
|
|
4409
|
+
console.log(`statusCode: ${err.statusCode}`);
|
|
4410
|
+
console.log(`message: ${err.message}`);
|
|
4442
4411
|
}</code></pre>
|
|
4443
4412
|
</div>
|
|
4444
4413
|
<div class="tab-pane fade" id="rekog-method-create-collection-cjs">
|
|
@@ -4453,11 +4422,11 @@ const client = new AWSRekognitionClient({
|
|
|
4453
4422
|
try {
|
|
4454
4423
|
// Creates a collection.
|
|
4455
4424
|
await client.createCollection('MyCollection');
|
|
4456
|
-
} catch
|
|
4425
|
+
} catch(err) {
|
|
4457
4426
|
// You can get the resulting HTTP status code from the exception.
|
|
4458
|
-
console.log(`name: ${
|
|
4459
|
-
console.log(`statusCode: ${
|
|
4460
|
-
console.log(`message: ${
|
|
4427
|
+
console.log(`name: ${err.name}`);
|
|
4428
|
+
console.log(`statusCode: ${err.statusCode}`);
|
|
4429
|
+
console.log(`message: ${err.message}`);
|
|
4461
4430
|
}</code></pre>
|
|
4462
4431
|
</div>
|
|
4463
4432
|
</div>
|
|
@@ -4633,11 +4602,11 @@ const faceId = await client.indexFace('MyCollection', fs.readFileSync(
|
|
|
4633
4602
|
// message: No face was found in the image
|
|
4634
4603
|
try {
|
|
4635
4604
|
await client.indexFace('MyCollection', 'img.jpg');
|
|
4636
|
-
} catch
|
|
4605
|
+
} catch(err) {
|
|
4637
4606
|
// You can get the resulting HTTP status code from the exception.
|
|
4638
|
-
console.log(`name: ${
|
|
4639
|
-
console.log(`statusCode: ${
|
|
4640
|
-
console.log(`message: ${
|
|
4607
|
+
console.log(`name: ${err.name}`);
|
|
4608
|
+
console.log(`statusCode: ${err.statusCode}`);
|
|
4609
|
+
console.log(`message: ${err.message}`);
|
|
4641
4610
|
}
|
|
4642
4611
|
|
|
4643
4612
|
// If multiple faces are found in the image, throw an error.
|
|
@@ -4646,11 +4615,11 @@ try {
|
|
|
4646
4615
|
// message: Multiple faces found in the image
|
|
4647
4616
|
try {
|
|
4648
4617
|
await client.indexFace('MyCollection', 'img.jpg');
|
|
4649
|
-
} catch
|
|
4618
|
+
} catch(err) {
|
|
4650
4619
|
// You can get the resulting HTTP status code from the exception.
|
|
4651
|
-
console.log(`name: ${
|
|
4652
|
-
console.log(`statusCode: ${
|
|
4653
|
-
console.log(`message: ${
|
|
4620
|
+
console.log(`name: ${err.name}`);
|
|
4621
|
+
console.log(`statusCode: ${err.statusCode}`);
|
|
4622
|
+
console.log(`message: ${err.message}`);
|
|
4654
4623
|
}</code></pre>
|
|
4655
4624
|
</div>
|
|
4656
4625
|
<div class="tab-pane fade" id="rekog-method-index-face-cjs">
|
|
@@ -4678,11 +4647,11 @@ const faceId = await client.indexFace('MyCollection', fs.readFileSync(
|
|
|
4678
4647
|
// message: No face was found in the image
|
|
4679
4648
|
try {
|
|
4680
4649
|
await client.indexFace('MyCollection', 'img.jpg');
|
|
4681
|
-
} catch
|
|
4650
|
+
} catch(err) {
|
|
4682
4651
|
// You can get the resulting HTTP status code from the exception.
|
|
4683
|
-
console.log(`name: ${
|
|
4684
|
-
console.log(`statusCode: ${
|
|
4685
|
-
console.log(`message: ${
|
|
4652
|
+
console.log(`name: ${err.name}`);
|
|
4653
|
+
console.log(`statusCode: ${err.statusCode}`);
|
|
4654
|
+
console.log(`message: ${err.message}`);
|
|
4686
4655
|
}
|
|
4687
4656
|
|
|
4688
4657
|
// If multiple faces are found in the image, throw an error.
|
|
@@ -4691,11 +4660,11 @@ try {
|
|
|
4691
4660
|
// message: Multiple faces found in the image
|
|
4692
4661
|
try {
|
|
4693
4662
|
await client.indexFace('MyCollection', 'img.jpg');
|
|
4694
|
-
} catch
|
|
4663
|
+
} catch(err) {
|
|
4695
4664
|
// You can get the resulting HTTP status code from the exception.
|
|
4696
|
-
console.log(`name: ${
|
|
4697
|
-
console.log(`statusCode: ${
|
|
4698
|
-
console.log(`message: ${
|
|
4665
|
+
console.log(`name: ${err.name}`);
|
|
4666
|
+
console.log(`statusCode: ${err.statusCode}`);
|
|
4667
|
+
console.log(`message: ${err.message}`);
|
|
4699
4668
|
}</code></pre>
|
|
4700
4669
|
</div>
|
|
4701
4670
|
</div>
|
|
@@ -5063,7 +5032,7 @@ await client.deleteFaces('MyCollection', ['f7befa24-3b83-43cc-b21
|
|
|
5063
5032
|
|
|
5064
5033
|
<script src="https://code.jquery.com/jquery-3.6.0.slim.min.js" integrity="sha256-u7e5khyithlIdTpu22PHhENmPcRdFiHRjhAuHcs05RI=" crossorigin="anonymous"></script>
|
|
5065
5034
|
<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/
|
|
5035
|
+
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.3.1/highlight.min.js"></script>
|
|
5067
5036
|
<script src="scripts/docs.js"></script>
|
|
5068
5037
|
</body>
|
|
5069
5038
|
</html>
|