dbtasker 2.1.0 → 2.5.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 CHANGED
@@ -1,4 +1,521 @@
1
- # dbtasker
2
- **Ongoing project. Any one can contribute**
1
+ # DBTASKER
2
+
3
+ DBTASKER is a powerful MySQL schema intelligence and query generation module. It allows developers to define database schemas declaratively in JSON. DBTASKER automatically validates, normalizes, and generates correct SQL for tables, columns, indexes, defaults, foreign keys, and more.
4
+ It is engine-aware, handles MySQL constraints, and is fully compatible with ORMs or other automation tools.
5
+
6
+ #### Engine Awareness
7
+ DBTASKER supports MySQL engines and handles constraints accordingly:
8
+
9
+ - InnoDB
10
+ - MyISAM
11
+ - MEMORY
12
+ - CSV
13
+ - ARCHIVE
14
+ - BLACKHOLE
15
+ - FEDERATED
16
+ - NDB / NDBCLUSTER
17
+ - MRG_MYISAM
18
+ - Spider
19
+ - RocksDB
20
+ - TokuDB
21
+
22
+
23
+ #### Design Philosophy
24
+
25
+ - Schema-first, declarative JSON
26
+ - Validation before SQL generation
27
+ - Engine-aware and safe migrations
28
+ - Flexible key aliases and metadata support
29
+ - Supports both SQL-level and ORM-level annotations
30
+
31
+
32
+ #### Compatibility
33
+ - Node.js 16+
34
+ - MySQL 5.7+ / 8+
35
+
36
+
37
+ ## Core Concept
38
+ DBTASKER uses a JSON-driven design:
39
+ ```js
40
+ Database → Tables → Columns → Column Properties
41
+ ```
42
+
43
+ - Database: Name of the MySQL database
44
+ - Table: Table within the database
45
+ - Column: Column within the table
46
+ - Properties: Rules, types, defaults, and constraints
47
+
48
+
49
+ DBTASKER normalizes keys case-insensitively, so multiple naming styles are supported (camelCase, snake_case, uppercase, lowercase).
50
+
51
+ #### JSON Schema Structure
52
+ ```js
53
+ {
54
+ DatabaseName: {
55
+ TableName: {
56
+ ColumnName: {
57
+ // Column properties
58
+ }
59
+ }
60
+ }
61
+ }
62
+ ```
63
+ Demo Schema Example
64
+ ```js
65
+ {
66
+ DatabaseName: {
67
+ TableName: {
68
+ ColumnName: {
69
+ ColumnType: "varchar",
70
+ lengthvalue: 255,
71
+ Null: true,
72
+ defaults: "guest",
73
+ comment: "User email address"
74
+ },
75
+ ColumnTwo: {
76
+ type: "int",
77
+ zerofill: true,
78
+ index: "key",
79
+ Null: false,
80
+ foreign_key: {
81
+ table: "user",
82
+ column: "id",
83
+ delete: true,
84
+ update: true
85
+ }
86
+ }
87
+ }
88
+ }
89
+ }
90
+ ```
91
+
92
+ ## Configuration File
93
+
94
+ DBTASKER requires a configuration JSON file to connect to your MySQL database and define runtime behavior. This config file allows you to:
95
+
96
+ - Set database connection credentials
97
+ - Control whether databases, tables, or columns are dropped
98
+ - Protect specific databases from accidental deletion
99
+ - Customize separators or other runtime options
100
+
101
+ **Basic Database Configuration**
102
+ ```js
103
+ {
104
+ user: "root",
105
+ password: "password123",
106
+ host: "localhost",
107
+ port: 3306
108
+ }
109
+ ```
110
+
111
+ 1. user: MySQL username
112
+ 2. password: MySQL password
113
+ 3. host: MySQL host
114
+ 4. port: MySQL port
115
+ 5. Drop database
116
+ 6. Do not delete database Array = []
117
+ 7. Drop Table
118
+ 8. Drop Column
119
+ 9. Database structure as JSON Object
120
+
121
+ You can control dropping databases, tables, or columns using boolean flags. DBTASKER supports multiple aliases for each option.
122
+
123
+ #### Drop Database
124
+
125
+ ### Aliases:
126
+ You can use these as key when declearing on config JSON object without caring for case sensitivity.
127
+ ```js
128
+ dropdb, dropdatabase, deletedb, deletedatabase,
129
+ drop_db, drop_database, delete_db, delete_database,
130
+ removedb, removedatabase, remove_db, remove_database
131
+ ```
132
+
133
+
134
+ **Example:**
135
+ ```js
136
+ dropdb: true
137
+ ```
138
+
139
+ ### Drop Table
140
+ **Aliases:**
141
+ You can use these as key when declearing on config JSON object without caring for case sensitivity.
142
+ ```js
143
+ droptable, deletetable, drop_table, delete_table,
144
+ removetable, remove_table,
145
+ dropdbtable, deletedbtable, removedbtable,
146
+ dropdatabasetable, deletedatabasetable, removedatabasetable,
147
+ drop_db_table, delete_db_table, remove_db_table,
148
+ drop_database_table, delete_database_table, remove_database_table
149
+ ```
150
+
151
+
152
+ **Example:**
153
+ ```js
154
+ droptable: true
155
+ ```
156
+
157
+
158
+ ### Drop Column
159
+ **Aliases:**
160
+ You can use these as key when declearing on config JSON object without caring for case sensitivity.
161
+ ```js
162
+ dropcol, dropcolumn, deletecol, deletecolumn,
163
+ removecol, removecolumn,
164
+ drop_col, drop_column, delete_col, delete_column,
165
+ remove_col, remove_column
166
+ ```
167
+
168
+
169
+ **Example:**
170
+ ```js
171
+ dropcol: false
172
+ ```
173
+
174
+ **Protect Databases from Deletion**
175
+ If you want to prevent certain databases from being dropped when dropdb is enabled, you can specify an array of database names under any of the aliases below:
176
+ You can use these as key when declearing on config JSON object without caring for case sensitivity.
177
+ ```js
178
+ donttouch, donottouch, donttouchdb, donottouchdb,
179
+ donttouchdatabase, donottouchdatabase,
180
+ dontdelete, donotdelete, dontdeletedb, donotdeletedb,
181
+ dontdeletedatabase, donotdeletedatabase,
182
+ dont_touch, do_not_touch, dont_touch_db, do_not_touch_db,
183
+ dont_touch_database, do_not_touch_database,
184
+ dont_delete, do_not_delete, dont_delete_db, do_not_delete_db,
185
+ dont_delete_database, do_not_delete_database,
186
+ reserveddb, reserved_db
187
+ ```
188
+
189
+ **Example:**
190
+ ```js
191
+ donttouch: ["production_db", "legacy_db"]
192
+ ```
193
+
194
+ ### Separator Option
195
+
196
+ You can define a custom separator for internal operations:
197
+
198
+ **Aliases:**
199
+ You can use these as key when declearing on config JSON object without caring for case sensitivity.
200
+ sep, seperator
201
+
202
+
203
+ **Example:**
204
+ ```js
205
+ sep: "_"
206
+ ```
207
+ Full Example Config File
208
+ ```js
209
+ {
210
+ user: "root",
211
+ password: "password123",
212
+ host: "localhost",
213
+ port: 3306,
214
+ dropdb: true,
215
+ droptable: true,
216
+ dropcol: false,
217
+ donttouch: ["production_db", "analytics_db"],
218
+ sep: "_"
219
+ }
220
+ ```
221
+
222
+ This configuration will:
223
+
224
+ - Connect to MySQL using the given credentials
225
+ - Drop databases and tables if they exist
226
+ - Preserve "production_db" and "analytics_db"
227
+ - Avoid dropping columns
228
+ - Use _ as a separator internally
229
+
230
+ ## Installation
231
+
232
+ DBTASKER is available via npm.
233
+
234
+ Install it using either of the following commands:
235
+ ```js
236
+ npm install DBTASKER
237
+ ```
238
+
239
+ or
240
+ ```js
241
+ npm i DBTASKER
242
+ ```
243
+ Usage
244
+
245
+ DBTASKER is designed to be simple and declarative. You provide:
246
+
247
+ 1. A configuration object (database credentials + behavior options)
248
+
249
+ 2. A JSON schema object (database, tables, columns)
250
+
251
+ DBTASKER handles the rest.
252
+
253
+ #### Step 1: Import DBTASKER
254
+
255
+ Create a JavaScript file (for example: index.js) and import DBTASKER.
256
+ ```js
257
+ Using require (CommonJS)
258
+ const DBTASKER = require("DBTASKER");
259
+
260
+ Using import (ES Module)
261
+ import DBTASKER from "DBTASKER";
262
+ ```
263
+
264
+ #### Step 2: Create a Configuration Object
265
+
266
+ This object defines how DBTASKER connects to the database and how it behaves.
267
+ ```js
268
+ const config = {
269
+ host: "localhost",
270
+ user: "root",
271
+ password: "password",
272
+ port: 3306
273
+ };
274
+ ```
275
+
276
+ You can later extend this config with options like:
277
+
278
+ - Drop database
279
+ - Drop tables
280
+ - Drop columns
281
+ - Reserved / protected databases
282
+
283
+ #### Step 3: Define Your Schema JSON Object
284
+
285
+ Your schema is defined declaratively using a nested JSON structure:
286
+ ```js
287
+ const schema = {
288
+ MyDatabase: {
289
+ users: {
290
+ id: {
291
+ type: "int",
292
+ autoincrement: true,
293
+ primarykey: true
294
+ },
295
+ email: {
296
+ type: "varchar",
297
+ length: 255,
298
+ required: true,
299
+ unique: true
300
+ },
301
+ created_at: {
302
+ type: "timestamp",
303
+ defaults: "CURRENT_TIMESTAMP"
304
+ }
305
+ }
306
+ }
307
+ };
308
+ ```
309
+
310
+ DBTASKER supports multiple aliases for column keys and is case-insensitive.
311
+
312
+ #### Step 4: Run DBTASKER
313
+
314
+ Call DBTASKER by passing the config first, then the schema object.
315
+ ```js
316
+ DBTASKER(config, schema);
317
+ ```
318
+
319
+ That’s it.
320
+
321
+ **DBTASKER will:**
322
+ - Connect to MySQL
323
+ - Validate your schema
324
+ - Create or alter databases, tables, and columns
325
+ - Apply indexes, foreign keys, defaults, and constraints
326
+
327
+ ### Full Minimal Example
328
+ ```js
329
+ const DBTASKER = require("DBTASKER");
330
+
331
+ const config = {
332
+ host: "localhost",
333
+ user: "root",
334
+ password: "password",
335
+ port: 3306,
336
+ droptable: true,
337
+ droptable: true,
338
+ dropcolumn: true,
339
+ donotdelete: ['test', 'example']
340
+ };
341
+
342
+ const schema = {
343
+ app_db: {
344
+ users: {
345
+ id: {
346
+ type: "int",
347
+ primarykey: true,
348
+ autoincrement: true
349
+ },
350
+ name: {
351
+ type: "varchar",
352
+ length: 100,
353
+ required: true
354
+ }
355
+ }
356
+ }
357
+ };
358
+
359
+ DBTASKER(config, schema);
360
+ ```
361
+
362
+ **Notes**
363
+
364
+ ### Important:
365
+ - The config object must always come first
366
+ - The schema JSON object must come second
367
+ - All keys are case-insensitive
368
+ - Multiple aliases are supported for maximum flexibility
369
+
370
+
371
+ ## Column Key Aliases (Case-Insensitive)
372
+ DBTASKER allows multiple aliases for each column property. Keys are normalized internally.
373
+
374
+ **Length / Size / Precision**
375
+ You can use these as key when declearing column property inside table object inside JSON object without caring for case sensitivity.
376
+ ```js
377
+ lengthvalue, length_value, size, scale, lengths,
378
+ length, value, values, range, maxlength, max_length, precision
379
+ ```
380
+
381
+ **Column Type / Data Type**
382
+ You can use these as key when declearing column property inside table object inside JSON object without caring for case sensitivity.
383
+ ```js
384
+ type, columntype, column_type,
385
+ datatype, data_type, typename, type_name
386
+ ```
387
+
388
+ **Zerofill**
389
+ You can use these as key when declearing column property inside table object inside JSON object without caring for case sensitivity.
390
+ ```js
391
+ zerofill, zero_fill, iszerofill, zerofillup
392
+ ```
393
+
394
+ **Auto Increment / Identity**
395
+ You can use these as key when declearing column property inside table object inside JSON object without caring for case sensitivity.
396
+ ```js
397
+ autoincrement, auto_increment, increment,
398
+ serial, generated, isidentity, identity
399
+ ```
400
+
401
+ **Signed / Unsigned**
402
+ You can use these as key when declearing column property inside table object inside JSON object without caring for case sensitivity.
403
+ ```js
404
+ signed, issigned, numericunsigned, numeric_unsigned,
405
+ unsigned, isunsigned
406
+ ```
407
+
408
+ **Defaults / Default Value**
409
+ You can use these as key when declearing column property inside table object inside JSON object without caring for case sensitivity.
410
+ ```js
411
+ default, defaults, defaultvalue, default_value,
412
+ example, sample, columndefault, column_default
413
+ ```
414
+
415
+ **Null / Not Null**
416
+ You can use these as key when declearing column property inside table object inside JSON object without caring for case sensitivity.
417
+ Disallow NULL / Required
418
+ ```js
419
+ notnull, not_null, nonnullable, notnullable,
420
+ required, disallownull, non_nullable, not_nullable, disallow_null
421
+ ```
422
+
423
+ **Allow NULL / Optional**
424
+ ```js
425
+ null, nulls, nullable, optional, isnulable, allownull, canbenull
426
+ ```
427
+
428
+ **Index / Key**
429
+ You can use these as key when declearing column property inside table object inside JSON object without caring for case sensitivity.
430
+ ```js
431
+ index, spatial, isspatial, fulltext, isfulltext,
432
+ isunique, isuniquekey, uniqueindex, uniquekey,
433
+ unique_index, unique_key,
434
+ primarykey, primary_key, primary, isprimary, isprimarykey,
435
+ indexkey, index_key, indexing
436
+ ```
437
+
438
+ **Comments / Description / Notes**
439
+ You can use these as key when declearing column property inside table object inside JSON object without caring for case sensitivity.
440
+ ```js
441
+ comment, comments, columncomment, column_comment,
442
+ description, label, helptext, hint, note
443
+ ```
444
+
445
+
446
+ **Foreign Key Definition**
447
+ Foreign keys are defined inline to reference another table’s column:
448
+ ```js
449
+ foreign_key: {
450
+ table: "user",
451
+ column: "id",
452
+ delete: true,
453
+ update: true
454
+ }
455
+ ```
456
+ ## Foreign Key Aliases (Case-Insensitive)
457
+ DBTASKER accepts:
458
+ ```js
459
+ "fk", "foreign_key", "foreignkey"
460
+ ```
461
+
462
+ Foreign Key Properties & Aliases
463
+ Property
464
+ ### Alias Options
465
+ #### Purpose
466
+ **Table**
467
+ ```js
468
+ "table", "fktable", "fk_table", "foreignkeytable", "foreign_key_table"
469
+ ```
470
+ Referenced table name
471
+
472
+ **column**
473
+ ```js
474
+ "column", "fkcolumn", "fk_column", "foreignkeycolumn", "foreign_key_column"
475
+ ```
476
+ Referenced column name
477
+
478
+ **delete**
479
+ ```js
480
+ "delete", "ondelete", "on_delete", "when_Delete", "whenDelete", 'ifdelete', 'if_delete'
481
+ ```
482
+ ON DELETE CASCADE behavior
483
+
484
+ **update**
485
+ ```js
486
+ "update", "onupdate", "on_update", "ifupdate", "if_update", "when_update", "whenupdate"
487
+ ```
488
+ ON UPDATE CASCADE behavior
489
+
490
+ You can use value of delete and update option as:
491
+ **values**
492
+ ```js
493
+ null, "NULL", "SET NULL", true, "DL", "DEL", "DELETE", "CASCADE", "DEFAULT", "SET DEFAULT", "RESTRICT", "NO ACTION"
494
+ ```
495
+
496
+ > Notes:
497
+ > DBTASKER automatically normalizes all keys internally.
498
+
499
+ Foreign key constraints are generated safely and include necessary values automatically.
500
+
501
+
502
+
503
+ #### Use Cases
504
+ Schema builders and migration tools
505
+
506
+
507
+ #### Admin dashboards
508
+ Low-code / no-code backends
509
+
510
+
511
+
512
+ #### License
513
+ MIT
514
+
515
+
516
+ #### Author
517
+ Md Nasiruddin Ahmed (Manik)
518
+
519
+ ---Designed for safe, flexible, and high-quality MySQL schema automation.
520
+
3
521
 
4
- Do operation to your database autometically
package/columnop.js CHANGED
@@ -51,7 +51,7 @@ function alterColumnQuery(columndata, columnName, tableName) {
51
51
  if (columndata.autoincrement === true) {
52
52
  queryText += "AUTO_INCREMENT ";
53
53
  }
54
-
54
+ if(columndata.index) queryText += `${columndata.index} `
55
55
  if (columndata._charset_) queryText += `CHARACTER SET ${columndata._charset_} `;
56
56
  if (columndata._collate_) queryText += `COLLATE ${columndata._collate_} `;
57
57
 
package/index.js CHANGED
@@ -29,9 +29,7 @@ module.exports = async function(allconfig, table_json) {
29
29
  'host': allconfig.host,
30
30
  'user': allconfig.user,
31
31
  'password': allconfig.password,
32
- 'port': allconfig.port,
33
- 'waitForConnections': true,
34
- 'connectionLimit': 100
32
+ 'port': allconfig.port
35
33
  }
36
34
  // get don't touch database
37
35
  let donttouchdb = [];
@@ -54,9 +52,9 @@ module.exports = async function(allconfig, table_json) {
54
52
  }
55
53
  // Declare seperator
56
54
  let seperator = "_";
57
- const sepkeys = ['sep', 'Sep', 'Seperator', 'seperator'];
58
- for (const item of sepkeys) {
59
- if (allconfig.hasOwnProperty(item)) {
55
+ const sepkeys = ['sep', 'seperator'];
56
+ for (const item of Object.keys(allconfig)) {
57
+ if (sepkeys.includes(item.toLowerCase())) {
60
58
  seperator = allconfig[item];
61
59
  break;
62
60
  }
@@ -77,7 +75,7 @@ module.exports = async function(allconfig, table_json) {
77
75
  dropdatabase = false;
78
76
  }
79
77
  let droptable;
80
- const droptablekeys = ['droptable', 'deletetable', 'drop_table', 'delete_table', 'removetable', 'remove_table', 'dropdbtable', 'deletedbtable', 'removedbtable', 'dropdatabasetable', 'deletedatabasetable', 'removedatabasetable', 'drop_db_table', 'delete_db_table', 'remove_db_table', 'drop_database_table', 'delete_database_table', 'remove_database_table',];
78
+ const droptablekeys = ['droptable', 'deletetable', 'drop_table', 'delete_table', 'removetable', 'remove_table', 'dropdbtable', 'deletedbtable', 'removedbtable', 'dropdatabasetable', 'deletedatabasetable', 'removedatabasetable', 'drop_db_table', 'delete_db_table', 'remove_db_table', 'drop_database_table', 'delete_database_table', 'remove_database_table'];
81
79
  for (const item of Object.keys(allconfig)) {
82
80
  if (droptablekeys.includes(item.toLowerCase())) {
83
81
  droptable = allconfig[item];
@@ -89,7 +87,7 @@ module.exports = async function(allconfig, table_json) {
89
87
  droptable = false;
90
88
  }
91
89
  let dropcolumn;
92
- const dropcolkeys = ['dropcol', 'dropcolumn', 'deletecol', 'deletecolumn', 'removecol', 'removecolumn', 'drop_col', 'drop_column', 'delete_col', 'delete_column', 'remove_col', 'remove_column',];
90
+ const dropcolkeys = ['dropcol', 'dropcolumn', 'deletecol', 'deletecolumn', 'removecol', 'removecolumn', 'drop_col', 'drop_column', 'delete_col', 'delete_column', 'remove_col', 'remove_column'];
93
91
  for (const item of Object.keys(allconfig)) {
94
92
  if (dropcolkeys.includes(item.toLowerCase())) {
95
93
  dropcolumn = allconfig[item];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dbtasker",
3
- "version": "2.1.0",
3
+ "version": "2.5.1",
4
4
  "description": "You can create database and table on your own with a lot of functionality.",
5
5
  "license": "ISC",
6
6
  "author": "Md Nasiruddin Ahmed",
package/validation.js CHANGED
@@ -304,54 +304,32 @@ async function JSONchecker(table_json, config, seperator = "_") {
304
304
  * ColumnType
305
305
  * COLUMNTYPE
306
306
  */
307
- if (deepColumn.hasOwnProperty("type")) {
308
- columntype = deepColumn.type;
309
- } else if (deepColumn.hasOwnProperty("Type")) {
310
- columntype = deepColumn.Type;
311
- } else if (deepColumn.hasOwnProperty("TYPE")) {
312
- columntype = deepColumn.TYPE;
313
- } else if (deepColumn.hasOwnProperty("columntype")) {
314
- columntype = deepColumn.columntype;
315
- } else if (deepColumn.hasOwnProperty("column_type")) {
316
- columntype = deepColumn.column_type;
317
- } else if (deepColumn.hasOwnProperty("Column_Type")) {
318
- columntype = deepColumn.Column_Type;
319
- } else if (deepColumn.hasOwnProperty("ColumnType")) {
320
- columntype = deepColumn.ColumnType;
321
- } else if (deepColumn.hasOwnProperty("COLUMNTYPE")) {
322
- columntype = deepColumn.COLUMNTYPE;
307
+ const coltypekeys = ['type', 'columntype', 'column_type', 'datatype', 'data_type', 'typename', 'type_name'];
308
+ for (const item of Object.keys(deepColumn)) {
309
+ if (coltypekeys.includes(item.toLowerCase())) {
310
+ columntype = deepColumn[item];
311
+ break;
312
+ }
323
313
  }
324
314
  if (typeof columntype !== "string" && columntype !== undefined) {
325
315
  columntype = null;
326
316
  }
327
317
  /**
328
- * LengthValue
329
- * lengthvalue
330
- * LENGTHVALUE
331
- * length_value
332
318
  * Length_Value
333
319
  */
334
- if (deepColumn.hasOwnProperty("LengthValue")) {
335
- length_value = deepColumn.LengthValue;
336
- } else if (deepColumn.hasOwnProperty("lengthvalue")) {
337
- length_value = deepColumn.lengthvalue;
338
- } else if (deepColumn.hasOwnProperty("length_value")) {
339
- length_value = deepColumn.length_value;
340
- } else if (deepColumn.hasOwnProperty("LENGTHVALUE")) {
341
- length_value = deepColumn.LENGTHVALUE;
342
- } else if (deepColumn.hasOwnProperty("Length_Value")) {
343
- length_value = deepColumn.Length_Value;
320
+ const legnthkeys = ["lengthvalue", "length_value", 'size', 'scale', 'lengths', 'length', 'value', 'values', 'range', 'maxlength', 'max_length', 'precision'];
321
+ for (const item of Object.keys(deepColumn)) {
322
+ if (legnthkeys.includes(item.toLowerCase())) {
323
+ length_value = deepColumn[item];
324
+ break;
325
+ }
344
326
  }
345
327
  /**
346
- * autoIncrement
347
- * autoincrement
348
- * auto_increment
349
328
  * AUTO_INCREMENT
350
- * AUTOINCREMENT
351
329
  */
352
- const autoincrementkeys = ["autoIncrement", "autoincrement", "auto_increment", "AUTO_INCREMENT", "AUTOINCREMENT", "increment", "INCREMENT"]
353
- for (const item of autoincrementkeys) {
354
- if (deepColumn.hasOwnProperty(item)) {
330
+ const autoincrementkeys = ['autoincrement', 'auto_increment', 'increment', 'serial', 'generated', 'isidentity', 'identity']
331
+ for (const item of Object.keys(deepColumn)) {
332
+ if (autoincrementkeys.includes(item.toLowerCase())) {
355
333
  autoincrement = deepColumn[item];
356
334
  break;
357
335
  }
@@ -370,16 +348,52 @@ async function JSONchecker(table_json, config, seperator = "_") {
370
348
  * INDEX
371
349
  * Index
372
350
  */
373
- const indexkey = ["index", "INDEX", "Index"];
374
- for (const item of indexkey) {
375
- if (deepColumn.hasOwnProperty(item)) {
351
+ let indexvalue = undefined;
352
+ const indexkey = ["index", 'indexkey', 'index_key', 'indexing'];
353
+ for (const item of Object.keys(deepColumn)) {
354
+ if (indexkey.includes(item.toLowerCase())) {
376
355
  indexes = deepColumn[item];
356
+ break;
357
+ } else if (['primarykey', 'primary_key', 'primary', 'isprimary', 'isprimarykey'].includes(item.toLowerCase())) {
358
+ if (truers.includes(deepColumn[item])) {
359
+ indexes = "PRIMARY KEY";
360
+ break;
361
+ } else {
362
+ indexes = undefined;
363
+ }
364
+ } else if (['isunique', 'isuniquekey', 'uniqueindex', 'uniquekey', 'unique_index', 'unique_key'].includes(item.toLowerCase())) {
365
+ if (truers.includes(deepColumn[item])) {
366
+ indexes = "UNIQUE";
367
+ break;
368
+ } else {
369
+ indexes = undefined;
370
+ }
371
+ } else if (['fulltext', 'isfulltext'].includes(item.toLowerCase())) {
372
+ if (truers.includes(deepColumn[item])) {
373
+ indexes = "FULLTEXT";
374
+ break;
375
+ } else {
376
+ indexes = undefined;
377
+ }
378
+ } else if (['spatial', 'isspatial'].includes(item.toLowerCase())) {
379
+ if (truers.includes(deepColumn[item])) {
380
+ indexes = "SPATIAL";
381
+ break;
382
+ } else {
383
+ indexes = undefined;
384
+ }
385
+ } else if (['index'].includes(item.toLowerCase())) {
386
+ if (truers.includes(deepColumn[item])) {
387
+ indexes = "INDEX";
388
+ break;
389
+ } else {
390
+ indexes = undefined;
391
+ }
377
392
  }
378
393
  }
379
- if (indexes !== undefined) indexes = fncs.stringifyAny(indexes).toUpperCase();
380
- if (indexes === "PRIMARY" || indexes === "KEY") {
381
- indexes = "PRIMARY KEY"
382
- } else if (indexes === "FULL") {
394
+ if (indexes !== undefined) { indexes = fncs.stringifyAny(indexes).toUpperCase(); }
395
+ else if (indexes === "PRIMARY") { indexes = "PRIMARY KEY" }
396
+ else if (indexes === "FULL") {
383
397
  indexes = "FULLTEXT";
384
398
  }
385
399
  /**
@@ -387,12 +401,31 @@ async function JSONchecker(table_json, config, seperator = "_") {
387
401
  * NULL
388
402
  * Null
389
403
  */
390
- if (deepColumn.hasOwnProperty("null")) {
391
- nulls = deepColumn.null;
392
- } else if (deepColumn.hasOwnProperty("NULL")) {
393
- nulls = deepColumn.NULL;
394
- } else if (deepColumn.hasOwnProperty("Null")) {
395
- nulls = deepColumn.Null;
404
+ const nullkeys = ['null', 'nulls', 'nullable', 'optional', 'isnulable', 'allownull', 'canbenull'];
405
+ for (const item of Object.keys(deepColumn)) {
406
+ if (nullkeys.includes(item.toLowerCase())) {
407
+ if (truers.includes(deepColumn[item])) {
408
+ nulls = true;
409
+ break;
410
+ } else if (falsers.includes(deepColumn[item])) {
411
+ nulls = false;
412
+ break;
413
+ } else {
414
+ nulls = true;
415
+ break;
416
+ }
417
+ } else if (['notnull', 'not_null', 'nonnullable', 'notnullable', 'required', 'disallownull', 'non_nullable', 'not_nullable', 'disallow_null'].includes(item.toLowerCase())) {
418
+ if (truers.includes(deepColumn[item])) {
419
+ nulls = false;
420
+ break;
421
+ } else if (falsers.includes(deepColumn[item])) {
422
+ nulls = true;
423
+ break;
424
+ } else {
425
+ nulls = true;
426
+ break;
427
+ }
428
+ }
396
429
  }
397
430
  if (truers.includes(nulls)) {
398
431
  nulls = true;
@@ -407,93 +440,64 @@ async function JSONchecker(table_json, config, seperator = "_") {
407
440
  );
408
441
  }
409
442
  /**
410
- * comment
411
443
  * COMMENT
412
- * Comment
413
444
  */
414
- if (deepColumn.hasOwnProperty("comment")) {
415
- comment = deepColumn.comment;
416
- } else if (deepColumn.hasOwnProperty("COMMENT")) {
417
- comment = deepColumn.COMMENT;
418
- } else if (deepColumn.hasOwnProperty("Comment")) {
419
- comment = deepColumn.Comment;
445
+ const commentkeys = ['comment', 'comments', 'columncomment', 'column_comment', 'description', 'label', 'helptext', 'hint', 'note'];
446
+ for (const item of Object.keys(deepColumn)) {
447
+ if (commentkeys.includes(item.toLowerCase())) {
448
+ comment = deepColumn[item];
449
+ break;
450
+ }
420
451
  }
421
452
  /**
422
- * unsigned
423
453
  * UNSIGNED
424
- * Unsigned
425
- * signed
426
- * Signed
427
- * SIGNED
428
454
  */
429
-
455
+ const unsignekey = ['numericunsigned', 'numeric_unsigned', 'unsigned', 'isunsigned'];
430
456
  let signed = undefined;
431
- if (deepColumn.hasOwnProperty("unsigned")) {
432
- unsigned = deepColumn.unsigned;
433
- } else if (deepColumn.hasOwnProperty("UNSIGNED")) {
434
- unsigned = deepColumn.UNSIGNED;
435
- } else if (deepColumn.hasOwnProperty("Unsigned")) {
436
- unsigned = deepColumn.Unsigned;
437
- } else if (deepColumn.hasOwnProperty("signed")) {
438
- signed = deepColumn.signed;
439
- } else if (deepColumn.hasOwnProperty("Signed")) {
440
- signed = deepColumn.Signed;
441
- } else if (deepColumn.hasOwnProperty("SIGNED")) {
442
- signed = deepColumn.SIGNED;
443
- }
444
- if (unsigned !== undefined) {
445
- if (truers.includes(unsigned)) {
446
- unsigned = true;
447
- } else if (falsers.includes(unsigned)) {
448
- unsigned = false;
449
- } else if (unsigned === undefined) {
450
- unsigned = undefined;
451
- } else {
452
- unsigned = null;
453
- }
454
- } else if (signed !== undefined) {
455
- if (truers.includes(signed)) {
456
- unsigned = false;
457
- } else if (falsers.includes(signed)) {
458
- unsigned = true;
459
- } else if (signed === undefined) {
460
- unsigned = undefined;
461
- } else {
462
- unsigned = null;
457
+ for (const item of Object.keys(deepColumn)) {
458
+ if (unsignekey.includes(item.toLowerCase())) {
459
+ if (truers.includes(deepColumn[item])) {
460
+ unsigned = true;
461
+ break;
462
+ } else if (falsers.includes(deepColumn[item])) {
463
+ unsigned = false;
464
+ break;
465
+ } else {
466
+ unsigned = null;
467
+ break;
468
+ }
469
+ } else if (['signed', 'issigned'].includes(item.toLowerCase())) {
470
+ if (truers.includes(deepColumn[item])) {
471
+ unsigned = false;
472
+ break;
473
+ } else if (falsers.includes(deepColumn[item])) {
474
+ unsigned = true;
475
+ break;
476
+ } else {
477
+ unsigned = null;
478
+ break;
479
+ }
463
480
  }
464
481
  }
465
482
  /**
466
- * default
467
483
  * DEFAULT
468
- * Default
469
484
  */
470
- if (deepColumn.hasOwnProperty("default")) {
471
- defaults = deepColumn.default;
472
- } else if (deepColumn.hasOwnProperty("DEFAULT")) {
473
- defaults = deepColumn.DEFAULT;
474
- } else if (deepColumn.hasOwnProperty("Default")) {
475
- defaults = deepColumn.Default;
485
+ const defaultkeys = ['default', 'defaults', 'defaultvalue', 'default_value', 'example', 'sample', 'columndefault', 'column_default'];
486
+ for (const item of Object.keys(deepColumn)) {
487
+ if (defaultkeys.includes(item.toLowerCase())) {
488
+ defaults = deepColumn[item];
489
+ break;
490
+ }
476
491
  }
477
492
  /**
478
- * zerofill
479
- * ZeroFill
480
- * Zerofill
481
493
  * ZEROFILL
482
- * zero_fill
483
- * Zero_Fill
484
494
  */
485
- if (deepColumn.hasOwnProperty("zerofill")) {
486
- zerofill = deepColumn.zerofill;
487
- } else if (deepColumn.hasOwnProperty("ZeroFill")) {
488
- zerofill = deepColumn.ZeroFill;
489
- } else if (deepColumn.hasOwnProperty("Zerofill")) {
490
- zerofill = deepColumn.Zerofill;
491
- } else if (deepColumn.hasOwnProperty("ZEROFILL")) {
492
- zerofill = deepColumn.ZEROFILL;
493
- } else if (deepColumn.hasOwnProperty("zero_fill")) {
494
- zerofill = deepColumn.zero_fill;
495
- } else if (deepColumn.hasOwnProperty("Zero_Fill")) {
496
- zerofill = deepColumn.Zero_Fill;
495
+ const zerofkeys = ['zerofill', 'zero_fill', 'iszerofill', 'zerofillup'];
496
+ for (const item of Object.keys(deepColumn)) {
497
+ if (zerofkeys.includes(item.toLowerCase())) {
498
+ zerofill = deepColumn[item];
499
+ break;
500
+ }
497
501
  }
498
502
  if (truers.includes(zerofill)) {
499
503
  zerofill = true;
@@ -898,9 +902,9 @@ async function JSONchecker(table_json, config, seperator = "_") {
898
902
  let fktable = undefined;
899
903
  let fkcolumn = undefined;
900
904
  let foreign_key = {};
901
- const fk_variations = ["fk", "Fk", "FK", "foreign_key", "foreign_Key", "Foreign_Key", "FOREIGN_KEY", "foreignkey", "foreignKey", "ForeignKey", "FOREIGNKEY"];
902
- for (const item of fk_variations) {
903
- if (deepColumn.hasOwnProperty(item)) {
905
+ const fk_variations = ["fk", "foreign_key", "foreignkey"];
906
+ for (const item of Object.keys(deepColumn)) {
907
+ if (fk_variations.includes(item.toLowerCase())) {
904
908
  foreign_key = deepColumn[item];
905
909
  break;
906
910
  }
@@ -914,9 +918,9 @@ async function JSONchecker(table_json, config, seperator = "_") {
914
918
  * RESTRICT: Prevents update if any matching child exists.
915
919
  * NO ACTION: Like RESTRICT (timing differences in some DB engines).
916
920
  */
917
- const deleteVariations = ["delete", "Delete", "DELETE", "ondelete", "OnDelete", "onDelete", "ONDELETE", "on_delete", "ON_DELETE", "On_Delete", "on_Delete"]
918
- for (const item of deleteVariations) {
919
- if (foreign_key.hasOwnProperty(item)) {
921
+ const deleteVariations = ["delete", "ondelete", "on_delete", "when_Delete", "whenDelete", 'ifdelete', 'if_delete']
922
+ for (const item of Object.keys(foreign_key)) {
923
+ if (deleteVariations.includes(item.toLowerCase())) {
920
924
  deleteOption = foreign_key[item];
921
925
  if (typeof deleteOption === "string") {
922
926
  deleteOption = deleteOption.toUpperCase();
@@ -925,9 +929,9 @@ async function JSONchecker(table_json, config, seperator = "_") {
925
929
  }
926
930
  }
927
931
  // Lets get update options
928
- const onupdatevariations = ["update", "Update", "UPDATE", "onupdate", "OnUpdate", "onUpdate", "ONUPDATE", "on_update", "ON_UPDATE", "On_Update", "on_Update"];
929
- for (const item of onupdatevariations) {
930
- if (foreign_key.hasOwnProperty(item)) {
932
+ const onupdatevariations = ["update", "onupdate", "on_update", "ifupdate", "if_update", "when_update", "whenupdate"];
933
+ for (const item of Object.keys(foreign_key)) {
934
+ if (onupdatevariations.includes(item.toLowerCase())) {
931
935
  updateOption = foreign_key[item];
932
936
  if (typeof updateOption === "string") {
933
937
  updateOption = updateOption.toUpperCase();
@@ -1006,17 +1010,17 @@ async function JSONchecker(table_json, config, seperator = "_") {
1006
1010
  }
1007
1011
  // check reference table and column
1008
1012
  // lets add foreign key table to variable
1009
- const tableKeyVariation = ["table", "Table", "TABLE", "fktable", "fkTable", "fkTABLE", "Fktable", "FkTable", "FkTABLE", "FKTable", "FKTABLE", "fk_table", "fk_Table", "fk_TABLE", "Fk_table", "Fk_Table", "Fk_TABLE", "FK_Table", "FK_TABLE", "foreignkeytable", "foreignKeyTable", "ForeignKeyTable", "FOREIGNKEYTABLE", "foreign_key_table", "foreign_Key_Table", "FOREIGN_KEY_TABLE", "Foreign_Key_Table"]
1010
- for (const item of tableKeyVariation) {
1011
- if (foreign_key.hasOwnProperty(item)) {
1013
+ const tableKeyVariation = ["table", "fktable", "fk_table", "foreignkeytable", "foreign_key_table"]
1014
+ for (const item of Object.keys(foreign_key)) {
1015
+ if (tableKeyVariation.includes(item.toLowerCase())) {
1012
1016
  fktable = foreign_key[item];
1013
1017
  break;
1014
1018
  }
1015
1019
  }
1016
1020
  // lets add foreign key column to variable
1017
- const columnKeyVariation = ["column", "Column", "COLUMN", "fkcolumn", "fkColumn", "fkCOLUMN", "Fkcolumn", "FkColumn", "FkCOLUMN", "FKColumn", "FKCOLUMN", "fk_column", "fk_Column", "fk_COLUMN", "Fk_column", "Fk_Column", "Fk_COLUMN", "FK_Column", "FK_COLUMN", "foreignkeycolumn", "foreignKeyColumn", "ForeignKeyColumn", "FOREIGNKEYCOLUMN", "foreign_key_column", "foreign_Key_Column", "FOREIGN_KEY_COLUMN", "Foreign_Key_Column"]
1018
- for (const item of (columnKeyVariation)) {
1019
- if (foreign_key.hasOwnProperty(item)) {
1021
+ const columnKeyVariation = ["column", "fkcolumn", "fk_column", "foreignkeycolumn", "foreign_key_column"]
1022
+ for (const item of Object.keys(foreign_key)) {
1023
+ if (columnKeyVariation.includes(item.toLowerCase())) {
1020
1024
  fkcolumn = foreign_key[item];
1021
1025
  break;
1022
1026
  }