dbtasker 1.0.0 → 2.5.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/README.md +521 -0
- package/columnop.js +748 -0
- package/dbop.js +236 -0
- package/enginesupport.js +237 -0
- package/function.js +927 -157
- package/index.js +117 -69
- package/package.json +15 -5
- package/tables.js +0 -1
- package/validation.js +1329 -0
- package/app.js +0 -32
- package/backup-tableoperation.js +0 -717
- package/check.js +0 -18
- package/checker.js +0 -359
- package/tableOperations.js +0 -614
- package/user_tables.js +0 -1655
package/README.md
ADDED
|
@@ -0,0 +1,521 @@
|
|
|
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
|
+
|
|
521
|
+
|