express-sweet 4.0.0 → 5.1.0
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 +221 -397
- package/LICENSE +1 -1
- package/README.md +210 -1174
- package/dist/build.cjs +32 -73
- package/dist/build.mjs +32 -73
- package/package.json +45 -61
- package/screenshots/avatar.png +0 -0
- package/screenshots/edit-profile.png +0 -0
- package/screenshots/hero-banner.png +0 -0
- package/screenshots/home.png +0 -0
- package/screenshots/mount-flow.mmd +11 -0
- package/screenshots/mount-flow.png +0 -0
- package/screenshots/new-person.png +0 -0
- package/screenshots/people.png +0 -0
- package/screenshots/sign-in.png +0 -0
- package/types/database/DatabaseManager.d.ts +15 -10
- package/types/database/Model.d.ts +29 -43
- package/types/database/index.d.ts +0 -1
- package/types/database/loadModels.d.ts +7 -13
- package/types/helpers/array.d.ts +21 -0
- package/types/helpers/comparison.d.ts +217 -0
- package/types/helpers/date.d.ts +20 -0
- package/types/helpers/html.d.ts +35 -0
- package/types/{handlebars_helpers → helpers}/index.d.ts +0 -2
- package/types/helpers/layouts.d.ts +29 -0
- package/types/helpers/math.d.ts +85 -0
- package/types/helpers/number.d.ts +19 -0
- package/types/helpers/object.d.ts +28 -0
- package/types/helpers/string.d.ts +45 -0
- package/types/index.d.ts +6 -9
- package/types/middleware/auth.d.ts +186 -0
- package/types/middleware/cors.d.ts +19 -0
- package/types/middleware/env.d.ts +40 -0
- package/types/middleware/error.d.ts +26 -0
- package/types/middleware/globals.d.ts +13 -0
- package/types/{middlewares → middleware}/index.d.ts +12 -13
- package/types/middleware/locals.d.ts +33 -0
- package/types/middleware/parser.d.ts +30 -0
- package/types/middleware/router.d.ts +31 -0
- package/types/middleware/views.d.ts +37 -0
- package/types/mount.d.ts +2 -3
- package/types/{interfaces → types}/AppConfig.d.ts +29 -18
- package/types/{interfaces → types}/AuthenticationConfig.d.ts +10 -11
- package/types/{interfaces → types}/DatabaseConfig.d.ts +0 -1
- package/types/{interfaces → types}/LoggingConfig.d.ts +0 -1
- package/types/{interfaces → types}/UploadConfig.d.ts +0 -1
- package/types/{interfaces → types}/ViewConfig.d.ts +1 -2
- package/types/{interfaces → types}/index.d.ts +1 -2
- package/types/utils/index.d.ts +0 -1
- package/types/utils/loadAppConfig.d.ts +1 -1
- package/types/utils/loadAuthenticationConfig.d.ts +1 -1
- package/types/utils/loadLoggingConfig.d.ts +1 -1
- package/types/utils/loadUploadConfig.d.ts +1 -1
- package/types/utils/loadViewConfig.d.ts +1 -1
- package/configuration_sample/cjs/authentication.js +0 -138
- package/configuration_sample/cjs/config.js +0 -92
- package/configuration_sample/cjs/database.js +0 -121
- package/configuration_sample/cjs/logging.js +0 -41
- package/configuration_sample/cjs/upload.js +0 -91
- package/configuration_sample/cjs/view.js +0 -54
- package/configuration_sample/esm/authentication.js +0 -136
- package/configuration_sample/esm/config.js +0 -92
- package/configuration_sample/esm/database.js +0 -121
- package/configuration_sample/esm/logging.js +0 -41
- package/configuration_sample/esm/upload.js +0 -91
- package/configuration_sample/esm/view.js +0 -54
- package/screencaps/belongs-to-many.png +0 -0
- package/screencaps/belongs-to.png +0 -0
- package/screencaps/demonstration.webp +0 -0
- package/screencaps/has-many.png +0 -0
- package/screencaps/has-one.png +0 -0
- package/types/handlebars_helpers/array.d.ts +0 -22
- package/types/handlebars_helpers/comparison.d.ts +0 -222
- package/types/handlebars_helpers/date.d.ts +0 -19
- package/types/handlebars_helpers/html.d.ts +0 -31
- package/types/handlebars_helpers/layouts.d.ts +0 -25
- package/types/handlebars_helpers/math.d.ts +0 -74
- package/types/handlebars_helpers/number.d.ts +0 -18
- package/types/handlebars_helpers/object.d.ts +0 -21
- package/types/handlebars_helpers/string.d.ts +0 -45
- package/types/middlewares/corsPolicy.d.ts +0 -28
- package/types/middlewares/envLoader.d.ts +0 -34
- package/types/middlewares/errorHandler.d.ts +0 -32
- package/types/middlewares/globalVars.d.ts +0 -25
- package/types/middlewares/localVars.d.ts +0 -44
- package/types/middlewares/passportAuth.d.ts +0 -15
- package/types/middlewares/requestParser.d.ts +0 -27
- package/types/middlewares/routeMapper.d.ts +0 -54
- package/types/middlewares/viewEngine.d.ts +0 -49
- package/types/services/Authentication.d.ts +0 -95
- package/types/services/index.d.ts +0 -33
- package/types/types/global.d.ts +0 -38
- package/types/utils/Types.d.ts +0 -29
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "express-sweet",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "5.1.0",
|
|
4
|
+
"description": "Express.js, supercharged. Auth, ORM, routing, views — everything snaps together so you can ship fast and stay sharp.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/build.cjs",
|
|
7
7
|
"module": "dist/build.mjs",
|
|
@@ -15,99 +15,83 @@
|
|
|
15
15
|
"files": [
|
|
16
16
|
"dist/",
|
|
17
17
|
"types/",
|
|
18
|
-
"
|
|
19
|
-
"LICENSE",
|
|
20
|
-
"package.json",
|
|
18
|
+
"screenshots/",
|
|
21
19
|
"README.md",
|
|
22
|
-
"
|
|
23
|
-
"
|
|
20
|
+
"CHANGELOG.md",
|
|
21
|
+
"LICENSE"
|
|
24
22
|
],
|
|
25
23
|
"scripts": {
|
|
26
24
|
"build": "node --max-old-space-size=8192 node_modules/rollup/dist/bin/rollup -c rollup.config.js",
|
|
27
25
|
"prebuild": "rm -rf dist types",
|
|
28
|
-
"
|
|
29
|
-
"watch": "node --max-old-space-size=8192 node_modules/rollup/dist/bin/rollup -c rollup.config.js --watch",
|
|
30
|
-
"docs:build": "typedoc",
|
|
31
|
-
"docs:clean": "rm -rf docs",
|
|
32
|
-
"docs:watch": "typedoc --watch",
|
|
33
|
-
"docs:serve": "typedoc && npx serve docs -p 8080"
|
|
26
|
+
"diagram": "npx -y @mermaid-js/mermaid-cli -i screenshots/mount-flow.mmd -o screenshots/mount-flow.png -b transparent"
|
|
34
27
|
},
|
|
35
28
|
"repository": {
|
|
36
29
|
"type": "git",
|
|
37
|
-
"url": "git+https://github.com/
|
|
30
|
+
"url": "git+https://github.com/shumatsumonobu/express-sweet.git"
|
|
38
31
|
},
|
|
39
32
|
"keywords": [
|
|
40
|
-
"nodejs",
|
|
41
33
|
"express",
|
|
42
34
|
"framework",
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
35
|
+
"mvc",
|
|
36
|
+
"routing",
|
|
37
|
+
"middleware",
|
|
38
|
+
"authentication",
|
|
39
|
+
"passport",
|
|
40
|
+
"sequelize",
|
|
41
|
+
"orm",
|
|
42
|
+
"handlebars",
|
|
43
|
+
"session",
|
|
44
|
+
"redis",
|
|
45
|
+
"file-upload",
|
|
52
46
|
"typescript",
|
|
53
|
-
"ts",
|
|
54
47
|
"esm",
|
|
55
|
-
"
|
|
56
|
-
"orm",
|
|
57
|
-
"mysql",
|
|
58
|
-
"mariadb",
|
|
59
|
-
"sqlite",
|
|
60
|
-
"postgresql",
|
|
61
|
-
"postgres",
|
|
62
|
-
"mssql"
|
|
48
|
+
"commonjs"
|
|
63
49
|
],
|
|
64
|
-
"author": "
|
|
50
|
+
"author": "shumatsumonobu <shumatsumonobu@gmail.com> (https://x.com/shumatsumonobu)",
|
|
65
51
|
"license": "MIT",
|
|
66
52
|
"engines": {
|
|
67
53
|
"node": ">=18.0.0"
|
|
68
54
|
},
|
|
69
55
|
"bugs": {
|
|
70
|
-
"url": "https://github.com/
|
|
71
|
-
"email": "
|
|
56
|
+
"url": "https://github.com/shumatsumonobu/express-sweet/issues",
|
|
57
|
+
"email": "shumatsumonobu@gmail.com"
|
|
72
58
|
},
|
|
73
|
-
"homepage": "https://github.com/
|
|
59
|
+
"homepage": "https://github.com/shumatsumonobu/express-sweet#readme",
|
|
74
60
|
"dependencies": {
|
|
75
|
-
"connect-redis": "^
|
|
61
|
+
"connect-redis": "^9.0.0",
|
|
76
62
|
"cookie-parser": "^1.4.7",
|
|
77
|
-
"dotenv": "^
|
|
63
|
+
"dotenv": "^17.3.1",
|
|
78
64
|
"express": "^5.2.1",
|
|
79
|
-
"express-handlebars": "^
|
|
80
|
-
"express-session": "^1.
|
|
81
|
-
"glob": "^
|
|
82
|
-
"http-errors": "~
|
|
83
|
-
"mariadb": "^3.2.3",
|
|
65
|
+
"express-handlebars": "^8.0.6",
|
|
66
|
+
"express-session": "^1.19.0",
|
|
67
|
+
"glob": "^13.0.6",
|
|
68
|
+
"http-errors": "~2.0.1",
|
|
84
69
|
"moment": "^2.30.1",
|
|
85
70
|
"morgan": "^1.10.1",
|
|
86
|
-
"multer": "^2.
|
|
71
|
+
"multer": "^2.1.1",
|
|
87
72
|
"passport": "^0.7.0",
|
|
88
73
|
"passport-local": "^1.0.0",
|
|
89
|
-
"redis": "^
|
|
90
|
-
"sequelize": "^6.37.
|
|
74
|
+
"redis": "^5.11.0",
|
|
75
|
+
"sequelize": "^6.37.8",
|
|
91
76
|
"striptags": "^3.2.0"
|
|
92
77
|
},
|
|
93
78
|
"devDependencies": {
|
|
94
|
-
"@rollup/plugin-commonjs": "^
|
|
79
|
+
"@rollup/plugin-commonjs": "^29.0.2",
|
|
95
80
|
"@rollup/plugin-json": "^6.1.0",
|
|
96
|
-
"@rollup/plugin-node-resolve": "^
|
|
97
|
-
"@rollup/plugin-terser": "^0.
|
|
98
|
-
"@types/cookie-parser": "^1.4.
|
|
81
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
82
|
+
"@rollup/plugin-terser": "^1.0.0",
|
|
83
|
+
"@types/cookie-parser": "^1.4.10",
|
|
99
84
|
"@types/express": "^5.0.6",
|
|
100
85
|
"@types/express-session": "^1.18.2",
|
|
101
|
-
"@types/
|
|
102
|
-
"@types/
|
|
103
|
-
"@types/
|
|
104
|
-
"@types/
|
|
105
|
-
"@types/
|
|
106
|
-
"@types/passport": "^1.0.
|
|
107
|
-
"
|
|
108
|
-
"rollup": "^4.45.1",
|
|
86
|
+
"@types/http-errors": "^2.0.5",
|
|
87
|
+
"@types/morgan": "^1.9.10",
|
|
88
|
+
"@types/multer": "^2.1.0",
|
|
89
|
+
"@types/node": "^25.5.0",
|
|
90
|
+
"@types/passport": "^1.0.17",
|
|
91
|
+
"@types/passport-local": "^1.0.38",
|
|
92
|
+
"rollup": "^4.59.0",
|
|
109
93
|
"rollup-plugin-typescript2": "^0.36.0",
|
|
110
|
-
"
|
|
111
|
-
"typescript": "^5.
|
|
94
|
+
"sqlite3": "^6.0.1",
|
|
95
|
+
"typescript": "^5.9.3"
|
|
112
96
|
}
|
|
113
97
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
flowchart TD
|
|
2
|
+
A["expx.mount(app)"] --> B["Global variables"]
|
|
3
|
+
B --> C[".env file loading & hook_after_env_load\n.env, config/config.js"]
|
|
4
|
+
C --> D["Sequelize model initialization\nconfig/database.js, models/"]
|
|
5
|
+
D --> E["Body parser, cookies, static files, Morgan logging\nconfig/logging.js, public/"]
|
|
6
|
+
E --> F["Handlebars view engine\nconfig/view.js, views/"]
|
|
7
|
+
F --> G["CORS policy\nconfig/config.js"]
|
|
8
|
+
G --> H["Local variables for views"]
|
|
9
|
+
H --> I["Passport.js authentication & session\nconfig/authentication.js"]
|
|
10
|
+
I --> J["File-based URL routing\nconfig/config.js, routes/"]
|
|
11
|
+
J --> K["Error handler\nconfig/config.js, views/errors/"]
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
import sequelize from 'sequelize';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* Singleton manager for the Sequelize database connection.
|
|
4
|
+
*
|
|
5
|
+
* Ensures a single shared Sequelize instance is used across all models and services.
|
|
6
|
+
* The instance is lazily created on the first call to {@link getInstance} and reused thereafter.
|
|
7
|
+
*
|
|
5
8
|
* @example
|
|
6
9
|
* ```js
|
|
7
|
-
*
|
|
8
|
-
*
|
|
10
|
+
* import * as expx from 'express-sweet';
|
|
11
|
+
*
|
|
12
|
+
* // Get the shared Sequelize instance
|
|
13
|
+
* const db = await expx.database.DatabaseManager.getInstance();
|
|
9
14
|
*
|
|
10
|
-
* // Check
|
|
11
|
-
*
|
|
15
|
+
* // Check if the database is reachable
|
|
16
|
+
* if (await expx.database.DatabaseManager.isConnected()) {
|
|
17
|
+
* console.log('Database OK');
|
|
18
|
+
* }
|
|
12
19
|
*
|
|
13
|
-
* //
|
|
14
|
-
*
|
|
20
|
+
* // Graceful shutdown
|
|
21
|
+
* await expx.database.DatabaseManager.close();
|
|
15
22
|
* ```
|
|
16
23
|
*/
|
|
17
24
|
export default class DatabaseManager {
|
|
@@ -54,7 +61,6 @@ export default class DatabaseManager {
|
|
|
54
61
|
* This returns the raw configuration before Sequelize processing.
|
|
55
62
|
* @returns {Promise<object>} Database configuration object containing all loaded options
|
|
56
63
|
* @throws {Error} When configuration loading fails
|
|
57
|
-
* @see {@link https://sequelize.org/docs/v6/other-topics/dialect-specific-things/ | Sequelize Dialect Options}
|
|
58
64
|
* @example
|
|
59
65
|
* ```js
|
|
60
66
|
* const config = await DatabaseManager.getConfig();
|
|
@@ -69,7 +75,6 @@ export default class DatabaseManager {
|
|
|
69
75
|
* This returns the actual options used by the Sequelize instance,
|
|
70
76
|
* which may include defaults and processed values.
|
|
71
77
|
* @returns {Promise<object>} Sequelize runtime options object
|
|
72
|
-
* @see {@link https://sequelize.org/api/v6/class/src/sequelize.js~sequelize#instance-constructor-options | Sequelize Constructor Options}
|
|
73
78
|
* @example
|
|
74
79
|
* ```js
|
|
75
80
|
* const options = await DatabaseManager.getSequelizeOptions();
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import sequelize from 'sequelize';
|
|
2
2
|
declare const Model_base: any;
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Abstract base class for database models, extending Sequelize.Model.
|
|
5
|
+
* Provides convenient access to the shared database connection, query utilities,
|
|
6
|
+
* transaction management, and Sequelize data types.
|
|
7
7
|
*
|
|
8
8
|
* @extends {sequelize.Model}
|
|
9
|
-
* @see {@link https://sequelize.org/api/v6/class/src/model.js~model | Sequelize Model}
|
|
10
9
|
* @example
|
|
11
10
|
* ```js
|
|
12
11
|
* // Creating a custom model
|
|
@@ -74,7 +73,6 @@ export default class Model extends Model_base {
|
|
|
74
73
|
* List of columns in the table accessed by this model.
|
|
75
74
|
* This member must be defined in a subclass.
|
|
76
75
|
* @type {sequelize.ModelAttributes}
|
|
77
|
-
* @see {@link https://sequelize.org/api/v6/variable/index.html#static-variable-DataTypes | Sequelize DataTypes}
|
|
78
76
|
* @example
|
|
79
77
|
* ```js
|
|
80
78
|
* import * as expx from 'express-sweet';
|
|
@@ -109,7 +107,6 @@ export default class Model extends Model_base {
|
|
|
109
107
|
* A convenience class holding commonly used data types.
|
|
110
108
|
* This is an alias for `sequelize.DataTypes`.
|
|
111
109
|
* @type {sequelize.DataTypes}
|
|
112
|
-
* @see {@link https://sequelize.org/api/v6/variable/index.html#static-variable-DataTypes | Sequelize DataTypes}
|
|
113
110
|
* @example
|
|
114
111
|
* ```js
|
|
115
112
|
* {id: this.DataTypes.INTEGER}
|
|
@@ -121,13 +118,12 @@ export default class Model extends Model_base {
|
|
|
121
118
|
/**
|
|
122
119
|
* An enum of query types used by sequelize.query.
|
|
123
120
|
* @type {sequelize.QueryTypes}
|
|
124
|
-
* @see {@link https://sequelize.org/api/v6/variable/index.html#static-variable-QueryTypes | Sequelize QueryTypes}
|
|
125
121
|
*/
|
|
126
122
|
static readonly QueryTypes: {
|
|
127
123
|
[key: string]: string;
|
|
128
124
|
};
|
|
129
125
|
/**
|
|
130
|
-
*
|
|
126
|
+
* Sequelize query operators for building WHERE conditions.
|
|
131
127
|
* @type {sequelize.Op}
|
|
132
128
|
* @example
|
|
133
129
|
* ```js
|
|
@@ -183,11 +179,9 @@ export default class Model extends Model_base {
|
|
|
183
179
|
[key: string]: any;
|
|
184
180
|
};
|
|
185
181
|
/**
|
|
186
|
-
* Creates
|
|
187
|
-
*
|
|
188
|
-
* function, you should use `sequelize.col`, so that the columns are properly interpreted as columns and not a strings.
|
|
182
|
+
* Creates an object representing a database function for use in queries (WHERE, ORDER BY, etc.)
|
|
183
|
+
* and as column default values. Use {@link col} to reference columns within function arguments.
|
|
189
184
|
* @type {sequelize.fn}
|
|
190
|
-
* @see {@link https://sequelize.org/api/v6/class/src/sequelize.js~sequelize#static-method-fn | Sequelize fn}
|
|
191
185
|
* @example
|
|
192
186
|
* ```js
|
|
193
187
|
* import BookModel from '../models/BookModel';
|
|
@@ -201,16 +195,14 @@ export default class Model extends Model_base {
|
|
|
201
195
|
*/
|
|
202
196
|
static readonly fn: (fn: string, ...args: unknown[]) => any;
|
|
203
197
|
/**
|
|
204
|
-
* Creates
|
|
205
|
-
*
|
|
198
|
+
* Creates an object representing a database column reference.
|
|
199
|
+
* Useful with {@link fn} to prevent column names from being escaped as strings.
|
|
206
200
|
* @type {sequelize.col}
|
|
207
|
-
* @see {@link https://sequelize.org/api/v6/class/src/sequelize.js~sequelize#static-method-col | Sequelize col}
|
|
208
201
|
*/
|
|
209
202
|
static readonly col: (col: string) => any;
|
|
210
203
|
/**
|
|
211
|
-
* Creates
|
|
204
|
+
* Creates an object representing a raw SQL literal that will not be escaped.
|
|
212
205
|
* @type {sequelize.literal}
|
|
213
|
-
* @see {@link https://sequelize.org/api/v6/class/src/sequelize.js~sequelize#static-method-literal | Sequelize literal}
|
|
214
206
|
* @example
|
|
215
207
|
* ```js
|
|
216
208
|
* import BookModel from '../models/BookModel';
|
|
@@ -228,10 +220,9 @@ export default class Model extends Model_base {
|
|
|
228
220
|
*/
|
|
229
221
|
static readonly literal: (val: string) => any;
|
|
230
222
|
/**
|
|
231
|
-
*
|
|
232
|
-
* The
|
|
223
|
+
* Creates a WHERE condition comparing an attribute (or function result) against a value.
|
|
224
|
+
* The attribute can be a raw attribute from the model or a Sequelize utility like {@link fn}.
|
|
233
225
|
* @type {sequelize.where}
|
|
234
|
-
* @see {@link https://sequelize.org/api/v6/class/src/sequelize.js~sequelize#static-method-where | Sequelize where}
|
|
235
226
|
* @example
|
|
236
227
|
* ```js
|
|
237
228
|
* import BookModel from '../models/BookModel';
|
|
@@ -249,10 +240,9 @@ export default class Model extends Model_base {
|
|
|
249
240
|
*/
|
|
250
241
|
static readonly where: (attr: sequelize.AttributeType, comparator: string, logic: sequelize.LogicType) => sequelize.Utils.Where;
|
|
251
242
|
/**
|
|
252
|
-
* Reference to
|
|
253
|
-
*
|
|
243
|
+
* Reference to the Sequelize Transaction class.
|
|
244
|
+
* Use this to access isolation level enums and transaction type constants.
|
|
254
245
|
* @type {sequelize.Transaction}
|
|
255
|
-
* @see {@link https://sequelize.org/api/v6/class/src/transaction.js~transaction | Sequelize Transaction}
|
|
256
246
|
* @example
|
|
257
247
|
* ```js
|
|
258
248
|
* BookModel.Transaction.ISOLATION_LEVELS.READ_UNCOMMITTED // "READ UNCOMMITTED"
|
|
@@ -270,11 +260,9 @@ export default class Model extends Model_base {
|
|
|
270
260
|
*/
|
|
271
261
|
static init(): Promise<any>;
|
|
272
262
|
/**
|
|
273
|
-
*
|
|
274
|
-
*
|
|
275
|
-
*
|
|
276
|
-
* This method is called automatically from within the "express-sweet.mount" method, so you don't have to run it yourself.
|
|
277
|
-
* @see {@link https://sequelize.org/api/v6/class/src/associations/base.js~association | Sequelize Associations}
|
|
263
|
+
* Defines associations with other models (hasOne, hasMany, belongsTo, belongsToMany).
|
|
264
|
+
* Override this method in subclasses to declare relationships.
|
|
265
|
+
* Called automatically by `express-sweet.mount()` after all models are initialized.
|
|
278
266
|
* @example
|
|
279
267
|
* ```js
|
|
280
268
|
* import * as expx from 'express-sweet';
|
|
@@ -294,10 +282,9 @@ export default class Model extends Model_base {
|
|
|
294
282
|
*/
|
|
295
283
|
static association(): void;
|
|
296
284
|
/**
|
|
297
|
-
* Starts a
|
|
298
|
-
* @
|
|
299
|
-
* @
|
|
300
|
-
* @returns {Promise<sequelize.Transaction>} Returns a transaction object to identify the transaction being executed.
|
|
285
|
+
* Starts a new database transaction.
|
|
286
|
+
* @param {sequelize.TransactionOptions} options Transaction options (isolation level, type, etc.).
|
|
287
|
+
* @returns {Promise<sequelize.Transaction>} The transaction object for use in subsequent queries.
|
|
301
288
|
* @example
|
|
302
289
|
* ```js
|
|
303
290
|
* // Simple transaction usage example.
|
|
@@ -333,10 +320,10 @@ export default class Model extends Model_base {
|
|
|
333
320
|
*/
|
|
334
321
|
static begin(options?: sequelize.TransactionOptions): Promise<sequelize.Transaction>;
|
|
335
322
|
/**
|
|
336
|
-
*
|
|
337
|
-
*
|
|
338
|
-
* @param {number} id The
|
|
339
|
-
* @returns {Promise<object|null>}
|
|
323
|
+
* Finds a single record by its primary key (`id` column).
|
|
324
|
+
* Convenience wrapper around `findOne({where: {id}, raw: true})`.
|
|
325
|
+
* @param {number} id The primary key value to search for.
|
|
326
|
+
* @returns {Promise<object|null>} The raw record object, or `null` if not found.
|
|
340
327
|
* @example
|
|
341
328
|
* ```js
|
|
342
329
|
* import BookModel from '../models/BookModel';
|
|
@@ -347,13 +334,12 @@ export default class Model extends Model_base {
|
|
|
347
334
|
*/
|
|
348
335
|
static findById(id: number): Promise<{} | null>;
|
|
349
336
|
/**
|
|
350
|
-
*
|
|
351
|
-
*
|
|
352
|
-
*
|
|
353
|
-
* @param {string} sql SQL string.
|
|
354
|
-
* @param {object} options Query options.
|
|
355
|
-
* @returns {Promise<any>}
|
|
356
|
-
* If you are running a type of query where you don't need the metadata, for example a SELECT query, you can pass in a query type to make sequelize format the results:
|
|
337
|
+
* Executes a raw SQL query against the database.
|
|
338
|
+
* By default returns `[results, metadata]`. Pass a `type` option (e.g., `QueryTypes.SELECT`)
|
|
339
|
+
* to receive formatted results directly.
|
|
340
|
+
* @param {string} sql The SQL query string.
|
|
341
|
+
* @param {object} options Query options including query type, replacements, etc.
|
|
342
|
+
* @returns {Promise<any>} Query results (format depends on the `type` option).
|
|
357
343
|
* @example
|
|
358
344
|
* ```js
|
|
359
345
|
* // By default the function will return two arguments - a results array, and an object containing metadata (such as amount of affected rows, etc).
|
|
@@ -1,23 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* Loads all model files from the models/ directory, initializes them, then sets up associations.
|
|
4
|
-
* All models must be pre-loaded before associating to prevent circular dependency issues.
|
|
5
|
-
* @returns {Promise<void>}
|
|
6
|
-
* @example
|
|
7
|
-
* ```js
|
|
8
|
-
* // This function is called automatically by express-sweet.mount()
|
|
9
|
-
* import loadModels from '~/database/loadModels';
|
|
10
|
-
* await loadModels();
|
|
11
|
-
* ```
|
|
2
|
+
* Loads, initializes, and associates all Sequelize models from the `models/` directory.
|
|
12
3
|
*
|
|
4
|
+
* All models are initialized first, then associations are set up in a separate pass.
|
|
5
|
+
* This two-phase approach prevents circular dependency errors when models reference each other.
|
|
6
|
+
*
|
|
7
|
+
* @returns {Promise<void>}
|
|
13
8
|
* @example
|
|
14
9
|
* ```bash
|
|
15
|
-
*
|
|
10
|
+
* # Expected directory structure
|
|
16
11
|
* models/
|
|
17
12
|
* ├── UserModel.js
|
|
18
13
|
* ├── ProfileModel.js
|
|
19
14
|
* └── BookModel.js
|
|
20
15
|
* ```
|
|
21
16
|
*/
|
|
22
|
-
|
|
23
|
-
export default _default;
|
|
17
|
+
export default function loadModels(): Promise<void>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finds the first object in an array whose specified field matches the given value.
|
|
3
|
+
* Returns `null` if no match is found or if parameters are invalid.
|
|
4
|
+
* @param {Array<{[key: string]: any}>} array The array of objects to search.
|
|
5
|
+
* @param {string} fieldName The property name to match against.
|
|
6
|
+
* @param {*} fieldValue The value to match.
|
|
7
|
+
* @returns {object|null} The first matching object, or `null` if not found.
|
|
8
|
+
* @example
|
|
9
|
+
* ```handlebars
|
|
10
|
+
* {{!-- Look up a category name by its ID --}}
|
|
11
|
+
* {{lookup (findObjectInArray categories 'id' categoryId) 'name'}}
|
|
12
|
+
*
|
|
13
|
+
* {{!-- Use within an each block to cross-reference related data --}}
|
|
14
|
+
* {{#each orders}}
|
|
15
|
+
* {{lookup (findObjectInArray ../users 'id' this.userId) 'name'}}
|
|
16
|
+
* {{/each}}
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare const findObjectInArray: (array: Array<{
|
|
20
|
+
[key: string]: any;
|
|
21
|
+
}>, fieldName: string, fieldValue: any) => object | null;
|