dbtasker 3.0.4 β 3.0.6
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 +102 -462
- package/package.json +2 -2
- package/validation.js +1 -1
package/README.md
CHANGED
|
@@ -1,225 +1,46 @@
|
|
|
1
|
-
# DBTASKER
|
|
1
|
+
# ποΈ DBTASKER
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
The Intelligent MySQL Schema Automation Engine
|
|
4
|
+
`dbtasker` is a powerful, engine-aware MySQL schema intelligence and query generation module. It allows developers to define database structures declaratively using JSON, providing automated validation, normalization, and SQL generation for tables, columns, indexes, and foreign keys.
|
|
5
5
|
|
|
6
|
-
#### Engine Awareness
|
|
7
|
-
DBTASKER supports MySQL engines and handles constraints accordingly:
|
|
8
6
|
|
|
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
7
|
|
|
8
|
+
## π Key Features
|
|
9
|
+
- **Declarative Schema:** Define your entire database structure in a single JSON object.
|
|
10
|
+
- **Engine Awareness:** Optimized for MySQL engines including InnoDB, MyISAM, RocksDB, and more.
|
|
11
|
+
- **Validation First:** Validates and normalizes your schema before any SQL is executed.
|
|
12
|
+
- **Intelligent Migration:** Safe handling of ALTER, DROP, and CREATE operations.
|
|
13
|
+
- **Alias Flexibility:** Case-insensitive keys and multiple naming aliases (camelCase, snake_case, etc.).
|
|
22
14
|
|
|
23
|
-
#### Design Philosophy
|
|
24
15
|
|
|
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
16
|
|
|
31
|
-
|
|
32
|
-
|
|
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**
|
|
17
|
+
## π¦ Installation
|
|
18
|
+
`Bash`
|
|
102
19
|
```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
|
-
|
|
195
|
-
**Force Update Column**
|
|
196
|
-
If you want to update column if it is referanced by another column as foreign key you can update it by adding another key to the config which is force update column which is turned on by default. You can turn it of if you think necessary.
|
|
197
|
-
|
|
198
|
-
```js
|
|
199
|
-
'forceupdatecol', 'forcemodifycol', 'forceupdatecolumn', 'forcemodifycolumn', 'force_update_col', 'force_modify_col', 'force_update_column', 'force_modify_column', 'forcealtercol', 'forcealtercolumn', 'force_alter_col', 'force_alter_column'
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
**Example:**
|
|
203
|
-
```js
|
|
204
|
-
forceupdatecol: true/1/\"1\"
|
|
20
|
+
npm install dbtasker
|
|
205
21
|
```
|
|
206
22
|
|
|
207
|
-
### Separator Option
|
|
208
|
-
|
|
209
|
-
You can define a custom separator for internal operations:
|
|
210
23
|
|
|
211
|
-
**Aliases:**
|
|
212
|
-
You can use these as key when declearing on config JSON object without caring for case sensitivity.
|
|
213
|
-
sep, seperator
|
|
214
24
|
|
|
25
|
+
## π οΈ Configurationd
|
|
26
|
+
btasker requires a configuration object to manage connection credentials and safety behaviors.
|
|
27
|
+
Property | Description
|
|
28
|
+
| :--- | :--- |
|
|
29
|
+
| **host** | MySQL Host (e.g., `localhost`) |
|
|
30
|
+
| **user** | Database Username |
|
|
31
|
+
| **password** | Database Password |
|
|
32
|
+
| **port** | Connection Port (Default: `3306`) |
|
|
33
|
+
| **dropdb** | `Boolean`: If true, allows dropping databases. |
|
|
34
|
+
| **droptable** | `Boolean`: If true, allows dropping tables. |
|
|
35
|
+
| **dropcol** | `Boolean`: If true, allows dropping columns. |
|
|
36
|
+
| **donttouch** | `Array`: List of database names protected from deletion. |
|
|
37
|
+
| **forcedeletecolumn** | `Boolean`: If true, allow dropping column even if referanced by any other column. |
|
|
38
|
+
| **forceupdatecolumn** | `Boolean`: If true, allow updating column even if referanced by any other column. `default: true` |
|
|
215
39
|
|
|
216
|
-
|
|
40
|
+
### Configuration Example
|
|
41
|
+
`JavaScript`
|
|
217
42
|
```js
|
|
218
|
-
|
|
219
|
-
```
|
|
220
|
-
Full Example Config File
|
|
221
|
-
```js
|
|
222
|
-
{
|
|
43
|
+
const config = {
|
|
223
44
|
user: "root",
|
|
224
45
|
password: "password123",
|
|
225
46
|
host: "localhost",
|
|
@@ -228,88 +49,33 @@ Full Example Config File
|
|
|
228
49
|
droptable: true,
|
|
229
50
|
dropcol: false,
|
|
230
51
|
donttouch: ["production_db", "analytics_db"],
|
|
231
|
-
sep: "_"
|
|
232
|
-
}
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
This configuration will:
|
|
236
|
-
|
|
237
|
-
- Connect to MySQL using the given credentials
|
|
238
|
-
- Drop databases and tables if they exist
|
|
239
|
-
- Preserve "production_db" and "analytics_db"
|
|
240
|
-
- Avoid dropping columns
|
|
241
|
-
- Use _ as a separator internally
|
|
242
|
-
|
|
243
|
-
## Installation
|
|
244
|
-
|
|
245
|
-
DBTASKER is available via npm.
|
|
246
|
-
|
|
247
|
-
Install it using either of the following commands:
|
|
248
|
-
```js
|
|
249
|
-
npm install dbtasker
|
|
250
|
-
```
|
|
251
|
-
|
|
252
|
-
or
|
|
253
|
-
```js
|
|
254
|
-
npm i dbtasker
|
|
255
|
-
```
|
|
256
|
-
Usage
|
|
257
|
-
|
|
258
|
-
DBTASKER is designed to be simple and declarative. You provide:
|
|
259
|
-
|
|
260
|
-
1. A configuration object (database credentials + behavior options)
|
|
261
|
-
|
|
262
|
-
2. A JSON schema object (database, tables, columns)
|
|
263
|
-
|
|
264
|
-
DBTASKER handles the rest.
|
|
265
|
-
|
|
266
|
-
#### Step 1: Import DBTASKER
|
|
267
|
-
|
|
268
|
-
Create a JavaScript file (for example: index.js) and import DBTASKER.
|
|
269
|
-
```js
|
|
270
|
-
Using require (CommonJS)
|
|
271
|
-
const dbtasker = require("dbtasker");
|
|
272
|
-
|
|
273
|
-
Using import (ES Module)
|
|
274
|
-
import dbtasker from "dbtasker";
|
|
275
|
-
```
|
|
276
|
-
|
|
277
|
-
#### Step 2: Create a Configuration Object
|
|
278
|
-
|
|
279
|
-
This object defines how DBTASKER connects to the database and how it behaves.
|
|
280
|
-
```js
|
|
281
|
-
const config = {
|
|
282
|
-
host: "localhost",
|
|
283
|
-
user: "root",
|
|
284
|
-
password: "password",
|
|
285
|
-
port: 3306
|
|
52
|
+
sep: "_"
|
|
286
53
|
};
|
|
287
54
|
```
|
|
288
55
|
|
|
289
|
-
You can later extend this config with options like:
|
|
290
56
|
|
|
291
|
-
- Drop database
|
|
292
|
-
- Drop tables
|
|
293
|
-
- Drop columns
|
|
294
|
-
- Reserved / protected databases
|
|
295
57
|
|
|
296
|
-
|
|
58
|
+
## π Schema Structure
|
|
59
|
+
The schema follows a strict nested hierarchy:
|
|
60
|
+
|
|
61
|
+
```Database β Table β Column β Properties```
|
|
297
62
|
|
|
298
|
-
|
|
63
|
+
`JavaScript`
|
|
299
64
|
```js
|
|
300
65
|
const schema = {
|
|
301
|
-
|
|
66
|
+
app_db: {
|
|
302
67
|
users: {
|
|
303
68
|
id: {
|
|
304
69
|
type: "int",
|
|
305
|
-
|
|
306
|
-
|
|
70
|
+
primarykey: true,
|
|
71
|
+
autoincrement: true
|
|
307
72
|
},
|
|
308
73
|
email: {
|
|
309
74
|
type: "varchar",
|
|
310
75
|
length: 255,
|
|
311
76
|
required: true,
|
|
312
|
-
unique: true
|
|
77
|
+
unique: true,
|
|
78
|
+
comment: "User email address"
|
|
313
79
|
},
|
|
314
80
|
created_at: {
|
|
315
81
|
type: "timestamp",
|
|
@@ -320,215 +86,89 @@ const schema = {
|
|
|
320
86
|
};
|
|
321
87
|
```
|
|
322
88
|
|
|
323
|
-
DBTASKER supports multiple aliases for column keys and is case-insensitive.
|
|
324
89
|
|
|
325
|
-
#### Step 4: Run DBTASKER
|
|
326
90
|
|
|
327
|
-
|
|
91
|
+
## π Foreign Keys
|
|
92
|
+
Foreign keys are defined inline within the column property to reference another table's column.
|
|
93
|
+
`JavaScript`
|
|
328
94
|
```js
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
- Create or alter databases, tables, and columns
|
|
338
|
-
- Apply indexes, foreign keys, defaults, and constraints
|
|
339
|
-
|
|
340
|
-
### Full Minimal Example
|
|
341
|
-
```js
|
|
342
|
-
const DBTASKER = require("dbtasker");
|
|
343
|
-
|
|
344
|
-
const config = {
|
|
345
|
-
host: "localhost",
|
|
346
|
-
user: "root",
|
|
347
|
-
password: "password",
|
|
348
|
-
port: 3306,
|
|
349
|
-
droptable: true,
|
|
350
|
-
droptable: true,
|
|
351
|
-
dropcolumn: true,
|
|
352
|
-
donotdelete: ['test', 'example']
|
|
353
|
-
};
|
|
354
|
-
|
|
355
|
-
const schema = {
|
|
356
|
-
app_db: {
|
|
357
|
-
users: {
|
|
358
|
-
id: {
|
|
359
|
-
type: "int",
|
|
360
|
-
primarykey: true,
|
|
361
|
-
autoincrement: true
|
|
362
|
-
},
|
|
363
|
-
name: {
|
|
364
|
-
type: "varchar",
|
|
365
|
-
length: 100,
|
|
366
|
-
required: true
|
|
367
|
-
}
|
|
368
|
-
}
|
|
95
|
+
ColumnTwo: {
|
|
96
|
+
type: "int",
|
|
97
|
+
index: "key",
|
|
98
|
+
foreign_key: {
|
|
99
|
+
table: "user",
|
|
100
|
+
column: "id",
|
|
101
|
+
delete: "CASCADE", // Options: true, "SET NULL", "RESTRICT", etc.
|
|
102
|
+
update: true
|
|
369
103
|
}
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
DBTASKER(config, schema);
|
|
373
|
-
```
|
|
374
|
-
|
|
375
|
-
**Notes**
|
|
376
|
-
|
|
377
|
-
### Important:
|
|
378
|
-
- The config object must always come first
|
|
379
|
-
- The schema JSON object must come second
|
|
380
|
-
- All keys are case-insensitive
|
|
381
|
-
- Multiple aliases are supported for maximum flexibility
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
## Column Key Aliases (Case-Insensitive)
|
|
385
|
-
DBTASKER allows multiple aliases for each column property. Keys are normalized internally.
|
|
386
|
-
|
|
387
|
-
**Length / Size / Precision**
|
|
388
|
-
You can use these as key when declearing column property inside table object inside JSON object without caring for case sensitivity.
|
|
389
|
-
```js
|
|
390
|
-
lengthvalue, length_value, size, scale, lengths,
|
|
391
|
-
length, value, values, range, maxlength, max_length, precision
|
|
392
|
-
```
|
|
393
|
-
|
|
394
|
-
**Column Type / Data Type**
|
|
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
|
-
type, columntype, column_type,
|
|
398
|
-
datatype, data_type, typename, type_name
|
|
399
|
-
```
|
|
400
|
-
|
|
401
|
-
**Zerofill**
|
|
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
|
-
zerofill, zero_fill, iszerofill, zerofillup
|
|
104
|
+
}
|
|
405
105
|
```
|
|
106
|
+
### Foreign Key Properties
|
|
107
|
+
| Property | Description |
|
|
108
|
+
| :---: | :--- |
|
|
109
|
+
| `table` | Referenced table name |
|
|
110
|
+
| `column` | Referenced column name |
|
|
111
|
+
| `delete` | `ON DELETE` behavior (CASCADE, SET NULL, RESTRICT, NO ACTION) |
|
|
112
|
+
| `update` | `ON UPDATE` behavior (CASCADE, SET NULL, RESTRICT, NO ACTION) |
|
|
406
113
|
|
|
407
|
-
**Auto Increment / Identity**
|
|
408
|
-
You can use these as key when declearing column property inside table object inside JSON object without caring for case sensitivity.
|
|
409
|
-
```js
|
|
410
|
-
autoincrement, auto_increment, increment,
|
|
411
|
-
serial, generated, isidentity, identity
|
|
412
|
-
```
|
|
413
114
|
|
|
414
|
-
**Signed / Unsigned**
|
|
415
|
-
You can use these as key when declearing column property inside table object inside JSON object without caring for case sensitivity.
|
|
416
|
-
```js
|
|
417
|
-
signed, issigned, numericunsigned, numeric_unsigned,
|
|
418
|
-
unsigned, isunsigned
|
|
419
|
-
```
|
|
420
115
|
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
```js
|
|
424
|
-
default, defaults, defaultvalue, default_value,
|
|
425
|
-
example, sample, columndefault, column_default
|
|
426
|
-
```
|
|
116
|
+
## π Property Aliases
|
|
117
|
+
`dbtasker` is highly flexible and accepts multiple aliases for each column property. All keys are **case-insensitive.**
|
|
427
118
|
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
119
|
+
| Feature | Supported Aliases |
|
|
120
|
+
| :--- | :--- |
|
|
121
|
+
| **Type** | `type, columntype, column_type, datatype, data_type, typename, type_name` |
|
|
122
|
+
| **Length** | `length, size, scale, value, range, precision, maxlength, lengthvalue` |
|
|
123
|
+
| **Zerofill** | `zerofill, zero_fill, iszerofill, zerofillup, zero, fillzero, fill_zero, iszero` |
|
|
124
|
+
| **Unsigned** | `unsigned, signed, issigned, isunsigned, numericsigned, numericunsigned` |
|
|
125
|
+
| **Identity** | `autoincrement, auto_increment, increment, generated, isidentity, serial, identity` |
|
|
126
|
+
| **Default** | `default, defaults, defaultvalue, default_value, example, sample, columndefault, column_default` |
|
|
127
|
+
| **Index** | `index, indexkey, index_key, indexing` |
|
|
128
|
+
| `PrimaryKey` | `primarykey, primary_key, primary, isprimary, isprimarykey` |
|
|
129
|
+
| `UniqueKey` | `unique, isunique, isuniquekey, uniqueindex, uniquekey, unique_index, unique_key` |
|
|
130
|
+
| `FulltextKey` | `fulltext, fulltextindex, isfulltextkey, fulltextkey, fulltext_key, isfulltext` |
|
|
131
|
+
| `SpatialKey` | `spatial, spatialindex, isspatialkey, spatialkey, spatial_key, isspatial` |
|
|
132
|
+
| **Nullability** | `null, nulls, nullable, optional, isnulable, allownull, canbenull, notnull, not_null, nonnullable, notnullable, required, disallownull, non_nullable, not_nullable, disallow_null` |
|
|
133
|
+
| **Comments** | `comment, comments, columncomment, column_comment, description, label, helptext, hint, note` |
|
|
134
|
+
| **ForeignKey** | `fk, fuck, foreign_key, foreignkey` |
|
|
435
135
|
|
|
436
|
-
**Allow NULL / Optional**
|
|
437
|
-
```js
|
|
438
|
-
null, nulls, nullable, optional, isnulable, allownull, canbenull
|
|
439
|
-
```
|
|
440
136
|
|
|
441
|
-
**Index / Key**
|
|
442
|
-
You can use these as key when declearing column property inside table object inside JSON object without caring for case sensitivity.
|
|
443
|
-
```js
|
|
444
|
-
index, spatial, isspatial, fulltext, isfulltext,
|
|
445
|
-
isunique, isuniquekey, uniqueindex, uniquekey,
|
|
446
|
-
unique_index, unique_key,
|
|
447
|
-
primarykey, primary_key, primary, isprimary, isprimarykey,
|
|
448
|
-
indexkey, index_key, indexing
|
|
449
|
-
```
|
|
450
|
-
|
|
451
|
-
**Comments / Description / Notes**
|
|
452
|
-
You can use these as key when declearing column property inside table object inside JSON object without caring for case sensitivity.
|
|
453
|
-
```js
|
|
454
|
-
comment, comments, columncomment, column_comment,
|
|
455
|
-
description, label, helptext, hint, note
|
|
456
|
-
```
|
|
457
137
|
|
|
138
|
+
## π‘οΈ Compatibility & Engines
|
|
139
|
+
- **Node.js:** 16.x or higher
|
|
140
|
+
- **MySQL:** 5.7+ / 8.0+
|
|
141
|
+
- **Engines:** InnoDB, MyISAM, MEMORY, RocksDB, TokuDB, and more.
|
|
458
142
|
|
|
459
|
-
**Foreign Key Definition**
|
|
460
|
-
Foreign keys are defined inline to reference another tableβs column:
|
|
461
|
-
```js
|
|
462
|
-
foreign_key: {
|
|
463
|
-
table: "user",
|
|
464
|
-
column: "id",
|
|
465
|
-
delete: true,
|
|
466
|
-
update: true
|
|
467
|
-
}
|
|
468
|
-
```
|
|
469
|
-
## Foreign Key Aliases (Case-Insensitive)
|
|
470
|
-
DBTASKER accepts:
|
|
471
|
-
```js
|
|
472
|
-
"fk", "fuck", "foreign_key", "foreignkey"
|
|
473
|
-
```
|
|
474
143
|
|
|
475
|
-
Foreign Key Properties & Aliases
|
|
476
|
-
Property
|
|
477
|
-
### Alias Options
|
|
478
|
-
#### Purpose
|
|
479
|
-
**Table**
|
|
480
|
-
```js
|
|
481
|
-
"table", "fktable", "fk_table", "foreignkeytable", "foreign_key_table"
|
|
482
|
-
```
|
|
483
|
-
Referenced table name
|
|
484
144
|
|
|
485
|
-
|
|
145
|
+
## π Quick Start
|
|
146
|
+
`JavaScript`
|
|
486
147
|
```js
|
|
487
|
-
|
|
488
|
-
```
|
|
489
|
-
Referenced column name
|
|
148
|
+
const dbtasker = require("dbtasker");
|
|
490
149
|
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
150
|
+
const config = {
|
|
151
|
+
host: "localhost",
|
|
152
|
+
user: "root",
|
|
153
|
+
password: "password"
|
|
154
|
+
};
|
|
496
155
|
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
156
|
+
const schema = {
|
|
157
|
+
store_db: {
|
|
158
|
+
products: {
|
|
159
|
+
id: { type: "int", primarykey: true, autoincrement: true },
|
|
160
|
+
name: { type: "varchar", length: 100, required: true }
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
};
|
|
502
164
|
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
```js
|
|
506
|
-
null, "NULL", "SET NULL", true, "DL", "DEL", "DELETE", "CASCADE", "DEFAULT", "SET DEFAULT", "RESTRICT", "NO ACTION"
|
|
165
|
+
// Connect, Validate, and Automate
|
|
166
|
+
dbtasker(config, schema);
|
|
507
167
|
```
|
|
508
168
|
|
|
509
|
-
> Notes:
|
|
510
|
-
> DBTASKER automatically normalizes all keys internally.
|
|
511
|
-
|
|
512
|
-
Foreign key constraints are generated safely and include necessary values automatically.
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
#### Use Cases
|
|
517
|
-
Schema builders and migration tools
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
#### Admin dashboards
|
|
521
|
-
Low-code / no-code backends
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
#### License
|
|
526
|
-
MIT
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
#### Author
|
|
530
|
-
Md Nasiruddin Ahmed (Manik)
|
|
531
169
|
|
|
532
|
-
---Designed for safe, flexible, and high-quality MySQL schema automation.
|
|
533
170
|
|
|
171
|
+
## π¨βπ» Author
|
|
172
|
+
**Md Nasiruddin Ahmed (Manik)** Designed for safe, flexible, and high-quality MySQL schema automation. π Visit us at: kormoi.com
|
|
534
173
|
|
|
174
|
+
**License:** MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dbtasker",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.6",
|
|
4
4
|
"description": "dbtasker is a powerful and developer-friendly MySQL schema automation tool that converts JSON-based definitions into validated SQL that allows developers to declaratively define databases, tables, columns, indexes, and foreign keys using a flexible, case-insensitive JSON schema.",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "Md Nasiruddin Ahmed",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"cstyler": "^
|
|
37
|
+
"cstyler": "^4.0.0",
|
|
38
38
|
"fs": "^0.0.1-security",
|
|
39
39
|
"mysql2": "^3.14.3",
|
|
40
40
|
"path": "^0.12.7"
|
package/validation.js
CHANGED
|
@@ -496,7 +496,7 @@ async function JSONchecker(table_json, config, separator = "_") {
|
|
|
496
496
|
/**
|
|
497
497
|
* ZEROFILL
|
|
498
498
|
*/
|
|
499
|
-
const zerofkeys = ['zerofill', 'zero_fill', 'iszerofill', 'zerofillup'];
|
|
499
|
+
const zerofkeys = ['zerofill', 'zero_fill', 'iszerofill', 'zerofillup', 'zero', 'fillzero', 'fill_zero', 'iszero'];
|
|
500
500
|
for (const item of Object.keys(deepColumn)) {
|
|
501
501
|
if (zerofkeys.includes(item.toLowerCase())) {
|
|
502
502
|
zerofill = deepColumn[item];
|