generate-dac 1.0.4 → 1.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/dist/DAC_Utils.js +37 -10
- package/dist/generate-table-dac/index.js +27 -0
- package/dist/handle-command-line.js +15 -0
- package/dist/index.js +2 -21
- package/dist/package-interface.js +2 -0
- package/dist/utils/excel-utils.js +7 -1
- package/package.json +1 -1
- package/src/DAC_Utils.ts +26 -2
- package/src/utils/excel-utils.ts +9 -2
package/dist/DAC_Utils.js
CHANGED
|
@@ -36,6 +36,14 @@ function get_SqlDbType(type) {
|
|
|
36
36
|
sqlType: 'int'
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
|
+
if (type === 'date') {
|
|
40
|
+
return {
|
|
41
|
+
type: 'Date',
|
|
42
|
+
codeType: 'DateTime',
|
|
43
|
+
codeGetMethodType: 'GetDateTime',
|
|
44
|
+
sqlType: 'date'
|
|
45
|
+
};
|
|
46
|
+
}
|
|
39
47
|
if (type === 'money') {
|
|
40
48
|
return {
|
|
41
49
|
type: 'Money',
|
|
@@ -64,6 +72,18 @@ function get_SqlDbType(type) {
|
|
|
64
72
|
sqlType: "nvarchar(".concat(length_1, ")")
|
|
65
73
|
};
|
|
66
74
|
}
|
|
75
|
+
var decimalReg = /Decimal\(([^\(\)]+)\)/i;
|
|
76
|
+
if (decimalReg.test(type)) {
|
|
77
|
+
var match = decimalReg.exec(type);
|
|
78
|
+
var length_2 = match ? match[1] : 250;
|
|
79
|
+
return {
|
|
80
|
+
type: 'Decimal',
|
|
81
|
+
option: length_2,
|
|
82
|
+
codeType: 'decimal',
|
|
83
|
+
codeGetMethodType: 'GetDecimal',
|
|
84
|
+
sqlType: "decimal(".concat(length_2, ")")
|
|
85
|
+
};
|
|
86
|
+
}
|
|
67
87
|
if (/DateTime/i.test(type)) {
|
|
68
88
|
return {
|
|
69
89
|
type: 'DateTime',
|
|
@@ -114,6 +134,7 @@ function dac_generate_data_access(tableName, schemas) {
|
|
|
114
134
|
var createUserStr = createUserFields.map(function (e, i) { return "".concat(e, " = ").concat(schemas.length + i); }).join(",\n\t\t\t");
|
|
115
135
|
columnEnumStr += ",\n\t\t\t" + createUserStr;
|
|
116
136
|
}
|
|
137
|
+
var tableNamePlural = (0, str_utils_1.str_plural)(tableName);
|
|
117
138
|
var insertParamsStart = schemas.filter(function (e) {
|
|
118
139
|
return e.col_name !== 'ID'
|
|
119
140
|
&& e.col_name !== 'Create_DateTime'
|
|
@@ -121,9 +142,9 @@ function dac_generate_data_access(tableName, schemas) {
|
|
|
121
142
|
}).map(function (e, i) {
|
|
122
143
|
var types = get_SqlDbType(e.type);
|
|
123
144
|
if (types.type === 'DateTime') {
|
|
124
|
-
return "CreateParameter(dbCommand, \"@".concat(e.col_name, "\", SqlDbType.").concat(types.type, ", FixDBDateTime(obj").concat(
|
|
145
|
+
return "CreateParameter(dbCommand, \"@".concat(e.col_name, "\", SqlDbType.").concat(types.type, ", FixDBDateTime(obj").concat(tableNamePlural, ".Collection[i].").concat(e.col_name, "));");
|
|
125
146
|
}
|
|
126
|
-
return "CreateParameter(dbCommand, \"@".concat(e.col_name, "\", SqlDbType.").concat(types.type, ", obj").concat(
|
|
147
|
+
return "CreateParameter(dbCommand, \"@".concat(e.col_name, "\", SqlDbType.").concat(types.type, ", obj").concat(tableNamePlural, ".Collection[i].").concat(e.col_name, ");");
|
|
127
148
|
}).join("\n" + repeat("\t", 5));
|
|
128
149
|
var updateParamsStart = schemas.filter(function (e) {
|
|
129
150
|
return e.col_name !== 'Create_DateTime'
|
|
@@ -132,9 +153,9 @@ function dac_generate_data_access(tableName, schemas) {
|
|
|
132
153
|
}).map(function (e, i) {
|
|
133
154
|
var types = get_SqlDbType(e.type);
|
|
134
155
|
if (types.type === 'DateTime') {
|
|
135
|
-
return "CreateParameter(dbCommand, \"@".concat(e.col_name, "\", SqlDbType.").concat(types.type, ", FixDBDateTime(obj").concat(
|
|
156
|
+
return "CreateParameter(dbCommand, \"@".concat(e.col_name, "\", SqlDbType.").concat(types.type, ", FixDBDateTime(obj").concat(tableNamePlural, ".Collection[i].").concat(e.col_name, "));");
|
|
136
157
|
}
|
|
137
|
-
return "CreateParameter(dbCommand, \"@".concat(e.col_name, "\", SqlDbType.").concat(types.type, ", obj").concat(
|
|
158
|
+
return "CreateParameter(dbCommand, \"@".concat(e.col_name, "\", SqlDbType.").concat(types.type, ", obj").concat(tableNamePlural, ".Collection[i].").concat(e.col_name, ");");
|
|
138
159
|
}).join("\n" + repeat("\t", 5));
|
|
139
160
|
var fillStr = schemas.map(function (e, i) {
|
|
140
161
|
return "\t\t\tif (!objDataReader.IsDBNull((int)".concat(tableName, "Column.").concat(e.col_name, "))\n\t\t\t\tobj").concat(tableName, ".").concat(e.col_name, " = objDataReader.").concat(get_SqlDbType(e.type).codeGetMethodType, "((int)").concat(tableName, "Column.").concat(e.col_name, ");");
|
|
@@ -150,6 +171,7 @@ function dac_generate_data_access(tableName, schemas) {
|
|
|
150
171
|
}
|
|
151
172
|
var dacTemplateGeneratedContentOutput = binding_template(dacTemplateGeneratedContent, {
|
|
152
173
|
Table_Name: tableName,
|
|
174
|
+
Table_Name_Plural: tableNamePlural,
|
|
153
175
|
table_name_lower: tableName.toLowerCase(),
|
|
154
176
|
table_column_enum: columnEnumStr,
|
|
155
177
|
insert_params: insertParamsStart,
|
|
@@ -245,7 +267,7 @@ function dac_generate_dataServiceObject(tableName, schemas) {
|
|
|
245
267
|
};
|
|
246
268
|
var classTemplate = (0, file_utils_1.text_from_file)("".concat(TEMPLATE_DIR, "/templates/DataServiceObjects_Class_Template.cs"));
|
|
247
269
|
var strProperties = schemas.map(function (e, i) {
|
|
248
|
-
return "public ".concat(get_SqlDbType(e.type).codeType, " ").concat(e.col_name.replace(/[ _]+/g, ''), " { get; set; }");
|
|
270
|
+
return "public ".concat(e.enum || get_SqlDbType(e.type).codeType, " ").concat(e.col_name.replace(/[ _]+/g, ''), " { get; set; }");
|
|
249
271
|
}).join('\n' + repeat("\t", 2));
|
|
250
272
|
var created_by_user = '';
|
|
251
273
|
var updated_by_user = '';
|
|
@@ -256,10 +278,13 @@ function dac_generate_dataServiceObject(tableName, schemas) {
|
|
|
256
278
|
updated_by_user = "public RPMAdminUser UpdatedByUser { get; set; }";
|
|
257
279
|
}
|
|
258
280
|
var className = get_className(tableName);
|
|
281
|
+
var tableNameLower = tableName.toLowerCase();
|
|
282
|
+
var classNamePlural = (0, str_utils_1.str_plural)(className);
|
|
259
283
|
var classStr = binding_template(classTemplate, {
|
|
260
284
|
table_name: tableName,
|
|
261
|
-
table_name_lower:
|
|
285
|
+
table_name_lower: tableNameLower,
|
|
262
286
|
class_name: className,
|
|
287
|
+
class_name_plural: classNamePlural,
|
|
263
288
|
properties: strProperties,
|
|
264
289
|
created_by_user: created_by_user,
|
|
265
290
|
updated_by_user: updated_by_user,
|
|
@@ -268,8 +293,9 @@ function dac_generate_dataServiceObject(tableName, schemas) {
|
|
|
268
293
|
result.classes.push(classStr);
|
|
269
294
|
var content = binding_template(DataServiceObjects_Template, {
|
|
270
295
|
table_name: tableName,
|
|
271
|
-
table_name_lower:
|
|
296
|
+
table_name_lower: tableNameLower,
|
|
272
297
|
class_name: className,
|
|
298
|
+
class_name_plural: classNamePlural,
|
|
273
299
|
datetime: CREATED_DATETIME,
|
|
274
300
|
content: classStr
|
|
275
301
|
});
|
|
@@ -286,7 +312,7 @@ function dac_generate_conversions(tableName, schemas) {
|
|
|
286
312
|
var className = get_className(tableName);
|
|
287
313
|
var methodTemplate = (0, file_utils_1.text_from_file)("".concat(TEMPLATE_DIR, "/templates/MakeDSO_Template_Method.cs"));
|
|
288
314
|
var dsoFields = schemas.map(function (e, i) {
|
|
289
|
-
return "ds".concat(className, ".").concat(e.colName, " = db").concat(className, ".").concat(e.col_name, ";");
|
|
315
|
+
return "ds".concat(className, ".").concat(e.colName, " =").concat(e.enum ? "(".concat(e.enum, ")") : '', " db").concat(className, ".").concat(e.col_name, ";");
|
|
290
316
|
}).join('\n' + repeat("\t", 3));
|
|
291
317
|
var dbFields = schemas.map(function (e, i) {
|
|
292
318
|
var type = get_SqlDbType(e.type);
|
|
@@ -296,7 +322,7 @@ function dac_generate_conversions(tableName, schemas) {
|
|
|
296
322
|
if (type.codeType === 'DateTime') {
|
|
297
323
|
return "db".concat(className, ".").concat(e.col_name, " = DateTimeHelper.MakeDBDefaultValue(ds").concat(className, ".").concat(e.colName, ");");
|
|
298
324
|
}
|
|
299
|
-
return "db".concat(className, ".").concat(e.col_name, " = ds").concat(className, ".").concat(e.colName, ";");
|
|
325
|
+
return "db".concat(className, ".").concat(e.col_name, " = ds").concat(className, ".").concat(e.colName).concat(e.enum ? ".GetHashCode()" : '', ";");
|
|
300
326
|
}).join('\n' + repeat("\t", 3));
|
|
301
327
|
var created_by_user = '';
|
|
302
328
|
var updated_by_user = '';
|
|
@@ -449,6 +475,7 @@ function DAC_Generate_From_XLSX(filePath, sheetIndex) {
|
|
|
449
475
|
var outputFolder = (0, file_utils_1.get_filename_without_extension)(filePath);
|
|
450
476
|
console.log("DAC_Generate_From_XLSX: ".concat(outputFolder).yellow);
|
|
451
477
|
var sheets = (0, excel_utils_1.json_read_all_sheets_from_excel)(filePath, { sheetIndex: sheetIndex, transformColumnName: true });
|
|
478
|
+
(0, excel_utils_1.json_to_file)(filePath.replace('xlsx', 'json'), sheets);
|
|
452
479
|
var schemas = [];
|
|
453
480
|
var stores = [];
|
|
454
481
|
var dropTables = [];
|
|
@@ -540,7 +567,7 @@ function DAC_Generate_From_XLSX(filePath, sheetIndex) {
|
|
|
540
567
|
name: 'table_schema.sql',
|
|
541
568
|
content: schemas.join("\n\n\n")
|
|
542
569
|
});
|
|
543
|
-
var content = "
|
|
570
|
+
var content = "".concat(dropConstrains.filter(function (e) { return e; }).join("\nGO\n"), "\n \n").concat(dropTables.join("\nGO\n"));
|
|
544
571
|
files.push({
|
|
545
572
|
name: 'table_schema_reset.sql',
|
|
546
573
|
content: content
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.start_generate_dac_for_new_table = void 0;
|
|
7
|
+
var dayjs_1 = __importDefault(require("dayjs"));
|
|
8
|
+
var DAC_Utils_1 = require("../DAC_Utils");
|
|
9
|
+
var file_utils_1 = require("../utils/file_utils");
|
|
10
|
+
function start_generate_dac_for_new_table(INPUT_DIR) {
|
|
11
|
+
if (!(0, file_utils_1.file_exists)(INPUT_DIR)) {
|
|
12
|
+
console.log("There's no input folder. Please create input folder and put excel file to generate.".red);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
var files = (0, file_utils_1.fileName_in_folder)(INPUT_DIR);
|
|
16
|
+
if (!files || !files.length) {
|
|
17
|
+
console.log("No input files.".red);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
var now = (0, dayjs_1.default)().format('DD-ddd-YYYY HH:mm');
|
|
21
|
+
console.log("Process Generate DAC ".concat(now).green);
|
|
22
|
+
files.forEach(function (file, i) {
|
|
23
|
+
console.log("Begin to process file ".concat(file.name).yellow);
|
|
24
|
+
(0, DAC_Utils_1.DAC_Generate_From_XLSX)(file.path);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
exports.start_generate_dac_for_new_table = start_generate_dac_for_new_table;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.startProcess = void 0;
|
|
7
|
+
var command_line_args_1 = __importDefault(require("command-line-args"));
|
|
8
|
+
function startProcess(options) {
|
|
9
|
+
var optionDefinitions = [
|
|
10
|
+
{ name: 'args', type: String, multiple: true, defaultOption: true }
|
|
11
|
+
];
|
|
12
|
+
var commands = (0, command_line_args_1.default)(optionDefinitions);
|
|
13
|
+
console.log(commands);
|
|
14
|
+
}
|
|
15
|
+
exports.startProcess = startProcess;
|
package/dist/index.js
CHANGED
|
@@ -5,26 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
var colors_1 = __importDefault(require("colors"));
|
|
8
|
-
var
|
|
9
|
-
var dayjs_1 = __importDefault(require("dayjs"));
|
|
10
|
-
var file_utils_1 = require("./utils/file_utils");
|
|
8
|
+
var generate_table_dac_1 = require("./generate-table-dac");
|
|
11
9
|
colors_1.default.enable();
|
|
12
10
|
var INPUT_DIR = './input/';
|
|
13
|
-
|
|
14
|
-
function start() {
|
|
15
|
-
if (!(0, file_utils_1.file_exists)(INPUT_DIR)) {
|
|
16
|
-
console.log("There's no input folder. Please create input folder and put excel file to generate.".red);
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
var files = (0, file_utils_1.fileName_in_folder)(INPUT_DIR);
|
|
20
|
-
if (!files || !files.length) {
|
|
21
|
-
console.log("No input files.".red);
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
var now = (0, dayjs_1.default)().format('DD-ddd-YYYY HH:mm');
|
|
25
|
-
console.log("Process Generate DAC ".concat(now).green);
|
|
26
|
-
files.forEach(function (file, i) {
|
|
27
|
-
console.log("Begin to process file ".concat(file.name).yellow);
|
|
28
|
-
(0, DAC_Utils_1.DAC_Generate_From_XLSX)(file.path);
|
|
29
|
-
});
|
|
30
|
-
}
|
|
11
|
+
(0, generate_table_dac_1.start_generate_dac_for_new_table)(INPUT_DIR);
|
|
@@ -86,9 +86,15 @@ function json_read_all_sheets_from_excel(path, options) {
|
|
|
86
86
|
}
|
|
87
87
|
tmps_2.push(tmp);
|
|
88
88
|
});
|
|
89
|
+
if (options && options.disableClean) {
|
|
90
|
+
return {
|
|
91
|
+
name: sheetName,
|
|
92
|
+
data: tmps_2
|
|
93
|
+
};
|
|
94
|
+
}
|
|
89
95
|
return {
|
|
90
96
|
name: sheetName,
|
|
91
|
-
data: tmps_2
|
|
97
|
+
data: array_clean_data(tmps_2)
|
|
92
98
|
};
|
|
93
99
|
}
|
|
94
100
|
}
|
package/package.json
CHANGED
package/src/DAC_Utils.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import dayjs from "dayjs";
|
|
2
|
-
import { SheetData, json_read_all_sheets_from_excel} from "./utils/excel-utils";
|
|
2
|
+
import { SheetData, json_read_all_sheets_from_excel, json_to_file} from "./utils/excel-utils";
|
|
3
3
|
import { str_className, str_plural } from "./utils/str-utils";
|
|
4
4
|
import { ColumnSchema } from "./interface";
|
|
5
5
|
import { __parent_dir, dir_create, file_exists, get_filename_without_extension, str_to_file, text_from_file } from "./utils/file_utils";
|
|
@@ -27,7 +27,7 @@ export function binding_template(content: string, data: any){
|
|
|
27
27
|
return result;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
export type SqlDbTypeType = '' | 'Int' | 'TinyInt' | 'NVarChar' | 'DateTime' | 'Bit' | 'Money';
|
|
30
|
+
export type SqlDbTypeType = '' | 'Int' | 'TinyInt' | 'NVarChar' | 'DateTime' | 'Bit' | 'Money' | 'Decimal' | 'Date';
|
|
31
31
|
export type CSharpType = 'int' | 'string' | 'DateTime' | 'bool' | 'decimal';
|
|
32
32
|
export type CShareGetMethodType = '' | 'GetDateTime' | 'GetInt32' | 'GetBoolean' | 'GetString' | 'GetByte' | 'GetDecimal';
|
|
33
33
|
|
|
@@ -52,6 +52,15 @@ export function get_SqlDbType(type: string): SqlDbType{
|
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
if(type === 'date'){
|
|
56
|
+
return {
|
|
57
|
+
type: 'Date',
|
|
58
|
+
codeType: 'DateTime',
|
|
59
|
+
codeGetMethodType: 'GetDateTime',
|
|
60
|
+
sqlType: 'date'
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
55
64
|
if(type === 'money'){
|
|
56
65
|
return {
|
|
57
66
|
type: 'Money',
|
|
@@ -82,6 +91,19 @@ export function get_SqlDbType(type: string): SqlDbType{
|
|
|
82
91
|
};
|
|
83
92
|
}
|
|
84
93
|
|
|
94
|
+
const decimalReg = /Decimal\(([^\(\)]+)\)/i;
|
|
95
|
+
if(decimalReg.test(type)){
|
|
96
|
+
const match = decimalReg.exec(type);
|
|
97
|
+
const length = match ? match[1] : 250;
|
|
98
|
+
return {
|
|
99
|
+
type: 'Decimal',
|
|
100
|
+
option: length,
|
|
101
|
+
codeType: 'decimal',
|
|
102
|
+
codeGetMethodType: 'GetDecimal',
|
|
103
|
+
sqlType: `decimal(${length})`
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
85
107
|
if(/DateTime/i.test(type)){
|
|
86
108
|
return {
|
|
87
109
|
type: 'DateTime',
|
|
@@ -600,6 +622,8 @@ export function DAC_Generate_From_XLSX(filePath: string, sheetIndex: number = 0)
|
|
|
600
622
|
|
|
601
623
|
const sheets: SheetData[] = json_read_all_sheets_from_excel(filePath, { sheetIndex: sheetIndex, transformColumnName: true });
|
|
602
624
|
|
|
625
|
+
json_to_file(filePath.replace('xlsx', 'json'), sheets);
|
|
626
|
+
|
|
603
627
|
const schemas: string[] = [];
|
|
604
628
|
const stores: string[] = [];
|
|
605
629
|
const dropTables: string[] = [];
|
package/src/utils/excel-utils.ts
CHANGED
|
@@ -113,10 +113,17 @@ export function json_read_all_sheets_from_excel(path: string, options?: Json_rea
|
|
|
113
113
|
tmps.push(tmp);
|
|
114
114
|
});
|
|
115
115
|
|
|
116
|
+
if(options && options.disableClean){
|
|
117
|
+
return {
|
|
118
|
+
name: sheetName,
|
|
119
|
+
data: tmps
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
|
|
116
123
|
return {
|
|
117
124
|
name: sheetName,
|
|
118
|
-
data: tmps
|
|
119
|
-
}
|
|
125
|
+
data: array_clean_data(tmps)
|
|
126
|
+
}
|
|
120
127
|
}
|
|
121
128
|
}
|
|
122
129
|
|