@carbonorm/carbonnode 3.11.0 → 4.0.1
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/README.md +123 -493
- package/dist/api/orm/builders/ConditionBuilder.d.ts +5 -0
- package/dist/api/orm/queries/PostQueryBuilder.d.ts +1 -1
- package/dist/api/restOrm.d.ts +4 -4
- package/dist/api/types/ormInterfaces.d.ts +32 -12
- package/dist/api/utils/cacheManager.d.ts +7 -8
- package/dist/index.cjs.js +289 -140
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +285 -139
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/cacheManager.test.ts +67 -0
- package/src/__tests__/expressServer.e2e.test.ts +104 -2
- package/src/__tests__/fixtures/c6.fixture.ts +2 -0
- package/src/__tests__/httpExecutorSingular.e2e.test.ts +35 -4
- package/src/__tests__/sakila-db/C6.js +1 -1
- package/src/__tests__/sakila-db/C6.ts +1 -1
- package/src/__tests__/sqlBuilders.test.ts +45 -0
- package/src/api/axiosInstance.ts +29 -0
- package/src/api/executors/HttpExecutor.ts +73 -97
- package/src/api/handlers/ExpressHandler.ts +30 -7
- package/src/api/orm/builders/ConditionBuilder.ts +74 -0
- package/src/api/orm/queries/PostQueryBuilder.ts +4 -2
- package/src/api/orm/queries/UpdateQueryBuilder.ts +3 -1
- package/src/api/types/ormInterfaces.ts +32 -18
- package/src/api/utils/cacheManager.ts +75 -34
- package/src/api/utils/testHelpers.ts +5 -3
- package/src/variables/isNode.ts +1 -8
package/README.md
CHANGED
|
@@ -7,12 +7,28 @@
|
|
|
7
7
|

|
|
8
8
|
[](https://github.com/CarbonORM/CarbonNode/actions/workflows/npm-publish-on-bump.yml)
|
|
9
9
|
|
|
10
|
-
# CarbonNode
|
|
10
|
+
# CarbonNode
|
|
11
|
+
|
|
12
|
+
CarbonNode is a part of the CarbonORM series. It is a NodeJS MySQL ORM that can run independently in the backend or paired with
|
|
13
|
+
CarbonReact for 1=1 syntax. Note the CarbonNode + CarbonReact experience is unmatched in interoperability.
|
|
14
|
+
|
|
15
|
+
# Purpose
|
|
16
|
+
|
|
17
|
+
CarbonNode is designed to generate RESTful API bindings for a MySQL database. The generated code provides a simple and
|
|
18
|
+
consistent interface for performing CRUD operations on the database tables. The goal is to reduce the amount of boilerplate
|
|
19
|
+
code needed to interact with the database and to provide a more efficient and reliable way to work with MySQL data in a NodeJS
|
|
20
|
+
environment. The major goals:
|
|
21
|
+
- Allow a 1-1 interoperability when querying data from the frontend to the backend.
|
|
22
|
+
- Language based Objects/Arrays for representing and modifying queries to eliminate string manipulation operations.
|
|
23
|
+
- Explicit column references to allow for easier refactoring and code completion in IDEs.
|
|
24
|
+
- Selecting a dead column will result in a compile time error instead of a runtime error.
|
|
25
|
+
- TypeScript types generated for each table in the database.
|
|
26
|
+
- Lifecycle hooks for each CRUD operation to allow for custom logic to be executed before and after the operation.
|
|
27
|
+
- Validation of data types and formats before executing CRUD operations to ensure data integrity.
|
|
28
|
+
|
|
29
|
+
It's easier to scale your middleware than your database.
|
|
30
|
+
CarbonNode aims to capture issues before they reach your database.
|
|
11
31
|
|
|
12
|
-
CarbonNode is a part of the CarbonORM series. It is a NodeJS MySQL ORM that is designed to work with CarbonPHP. This langauge
|
|
13
|
-
will implement the same ORM as CarbonPHP, but will be written in Typescript. Currently only C6 enabled requests can be sent
|
|
14
|
-
using the bindings. Receiving API requests and handling it appropriately is not yet implemented. This is scheduled for
|
|
15
|
-
early 2024. This repository is in the early stages of development an any support is greatly appreciated.
|
|
16
32
|
|
|
17
33
|
## Alpha Release
|
|
18
34
|
|
|
@@ -70,383 +86,74 @@ generate. Here are the templates used to generate the code:
|
|
|
70
86
|
|
|
71
87
|
0) **npx generateRestBindings** is executed.
|
|
72
88
|
1) **The MySQL dump tool** outputs a strcture for every table.
|
|
73
|
-
```sql
|
|
74
|
-
--
|
|
75
|
-
-- Table structure for table `carbon_users`
|
|
76
|
-
--
|
|
77
|
-
|
|
78
|
-
DROP TABLE IF EXISTS `carbon_users`;
|
|
79
|
-
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
|
80
|
-
/*!50503 SET character_set_client = utf8mb4 */;
|
|
81
|
-
CREATE TABLE `carbon_users` (
|
|
82
|
-
`user_username` varchar(100) NOT NULL,
|
|
83
|
-
`user_password` varchar(225) NOT NULL,
|
|
84
|
-
`user_id` binary(16) NOT NULL,
|
|
85
|
-
`user_type` varchar(20) NOT NULL DEFAULT 'Athlete',
|
|
86
|
-
`user_sport` varchar(20) DEFAULT 'GOLF',
|
|
87
|
-
`user_session_id` varchar(225) DEFAULT NULL,
|
|
88
|
-
`user_facebook_id` varchar(225) DEFAULT NULL,
|
|
89
|
-
`user_first_name` varchar(25) NOT NULL,
|
|
90
|
-
`user_last_name` varchar(25) NOT NULL,
|
|
91
|
-
`user_profile_pic` varchar(225) DEFAULT NULL,
|
|
92
|
-
`user_profile_uri` varchar(225) DEFAULT NULL,
|
|
93
|
-
`user_cover_photo` varchar(225) DEFAULT NULL,
|
|
94
|
-
`user_birthday` varchar(9) DEFAULT NULL,
|
|
95
|
-
`user_gender` varchar(25) DEFAULT NULL,
|
|
96
|
-
`user_about_me` varchar(225) DEFAULT NULL,
|
|
97
|
-
`user_rank` int DEFAULT '0',
|
|
98
|
-
`user_email` varchar(50) NOT NULL,
|
|
99
|
-
`user_email_code` varchar(225) DEFAULT NULL,
|
|
100
|
-
`user_email_confirmed` tinyint DEFAULT '0' COMMENT 'need to change to enums, but no support in rest yet',
|
|
101
|
-
`user_generated_string` varchar(200) DEFAULT NULL,
|
|
102
|
-
`user_membership` int DEFAULT '0',
|
|
103
|
-
`user_deactivated` tinyint DEFAULT '0',
|
|
104
|
-
`user_last_login` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
105
|
-
`user_ip` varchar(20) NOT NULL,
|
|
106
|
-
`user_education_history` varchar(200) DEFAULT NULL,
|
|
107
|
-
`user_location` varchar(20) DEFAULT NULL,
|
|
108
|
-
`user_creation_date` datetime DEFAULT CURRENT_TIMESTAMP,
|
|
109
|
-
PRIMARY KEY (`user_id`),
|
|
110
|
-
UNIQUE KEY `carbon_users_user_username_uindex` (`user_username`),
|
|
111
|
-
UNIQUE KEY `user_user_profile_uri_uindex` (`user_profile_uri`),
|
|
112
|
-
UNIQUE KEY `carbon_users_user_facebook_id_uindex` (`user_facebook_id`),
|
|
113
|
-
CONSTRAINT `user_entity_entity_pk_fk` FOREIGN KEY (`user_id`) REFERENCES `carbon_carbons` (`entity_pk`) ON DELETE CASCADE ON UPDATE CASCADE
|
|
114
|
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
|
|
115
|
-
/*!40101 SET character_set_client = @saved_cs_client */;
|
|
116
|
-
```
|
|
117
|
-
3) **Profit**
|
|
118
|
-
- C6 will produce 1-1 constants.
|
|
119
|
-
```typescript
|
|
120
|
-
export interface iUsers {
|
|
121
|
-
'user_username'?: string;
|
|
122
|
-
'user_password'?: string;
|
|
123
|
-
'user_id'?: string;
|
|
124
|
-
'user_type'?: string;
|
|
125
|
-
'user_sport'?: string | null;
|
|
126
|
-
'user_session_id'?: string | null;
|
|
127
|
-
'user_facebook_id'?: string | null;
|
|
128
|
-
'user_first_name'?: string;
|
|
129
|
-
'user_last_name'?: string;
|
|
130
|
-
'user_profile_pic'?: string | null;
|
|
131
|
-
'user_profile_uri'?: string | null;
|
|
132
|
-
'user_cover_photo'?: string | null;
|
|
133
|
-
'user_birthday'?: string | null;
|
|
134
|
-
'user_gender'?: string | null;
|
|
135
|
-
'user_about_me'?: string | null;
|
|
136
|
-
'user_rank'?: number | null;
|
|
137
|
-
'user_email'?: string;
|
|
138
|
-
'user_email_code'?: string | null;
|
|
139
|
-
'user_email_confirmed'?: number | null;
|
|
140
|
-
'user_generated_string'?: string | null;
|
|
141
|
-
'user_membership'?: number | null;
|
|
142
|
-
'user_deactivated'?: number | null;
|
|
143
|
-
'user_last_login'?: string;
|
|
144
|
-
'user_ip'?: string;
|
|
145
|
-
'user_education_history'?: string | null;
|
|
146
|
-
'user_location'?: string | null;
|
|
147
|
-
'user_creation_date'?: string | null;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
### Derived table joins
|
|
151
89
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
[C6C.SUBSELECT]: {
|
|
162
|
-
[C6C.SELECT]: [Property_Units.LOCATION],
|
|
163
|
-
[C6C.FROM]: Property_Units.TABLE_NAME,
|
|
164
|
-
[C6C.WHERE]: { [Property_Units.UNIT_ID]: [C6C.EQUAL, unitIdParam] },
|
|
165
|
-
[C6C.LIMIT]: 1,
|
|
166
|
-
},
|
|
167
|
-
[C6C.AS]: 'pu_target',
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
const query = {
|
|
171
|
-
[C6C.SELECT]: [
|
|
172
|
-
Property_Units.UNIT_ID,
|
|
173
|
-
Property_Units.LOCATION,
|
|
174
|
-
F(Property_Units.LOCATION, 'pu_target'),
|
|
175
|
-
],
|
|
176
|
-
[C6C.JOIN]: {
|
|
177
|
-
[C6C.INNER]: {
|
|
178
|
-
'parcel_sales ps': { 'ps.parcel_id': [C6C.EQUAL, Property_Units.PARCEL_ID] },
|
|
179
|
-
[puTarget as any]: {},
|
|
180
|
-
},
|
|
181
|
-
},
|
|
182
|
-
[C6C.PAGINATION]: {
|
|
183
|
-
[C6C.ORDER]: {
|
|
184
|
-
[C6C.ST_DISTANCE_SPHERE]: [
|
|
185
|
-
Property_Units.LOCATION,
|
|
186
|
-
F(Property_Units.LOCATION, 'pu_target'),
|
|
187
|
-
],
|
|
188
|
-
},
|
|
189
|
-
},
|
|
190
|
-
};
|
|
90
|
+
```mysql
|
|
91
|
+
CREATE TABLE actor (
|
|
92
|
+
actor_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
93
|
+
first_name VARCHAR(45) NOT NULL,
|
|
94
|
+
last_name VARCHAR(45) NOT NULL,
|
|
95
|
+
last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
96
|
+
PRIMARY KEY (actor_id),
|
|
97
|
+
KEY idx_actor_last_name (last_name)
|
|
98
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
191
99
|
```
|
|
192
100
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
'
|
|
199
|
-
'USER_PASSWORD': string;
|
|
200
|
-
'USER_ID': string;
|
|
201
|
-
'USER_TYPE': string;
|
|
202
|
-
'USER_SPORT': string;
|
|
203
|
-
'USER_SESSION_ID': string;
|
|
204
|
-
'USER_FACEBOOK_ID': string;
|
|
205
|
-
'USER_FIRST_NAME': string;
|
|
206
|
-
'USER_LAST_NAME': string;
|
|
207
|
-
'USER_PROFILE_PIC': string;
|
|
208
|
-
'USER_PROFILE_URI': string;
|
|
209
|
-
'USER_COVER_PHOTO': string;
|
|
210
|
-
'USER_BIRTHDAY': string;
|
|
211
|
-
'USER_GENDER': string;
|
|
212
|
-
'USER_ABOUT_ME': string;
|
|
213
|
-
'USER_RANK': string;
|
|
214
|
-
'USER_EMAIL': string;
|
|
215
|
-
'USER_EMAIL_CODE': string;
|
|
216
|
-
'USER_EMAIL_CONFIRMED': string;
|
|
217
|
-
'USER_GENERATED_STRING': string;
|
|
218
|
-
'USER_MEMBERSHIP': string;
|
|
219
|
-
'USER_DEACTIVATED': string;
|
|
220
|
-
'USER_LAST_LOGIN': string;
|
|
221
|
-
'USER_IP': string;
|
|
222
|
-
'USER_EDUCATION_HISTORY': string;
|
|
223
|
-
'USER_LOCATION': string;
|
|
224
|
-
'USER_CREATION_DATE': string;
|
|
101
|
+
```typescript
|
|
102
|
+
export interface iActor {
|
|
103
|
+
'actor_id'?: number;
|
|
104
|
+
'first_name'?: string;
|
|
105
|
+
'last_name'?: string;
|
|
106
|
+
'last_update'?: Date | number | string;
|
|
225
107
|
}
|
|
226
108
|
|
|
227
|
-
export
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
USER_GENDER: 'carbon_users.user_gender',
|
|
243
|
-
USER_ABOUT_ME: 'carbon_users.user_about_me',
|
|
244
|
-
USER_RANK: 'carbon_users.user_rank',
|
|
245
|
-
USER_EMAIL: 'carbon_users.user_email',
|
|
246
|
-
USER_EMAIL_CODE: 'carbon_users.user_email_code',
|
|
247
|
-
USER_EMAIL_CONFIRMED: 'carbon_users.user_email_confirmed',
|
|
248
|
-
USER_GENERATED_STRING: 'carbon_users.user_generated_string',
|
|
249
|
-
USER_MEMBERSHIP: 'carbon_users.user_membership',
|
|
250
|
-
USER_DEACTIVATED: 'carbon_users.user_deactivated',
|
|
251
|
-
USER_LAST_LOGIN: 'carbon_users.user_last_login',
|
|
252
|
-
USER_IP: 'carbon_users.user_ip',
|
|
253
|
-
USER_EDUCATION_HISTORY: 'carbon_users.user_education_history',
|
|
254
|
-
USER_LOCATION: 'carbon_users.user_location',
|
|
255
|
-
USER_CREATION_DATE: 'carbon_users.user_creation_date',
|
|
109
|
+
export type ActorPrimaryKeys =
|
|
110
|
+
'actor_id'
|
|
111
|
+
;
|
|
112
|
+
|
|
113
|
+
const actor:
|
|
114
|
+
C6RestfulModel<
|
|
115
|
+
'actor',
|
|
116
|
+
iActor,
|
|
117
|
+
ActorPrimaryKeys
|
|
118
|
+
> = {
|
|
119
|
+
TABLE_NAME: 'actor',
|
|
120
|
+
ACTOR_ID: 'actor.actor_id',
|
|
121
|
+
FIRST_NAME: 'actor.first_name',
|
|
122
|
+
LAST_NAME: 'actor.last_name',
|
|
123
|
+
LAST_UPDATE: 'actor.last_update',
|
|
256
124
|
PRIMARY: [
|
|
257
|
-
'
|
|
125
|
+
'actor.actor_id',
|
|
258
126
|
],
|
|
259
127
|
PRIMARY_SHORT: [
|
|
260
|
-
'
|
|
128
|
+
'actor_id',
|
|
261
129
|
],
|
|
262
130
|
COLUMNS: {
|
|
263
|
-
'
|
|
264
|
-
'
|
|
265
|
-
'
|
|
266
|
-
'
|
|
267
|
-
'carbon_users.user_sport': 'user_sport',
|
|
268
|
-
'carbon_users.user_session_id': 'user_session_id',
|
|
269
|
-
'carbon_users.user_facebook_id': 'user_facebook_id',
|
|
270
|
-
'carbon_users.user_first_name': 'user_first_name',
|
|
271
|
-
'carbon_users.user_last_name': 'user_last_name',
|
|
272
|
-
'carbon_users.user_profile_pic': 'user_profile_pic',
|
|
273
|
-
'carbon_users.user_profile_uri': 'user_profile_uri',
|
|
274
|
-
'carbon_users.user_cover_photo': 'user_cover_photo',
|
|
275
|
-
'carbon_users.user_birthday': 'user_birthday',
|
|
276
|
-
'carbon_users.user_gender': 'user_gender',
|
|
277
|
-
'carbon_users.user_about_me': 'user_about_me',
|
|
278
|
-
'carbon_users.user_rank': 'user_rank',
|
|
279
|
-
'carbon_users.user_email': 'user_email',
|
|
280
|
-
'carbon_users.user_email_code': 'user_email_code',
|
|
281
|
-
'carbon_users.user_email_confirmed': 'user_email_confirmed',
|
|
282
|
-
'carbon_users.user_generated_string': 'user_generated_string',
|
|
283
|
-
'carbon_users.user_membership': 'user_membership',
|
|
284
|
-
'carbon_users.user_deactivated': 'user_deactivated',
|
|
285
|
-
'carbon_users.user_last_login': 'user_last_login',
|
|
286
|
-
'carbon_users.user_ip': 'user_ip',
|
|
287
|
-
'carbon_users.user_education_history': 'user_education_history',
|
|
288
|
-
'carbon_users.user_location': 'user_location',
|
|
289
|
-
'carbon_users.user_creation_date': 'user_creation_date',
|
|
131
|
+
'actor.actor_id': 'actor_id',
|
|
132
|
+
'actor.first_name': 'first_name',
|
|
133
|
+
'actor.last_name': 'last_name',
|
|
134
|
+
'actor.last_update': 'last_update',
|
|
290
135
|
},
|
|
291
136
|
TYPE_VALIDATION: {
|
|
292
|
-
'
|
|
293
|
-
MYSQL_TYPE: '
|
|
294
|
-
MAX_LENGTH: '100',
|
|
295
|
-
AUTO_INCREMENT: false,
|
|
296
|
-
SKIP_COLUMN_IN_POST: false
|
|
297
|
-
},
|
|
298
|
-
'carbon_users.user_password': {
|
|
299
|
-
MYSQL_TYPE: 'varchar',
|
|
300
|
-
MAX_LENGTH: '225',
|
|
301
|
-
AUTO_INCREMENT: false,
|
|
302
|
-
SKIP_COLUMN_IN_POST: false
|
|
303
|
-
},
|
|
304
|
-
'carbon_users.user_id': {
|
|
305
|
-
MYSQL_TYPE: 'binary',
|
|
306
|
-
MAX_LENGTH: '16',
|
|
307
|
-
AUTO_INCREMENT: false,
|
|
308
|
-
SKIP_COLUMN_IN_POST: false
|
|
309
|
-
},
|
|
310
|
-
'carbon_users.user_type': {
|
|
311
|
-
MYSQL_TYPE: 'varchar',
|
|
312
|
-
MAX_LENGTH: '20',
|
|
313
|
-
AUTO_INCREMENT: false,
|
|
314
|
-
SKIP_COLUMN_IN_POST: false
|
|
315
|
-
},
|
|
316
|
-
'carbon_users.user_sport': {
|
|
317
|
-
MYSQL_TYPE: 'varchar',
|
|
318
|
-
MAX_LENGTH: '20',
|
|
319
|
-
AUTO_INCREMENT: false,
|
|
320
|
-
SKIP_COLUMN_IN_POST: false
|
|
321
|
-
},
|
|
322
|
-
'carbon_users.user_session_id': {
|
|
323
|
-
MYSQL_TYPE: 'varchar',
|
|
324
|
-
MAX_LENGTH: '225',
|
|
325
|
-
AUTO_INCREMENT: false,
|
|
326
|
-
SKIP_COLUMN_IN_POST: false
|
|
327
|
-
},
|
|
328
|
-
'carbon_users.user_facebook_id': {
|
|
329
|
-
MYSQL_TYPE: 'varchar',
|
|
330
|
-
MAX_LENGTH: '225',
|
|
331
|
-
AUTO_INCREMENT: false,
|
|
332
|
-
SKIP_COLUMN_IN_POST: false
|
|
333
|
-
},
|
|
334
|
-
'carbon_users.user_first_name': {
|
|
335
|
-
MYSQL_TYPE: 'varchar',
|
|
336
|
-
MAX_LENGTH: '25',
|
|
337
|
-
AUTO_INCREMENT: false,
|
|
338
|
-
SKIP_COLUMN_IN_POST: false
|
|
339
|
-
},
|
|
340
|
-
'carbon_users.user_last_name': {
|
|
341
|
-
MYSQL_TYPE: 'varchar',
|
|
342
|
-
MAX_LENGTH: '25',
|
|
343
|
-
AUTO_INCREMENT: false,
|
|
344
|
-
SKIP_COLUMN_IN_POST: false
|
|
345
|
-
},
|
|
346
|
-
'carbon_users.user_profile_pic': {
|
|
347
|
-
MYSQL_TYPE: 'varchar',
|
|
348
|
-
MAX_LENGTH: '225',
|
|
349
|
-
AUTO_INCREMENT: false,
|
|
350
|
-
SKIP_COLUMN_IN_POST: false
|
|
351
|
-
},
|
|
352
|
-
'carbon_users.user_profile_uri': {
|
|
353
|
-
MYSQL_TYPE: 'varchar',
|
|
354
|
-
MAX_LENGTH: '225',
|
|
355
|
-
AUTO_INCREMENT: false,
|
|
356
|
-
SKIP_COLUMN_IN_POST: false
|
|
357
|
-
},
|
|
358
|
-
'carbon_users.user_cover_photo': {
|
|
359
|
-
MYSQL_TYPE: 'varchar',
|
|
360
|
-
MAX_LENGTH: '225',
|
|
361
|
-
AUTO_INCREMENT: false,
|
|
362
|
-
SKIP_COLUMN_IN_POST: false
|
|
363
|
-
},
|
|
364
|
-
'carbon_users.user_birthday': {
|
|
365
|
-
MYSQL_TYPE: 'varchar',
|
|
366
|
-
MAX_LENGTH: '9',
|
|
367
|
-
AUTO_INCREMENT: false,
|
|
368
|
-
SKIP_COLUMN_IN_POST: false
|
|
369
|
-
},
|
|
370
|
-
'carbon_users.user_gender': {
|
|
371
|
-
MYSQL_TYPE: 'varchar',
|
|
372
|
-
MAX_LENGTH: '25',
|
|
373
|
-
AUTO_INCREMENT: false,
|
|
374
|
-
SKIP_COLUMN_IN_POST: false
|
|
375
|
-
},
|
|
376
|
-
'carbon_users.user_about_me': {
|
|
377
|
-
MYSQL_TYPE: 'varchar',
|
|
378
|
-
MAX_LENGTH: '225',
|
|
379
|
-
AUTO_INCREMENT: false,
|
|
380
|
-
SKIP_COLUMN_IN_POST: false
|
|
381
|
-
},
|
|
382
|
-
'carbon_users.user_rank': {
|
|
383
|
-
MYSQL_TYPE: 'int',
|
|
137
|
+
'actor.actor_id': {
|
|
138
|
+
MYSQL_TYPE: 'smallint',
|
|
384
139
|
MAX_LENGTH: '',
|
|
385
|
-
AUTO_INCREMENT:
|
|
386
|
-
SKIP_COLUMN_IN_POST: false
|
|
387
|
-
},
|
|
388
|
-
'carbon_users.user_email': {
|
|
389
|
-
MYSQL_TYPE: 'varchar',
|
|
390
|
-
MAX_LENGTH: '50',
|
|
391
|
-
AUTO_INCREMENT: false,
|
|
140
|
+
AUTO_INCREMENT: true,
|
|
392
141
|
SKIP_COLUMN_IN_POST: false
|
|
393
142
|
},
|
|
394
|
-
'
|
|
143
|
+
'actor.first_name': {
|
|
395
144
|
MYSQL_TYPE: 'varchar',
|
|
396
|
-
MAX_LENGTH: '
|
|
145
|
+
MAX_LENGTH: '45',
|
|
397
146
|
AUTO_INCREMENT: false,
|
|
398
147
|
SKIP_COLUMN_IN_POST: false
|
|
399
148
|
},
|
|
400
|
-
'
|
|
401
|
-
MYSQL_TYPE: 'tinyint',
|
|
402
|
-
MAX_LENGTH: '',
|
|
403
|
-
AUTO_INCREMENT: false,
|
|
404
|
-
SKIP_COLUMN_IN_POST: false
|
|
405
|
-
},
|
|
406
|
-
'carbon_users.user_generated_string': {
|
|
149
|
+
'actor.last_name': {
|
|
407
150
|
MYSQL_TYPE: 'varchar',
|
|
408
|
-
MAX_LENGTH: '
|
|
151
|
+
MAX_LENGTH: '45',
|
|
409
152
|
AUTO_INCREMENT: false,
|
|
410
153
|
SKIP_COLUMN_IN_POST: false
|
|
411
154
|
},
|
|
412
|
-
'
|
|
413
|
-
MYSQL_TYPE: '
|
|
414
|
-
MAX_LENGTH: '',
|
|
415
|
-
AUTO_INCREMENT: false,
|
|
416
|
-
SKIP_COLUMN_IN_POST: false
|
|
417
|
-
},
|
|
418
|
-
'carbon_users.user_deactivated': {
|
|
419
|
-
MYSQL_TYPE: 'tinyint',
|
|
420
|
-
MAX_LENGTH: '',
|
|
421
|
-
AUTO_INCREMENT: false,
|
|
422
|
-
SKIP_COLUMN_IN_POST: false
|
|
423
|
-
},
|
|
424
|
-
'carbon_users.user_last_login': {
|
|
425
|
-
MYSQL_TYPE: 'datetime',
|
|
426
|
-
MAX_LENGTH: '',
|
|
427
|
-
AUTO_INCREMENT: false,
|
|
428
|
-
SKIP_COLUMN_IN_POST: false
|
|
429
|
-
},
|
|
430
|
-
'carbon_users.user_ip': {
|
|
431
|
-
MYSQL_TYPE: 'varchar',
|
|
432
|
-
MAX_LENGTH: '20',
|
|
433
|
-
AUTO_INCREMENT: false,
|
|
434
|
-
SKIP_COLUMN_IN_POST: false
|
|
435
|
-
},
|
|
436
|
-
'carbon_users.user_education_history': {
|
|
437
|
-
MYSQL_TYPE: 'varchar',
|
|
438
|
-
MAX_LENGTH: '200',
|
|
439
|
-
AUTO_INCREMENT: false,
|
|
440
|
-
SKIP_COLUMN_IN_POST: false
|
|
441
|
-
},
|
|
442
|
-
'carbon_users.user_location': {
|
|
443
|
-
MYSQL_TYPE: 'varchar',
|
|
444
|
-
MAX_LENGTH: '20',
|
|
445
|
-
AUTO_INCREMENT: false,
|
|
446
|
-
SKIP_COLUMN_IN_POST: false
|
|
447
|
-
},
|
|
448
|
-
'carbon_users.user_creation_date': {
|
|
449
|
-
MYSQL_TYPE: 'datetime',
|
|
155
|
+
'actor.last_update': {
|
|
156
|
+
MYSQL_TYPE: 'timestamp',
|
|
450
157
|
MAX_LENGTH: '',
|
|
451
158
|
AUTO_INCREMENT: false,
|
|
452
159
|
SKIP_COLUMN_IN_POST: false
|
|
@@ -454,160 +161,83 @@ export const users: iC6RestfulModel<RestTableNames> & iDefineUsers = {
|
|
|
454
161
|
},
|
|
455
162
|
REGEX_VALIDATION: {
|
|
456
163
|
},
|
|
164
|
+
LIFECYCLE_HOOKS: {
|
|
165
|
+
GET: {beforeProcessing:{}, beforeExecution:{}, afterExecution:{}, afterCommit:{}},
|
|
166
|
+
PUT: {beforeProcessing:{}, beforeExecution:{}, afterExecution:{}, afterCommit:{}},
|
|
167
|
+
POST: {beforeProcessing:{}, beforeExecution:{}, afterExecution:{}, afterCommit:{}},
|
|
168
|
+
DELETE: {beforeProcessing:{}, beforeExecution:{}, afterExecution:{}, afterCommit:{}},
|
|
169
|
+
},
|
|
457
170
|
TABLE_REFERENCES: {
|
|
458
|
-
|
|
459
|
-
TABLE: 'carbon_carbons',
|
|
460
|
-
COLUMN: 'entity_pk',
|
|
461
|
-
CONSTRAINT: 'user_entity_entity_pk_fk',
|
|
462
|
-
},],
|
|
171
|
+
|
|
463
172
|
},
|
|
464
173
|
TABLE_REFERENCED_BY: {
|
|
465
|
-
|
|
174
|
+
'actor_id': [{
|
|
175
|
+
TABLE: 'film_actor',
|
|
176
|
+
COLUMN: 'actor_id',
|
|
177
|
+
CONSTRAINT: 'fk_film_actor_actor',
|
|
178
|
+
},],
|
|
466
179
|
}
|
|
467
180
|
}
|
|
468
|
-
```
|
|
469
|
-
- A File named the pascal case formated table name will be created with bindings to query the middleware (backend langague) -> MySQL.
|
|
470
|
-
```typescript
|
|
471
|
-
import {AxiosResponse} from "axios";
|
|
472
|
-
import {
|
|
473
|
-
iPostC6RestResponse,
|
|
474
|
-
restRequest,
|
|
475
|
-
GET,
|
|
476
|
-
POST,
|
|
477
|
-
PUT,
|
|
478
|
-
DELETE,
|
|
479
|
-
iDeleteC6RestResponse,
|
|
480
|
-
iGetC6RestResponse,
|
|
481
|
-
iPutC6RestResponse,
|
|
482
|
-
removeInvalidKeys,
|
|
483
|
-
iAPI,
|
|
484
|
-
Modify
|
|
485
|
-
} from "@carbonorm/carbonnode";
|
|
486
|
-
import {deleteRestfulObjectArrays, updateRestfulObjectArrays} from "@carbonorm/carbonreact";
|
|
487
|
-
import {C6, iUsers, users, RestTableNames} from "./C6";
|
|
488
|
-
|
|
489
|
-
type GetCustomAndRequiredFields = {}
|
|
490
|
-
|
|
491
|
-
type GetRequestTableOverrides = {}
|
|
492
|
-
|
|
493
|
-
// required parameters, optional parameters, parameter type overrides, response, and table names
|
|
494
|
-
const Get = restRequest<GetCustomAndRequiredFields, iUsers, GetRequestTableOverrides, iGetC6RestResponse<iUsers>, RestTableNames>({
|
|
495
|
-
C6: C6,
|
|
496
|
-
tableName: users.TABLE_NAME,
|
|
497
|
-
requestMethod: GET,
|
|
498
|
-
queryCallback: (request) => {
|
|
499
|
-
request.success ??= 'Successfully received users!'
|
|
500
|
-
request.error ??= 'An unknown issue occurred creating the users!'
|
|
501
|
-
return request
|
|
502
|
-
},
|
|
503
|
-
responseCallback: (response, _request) => {
|
|
504
|
-
const responseData = response?.data?.rest;
|
|
505
|
-
updateRestfulObjectArrays<iUsers>(Array.isArray(responseData) ? responseData : [responseData], "users", C6.users.PRIMARY_SHORT as (keyof iUsers)[])
|
|
506
|
-
}
|
|
507
|
-
});
|
|
508
181
|
|
|
509
|
-
|
|
182
|
+
export const Actor = {
|
|
183
|
+
...actor,
|
|
184
|
+
...restOrm<
|
|
185
|
+
OrmGenerics<any, 'actor', iActor, ActorPrimaryKeys>
|
|
186
|
+
>(() => ({
|
|
187
|
+
...GLOBAL_REST_PARAMETERS,
|
|
188
|
+
restModel: actor
|
|
189
|
+
}))
|
|
190
|
+
}
|
|
191
|
+
```
|
|
510
192
|
|
|
511
|
-
|
|
193
|
+
3) **Profit**
|
|
194
|
+
- C6 will produce 1-1 constants.
|
|
512
195
|
|
|
513
|
-
|
|
514
|
-
updateRestfulObjectArrays<iUsers>([
|
|
515
|
-
removeInvalidKeys<iUsers>({
|
|
516
|
-
...request,
|
|
517
|
-
...response?.data?.rest,
|
|
518
|
-
}, C6.TABLES)
|
|
519
|
-
], "users", users.PRIMARY_SHORT as (keyof iUsers)[])
|
|
520
|
-
}
|
|
196
|
+
Allowing you to do:
|
|
521
197
|
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
198
|
+
```typescript
|
|
199
|
+
import { Actor, C6C } from "./api/rest/Actor";
|
|
200
|
+
|
|
201
|
+
// GET
|
|
202
|
+
const actors = await Actor.GET({
|
|
203
|
+
[C6C.SELECT]: [
|
|
204
|
+
Actor.ACTOR_ID,
|
|
205
|
+
Actor.FIRST_NAME,
|
|
206
|
+
Actor.LAST_NAME,
|
|
207
|
+
],
|
|
208
|
+
[C6C.WHERE]: {
|
|
209
|
+
[Actor.LAST_NAME]: { like: "%PITT%" },
|
|
530
210
|
},
|
|
531
|
-
|
|
211
|
+
[C6C.LIMIT]: 10,
|
|
532
212
|
});
|
|
533
213
|
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
if ('number' === typeof id || 'string' === typeof id) {
|
|
540
|
-
if (1 !== users.PRIMARY_SHORT.length) {
|
|
541
|
-
console.error("C6 received unexpected result's given the primary key length");
|
|
542
|
-
} else {
|
|
543
|
-
request[users.PRIMARY_SHORT[0]] = id
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
updateRestfulObjectArrays<iUsers>(
|
|
547
|
-
undefined !== request.dataInsertMultipleRows
|
|
548
|
-
? request.dataInsertMultipleRows.map((request, index) => {
|
|
549
|
-
return removeInvalidKeys<iUsers>({
|
|
550
|
-
...request,
|
|
551
|
-
...(index === 0 ? response?.data?.rest : {}),
|
|
552
|
-
}, C6.TABLES)
|
|
553
|
-
})
|
|
554
|
-
: [
|
|
555
|
-
removeInvalidKeys<iUsers>({
|
|
556
|
-
...request,
|
|
557
|
-
...response?.data?.rest,
|
|
558
|
-
}, C6.TABLES)
|
|
559
|
-
],
|
|
560
|
-
"users",
|
|
561
|
-
users.PRIMARY_SHORT as (keyof iUsers)[]
|
|
562
|
-
)
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
const Post = restRequest<PostCustomAndRequiredFields, iUsers, PostRequestTableOverrides, iPostC6RestResponse<iUsers>, RestTableNames>({
|
|
566
|
-
C6: C6,
|
|
567
|
-
tableName: users.TABLE_NAME,
|
|
568
|
-
requestMethod: POST,
|
|
569
|
-
queryCallback: (request) => {
|
|
570
|
-
request.success ??= 'Successfully created the users data!'
|
|
571
|
-
request.error ??= 'An unknown issue occurred creating the users data!'
|
|
572
|
-
return request
|
|
214
|
+
// POST
|
|
215
|
+
await Actor.POST({
|
|
216
|
+
[C6C.DATA]: {
|
|
217
|
+
[Actor.FIRST_NAME]: "Brad",
|
|
218
|
+
[Actor.LAST_NAME]: "Pitt",
|
|
573
219
|
},
|
|
574
|
-
responseCallback: postStateUsers
|
|
575
220
|
});
|
|
576
221
|
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
], "users", users.PRIMARY_SHORT as (keyof iUsers)[])
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
const Delete = restRequest<DeleteCustomAndRequiredFields, iUsers, DeleteRequestTableOverrides, iDeleteC6RestResponse<iUsers>, RestTableNames>({
|
|
588
|
-
C6: C6,
|
|
589
|
-
tableName: users.TABLE_NAME,
|
|
590
|
-
requestMethod: DELETE,
|
|
591
|
-
queryCallback: (request) => {
|
|
592
|
-
request.success ??= 'Successfully removed the users data!'
|
|
593
|
-
request.error ??= 'An unknown issue occurred removing the users data!'
|
|
594
|
-
return request
|
|
222
|
+
// PUT
|
|
223
|
+
await Actor.PUT({
|
|
224
|
+
[C6C.WHERE]: {
|
|
225
|
+
[Actor.ACTOR_ID]: 42,
|
|
226
|
+
},
|
|
227
|
+
[C6C.DATA]: {
|
|
228
|
+
[Actor.LAST_NAME]: "Updated",
|
|
595
229
|
},
|
|
596
|
-
responseCallback: deleteStateUsers
|
|
597
230
|
});
|
|
598
231
|
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
export default Users;
|
|
232
|
+
// DELETE
|
|
233
|
+
await Actor.DELETE({
|
|
234
|
+
[C6C.WHERE]: {
|
|
235
|
+
[Actor.ACTOR_ID]: 42,
|
|
236
|
+
},
|
|
237
|
+
});
|
|
608
238
|
```
|
|
609
239
|
|
|
610
|
-
|
|
240
|
+
Our CarbonReact extends this solution for automatic state and pagination management.
|
|
611
241
|
|
|
612
242
|
|
|
613
243
|
# Git Hooks
|