generate-dac 1.0.8 → 1.1.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/dist/DAC_Utils.js
CHANGED
|
@@ -36,6 +36,22 @@ function get_SqlDbType(type) {
|
|
|
36
36
|
sqlType: 'int'
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
|
+
if (type === 'bigint') {
|
|
40
|
+
return {
|
|
41
|
+
type: 'BigInt',
|
|
42
|
+
codeType: 'long',
|
|
43
|
+
codeGetMethodType: 'GetInt64',
|
|
44
|
+
sqlType: 'bigint'
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
if (type === 'smallint') {
|
|
48
|
+
return {
|
|
49
|
+
type: 'SmallInt',
|
|
50
|
+
codeType: 'int',
|
|
51
|
+
codeGetMethodType: 'GetInt16',
|
|
52
|
+
sqlType: 'smallint'
|
|
53
|
+
};
|
|
54
|
+
}
|
|
39
55
|
if (type === 'date') {
|
|
40
56
|
return {
|
|
41
57
|
type: 'Date',
|
|
@@ -80,16 +96,28 @@ function get_SqlDbType(type) {
|
|
|
80
96
|
sqlType: "nvarchar(".concat(length_1, ")")
|
|
81
97
|
};
|
|
82
98
|
}
|
|
99
|
+
var varcharReg = /VARCHAR\(([^\(\)]+)\)/i;
|
|
100
|
+
if (varcharReg.test(type)) {
|
|
101
|
+
var match = varcharReg.exec(type);
|
|
102
|
+
var length_2 = match ? match[1] : 250;
|
|
103
|
+
return {
|
|
104
|
+
type: 'VarChar',
|
|
105
|
+
option: length_2,
|
|
106
|
+
codeType: 'string',
|
|
107
|
+
codeGetMethodType: 'GetString',
|
|
108
|
+
sqlType: "varchar(".concat(length_2, ")")
|
|
109
|
+
};
|
|
110
|
+
}
|
|
83
111
|
var decimalReg = /Decimal\(([^\(\)]+)\)/i;
|
|
84
112
|
if (decimalReg.test(type)) {
|
|
85
113
|
var match = decimalReg.exec(type);
|
|
86
|
-
var
|
|
114
|
+
var length_3 = match ? match[1] : 250;
|
|
87
115
|
return {
|
|
88
116
|
type: 'Decimal',
|
|
89
|
-
option:
|
|
117
|
+
option: length_3,
|
|
90
118
|
codeType: 'decimal',
|
|
91
119
|
codeGetMethodType: 'GetDecimal',
|
|
92
|
-
sqlType: "decimal(".concat(
|
|
120
|
+
sqlType: "decimal(".concat(length_3, ")")
|
|
93
121
|
};
|
|
94
122
|
}
|
|
95
123
|
if (/DateTime/i.test(type)) {
|
package/dist/convert-table.js
CHANGED
|
@@ -8,13 +8,13 @@ var file_utils_1 = require("./utils/file_utils");
|
|
|
8
8
|
var table_utils_1 = require("./tables/table-utils");
|
|
9
9
|
var excel_utils_1 = require("./utils/excel-utils");
|
|
10
10
|
colors_1.default.enable();
|
|
11
|
-
var SOURCE_FILE_NAME = '
|
|
11
|
+
var SOURCE_FILE_NAME = 'source_schema.sql';
|
|
12
12
|
var SOURCE_FILE_PATH = "./input/".concat(SOURCE_FILE_NAME);
|
|
13
13
|
var sourceSchemaData = (0, file_utils_1.text_from_file)(SOURCE_FILE_PATH);
|
|
14
14
|
var sourceTables = (0, table_utils_1.schema_to_table_models)(sourceSchemaData);
|
|
15
15
|
console.log("sourceTables=".concat(sourceTables.length).green);
|
|
16
16
|
(0, excel_utils_1.json_to_file)("./output/source-schema.json", sourceTables);
|
|
17
|
-
var TARGET_FILE_NAME = '
|
|
17
|
+
var TARGET_FILE_NAME = 'target_schema.sql';
|
|
18
18
|
var TARGET_FILE_PATH = "./input/".concat(TARGET_FILE_NAME);
|
|
19
19
|
var targetSchemaData = (0, file_utils_1.text_from_file)(TARGET_FILE_PATH);
|
|
20
20
|
var targetTables = (0, table_utils_1.schema_to_table_models)(targetSchemaData);
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "generate-dac",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "jest",
|
|
8
8
|
"start": "ts-node ./src/index.ts",
|
|
9
9
|
"build": "tsc --skipLibCheck",
|
|
10
|
-
"test-build": "node ./dist/index.js"
|
|
10
|
+
"test-build": "node ./dist/index.js",
|
|
11
|
+
"schema:compare": "ts-node ./src/convert-table.ts"
|
|
11
12
|
},
|
|
12
13
|
"bin": {
|
|
13
14
|
"generate-dac": "dist/index.js"
|
|
@@ -19,7 +20,6 @@
|
|
|
19
20
|
"@types/encoding-japanese": "^2.0.1",
|
|
20
21
|
"@types/fs-extra": "^11.0.1",
|
|
21
22
|
"@types/uuid": "^8.3.4",
|
|
22
|
-
"canvas": "^2.11.2",
|
|
23
23
|
"colors": "^1.4.0",
|
|
24
24
|
"command-line-args": "^5.2.1",
|
|
25
25
|
"dayjs": "^1.11.10",
|
package/src/DAC_Utils.ts
CHANGED
|
@@ -27,9 +27,9 @@ 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' | 'Decimal' | 'Date' | 'NText';
|
|
31
|
-
export type CSharpType = 'int' | 'string' | 'DateTime' | 'bool' | 'decimal';
|
|
32
|
-
export type CShareGetMethodType = '' | 'GetDateTime' | 'GetInt32' | 'GetBoolean' | 'GetString' | 'GetByte' | 'GetDecimal';
|
|
30
|
+
export type SqlDbTypeType = '' | 'Int' | 'TinyInt' | 'NVarChar' | 'DateTime' | 'Bit' | 'Money' | 'Decimal' | 'Date' | 'NText' | 'VarChar' | 'BigInt' | 'SmallInt';
|
|
31
|
+
export type CSharpType = 'int' | 'string' | 'DateTime' | 'bool' | 'decimal' | 'long';
|
|
32
|
+
export type CShareGetMethodType = '' | 'GetDateTime' | 'GetInt32' | 'GetBoolean' | 'GetString' | 'GetByte' | 'GetDecimal' | 'GetInt64' | 'GetInt16';
|
|
33
33
|
|
|
34
34
|
|
|
35
35
|
export interface SqlDbType{
|
|
@@ -52,6 +52,24 @@ export function get_SqlDbType(type: string): SqlDbType{
|
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
if(type === 'bigint'){
|
|
56
|
+
return {
|
|
57
|
+
type: 'BigInt',
|
|
58
|
+
codeType: 'long',
|
|
59
|
+
codeGetMethodType: 'GetInt64',
|
|
60
|
+
sqlType: 'bigint'
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if(type === 'smallint'){
|
|
65
|
+
return {
|
|
66
|
+
type: 'SmallInt',
|
|
67
|
+
codeType: 'int',
|
|
68
|
+
codeGetMethodType: 'GetInt16',
|
|
69
|
+
sqlType: 'smallint'
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
55
73
|
if(type === 'date'){
|
|
56
74
|
return {
|
|
57
75
|
type: 'Date',
|
|
@@ -99,6 +117,19 @@ export function get_SqlDbType(type: string): SqlDbType{
|
|
|
99
117
|
};
|
|
100
118
|
}
|
|
101
119
|
|
|
120
|
+
const varcharReg = /VARCHAR\(([^\(\)]+)\)/i;
|
|
121
|
+
if(varcharReg.test(type)){
|
|
122
|
+
const match = varcharReg.exec(type);
|
|
123
|
+
const length = match ? match[1] : 250;
|
|
124
|
+
return {
|
|
125
|
+
type: 'VarChar',
|
|
126
|
+
option: length,
|
|
127
|
+
codeType: 'string',
|
|
128
|
+
codeGetMethodType: 'GetString',
|
|
129
|
+
sqlType: `varchar(${length})`
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
102
133
|
const decimalReg = /Decimal\(([^\(\)]+)\)/i;
|
|
103
134
|
if(decimalReg.test(type)){
|
|
104
135
|
const match = decimalReg.exec(type);
|
package/src/convert-table.ts
CHANGED
|
@@ -4,12 +4,12 @@ import fs from 'fs';
|
|
|
4
4
|
import { text_from_file } from "./utils/file_utils";
|
|
5
5
|
import { schema_to_table_models, table_compares } from './tables/table-utils';
|
|
6
6
|
import { json_to_file } from './utils/excel-utils';
|
|
7
|
-
import { createCanvas } from 'canvas';
|
|
7
|
+
// import { createCanvas } from 'canvas';
|
|
8
8
|
import { SQLTable } from './tables/sql-interface';
|
|
9
9
|
|
|
10
10
|
colors.enable();
|
|
11
11
|
|
|
12
|
-
const SOURCE_FILE_NAME = '
|
|
12
|
+
const SOURCE_FILE_NAME = 'source_schema.sql';
|
|
13
13
|
const SOURCE_FILE_PATH = `./input/${SOURCE_FILE_NAME}`;
|
|
14
14
|
|
|
15
15
|
const sourceSchemaData = text_from_file(SOURCE_FILE_PATH);
|
|
@@ -17,7 +17,7 @@ const sourceTables = schema_to_table_models(sourceSchemaData);
|
|
|
17
17
|
console.log(`sourceTables=${sourceTables.length}`.green);
|
|
18
18
|
json_to_file(`./output/source-schema.json`, sourceTables);
|
|
19
19
|
|
|
20
|
-
const TARGET_FILE_NAME = '
|
|
20
|
+
const TARGET_FILE_NAME = 'target_schema.sql';
|
|
21
21
|
const TARGET_FILE_PATH = `./input/${TARGET_FILE_NAME}`;
|
|
22
22
|
|
|
23
23
|
const targetSchemaData = text_from_file(TARGET_FILE_PATH);
|
|
@@ -119,46 +119,6 @@ namespace XHS.DataAccess
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
}
|
|
122
|
-
|
|
123
|
-
public int Delete({Table_Name_Plural} obj{Table_Name_Plural})
|
|
124
|
-
{
|
|
125
|
-
int intRowsAffected = 0;
|
|
126
|
-
|
|
127
|
-
if (obj{Table_Name_Plural}.Collection.Length == 0)
|
|
128
|
-
return 0;
|
|
129
|
-
|
|
130
|
-
SqlTransaction dbTransaction = objDBConnection.BeginTransaction();
|
|
131
|
-
|
|
132
|
-
try
|
|
133
|
-
{
|
|
134
|
-
SqlCommand dbCommand = new SqlCommand();
|
|
135
|
-
|
|
136
|
-
dbCommand.Connection = objDBConnection;
|
|
137
|
-
dbCommand.CommandTimeout = 30;
|
|
138
|
-
dbCommand.CommandType = CommandType.StoredProcedure;
|
|
139
|
-
dbCommand.CommandText = "xhs_sp_del_{table_name_lower}";
|
|
140
|
-
dbCommand.Transaction = dbTransaction;
|
|
141
|
-
|
|
142
|
-
for (int i = 0; i < obj{Table_Name_Plural}.Collection.Length; i++)
|
|
143
|
-
{
|
|
144
|
-
dbCommand.Parameters.Clear();
|
|
145
|
-
|
|
146
|
-
CreateParameter(dbCommand, "@ID", SqlDbType.Int, obj{Table_Name_Plural}.Collection[i].ID);
|
|
147
|
-
|
|
148
|
-
intRowsAffected += dbCommand.ExecuteNonQuery();
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
dbTransaction.Commit();
|
|
152
|
-
dbCommand.Dispose();
|
|
153
|
-
return intRowsAffected;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
catch (Exception e)
|
|
157
|
-
{
|
|
158
|
-
dbTransaction.Rollback();
|
|
159
|
-
throw new ApplicationException("Error occurred during attempt to delete record into XHS {Table_Name} table and has been rolled-back.", e);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
122
|
|
|
163
123
|
protected void Fill(SqlDataReader objDataReader, ref {Table_Name} obj{Table_Name})
|
|
164
124
|
{
|
|
@@ -267,6 +227,47 @@ namespace XHS.DataAccess
|
|
|
267
227
|
throw new ApplicationException("Error occurred during attempt to read record from XHS {Table_Name} table.", e);
|
|
268
228
|
}
|
|
269
229
|
|
|
270
|
-
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
public int SoftDelete({Table_Name_Plural} obj{Table_Name_Plural}, int userAccountID)
|
|
233
|
+
{
|
|
234
|
+
int intRowsAffected = 0;
|
|
235
|
+
|
|
236
|
+
if (obj{Table_Name_Plural}.Collection.Length == 0)
|
|
237
|
+
return 0;
|
|
238
|
+
|
|
239
|
+
SqlTransaction dbTransaction = objDBConnection.BeginTransaction();
|
|
240
|
+
|
|
241
|
+
try
|
|
242
|
+
{
|
|
243
|
+
SqlCommand dbCommand = new SqlCommand();
|
|
244
|
+
|
|
245
|
+
dbCommand.Connection = objDBConnection;
|
|
246
|
+
dbCommand.CommandTimeout = 30;
|
|
247
|
+
dbCommand.CommandType = CommandType.StoredProcedure;
|
|
248
|
+
dbCommand.CommandText = "xhs_sp_soft_del_{table_name_lower}";
|
|
249
|
+
dbCommand.Transaction = dbTransaction;
|
|
250
|
+
|
|
251
|
+
for (int i = 0; i < obj{Table_Name_Plural}.Collection.Length; i++)
|
|
252
|
+
{
|
|
253
|
+
dbCommand.Parameters.Clear();
|
|
254
|
+
|
|
255
|
+
CreateParameter(dbCommand, "@ID", SqlDbType.Int, obj{Table_Name_Plural}.Collection[i].ID);
|
|
256
|
+
CreateParameter(dbCommand, "@UserAccountID", SqlDbType.Int, userAccountID);
|
|
257
|
+
|
|
258
|
+
intRowsAffected += dbCommand.ExecuteNonQuery();
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
dbTransaction.Commit();
|
|
262
|
+
dbCommand.Dispose();
|
|
263
|
+
return intRowsAffected;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
catch (Exception e)
|
|
267
|
+
{
|
|
268
|
+
dbTransaction.Rollback();
|
|
269
|
+
throw new ApplicationException("Error occurred during attempt to soft delete record into XHS {Table_Name} table and has been rolled-back.", e);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
271
272
|
}
|
|
272
273
|
}
|
|
@@ -61,26 +61,6 @@ BEGIN
|
|
|
61
61
|
END
|
|
62
62
|
GO
|
|
63
63
|
|
|
64
|
-
/****** Object: StoredProcedure [dbo].[xhs_sp_del_{table_name_lower}] Script Date: {datetime} ******/
|
|
65
|
-
IF EXISTS (select * from dbo.sysobjects where id = object_id(N'[dbo].[xhs_sp_del_{table_name_lower}]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
|
|
66
|
-
DROP PROCEDURE [dbo].[xhs_sp_del_{table_name_lower}]
|
|
67
|
-
GO
|
|
68
|
-
|
|
69
|
-
SET ANSI_NULLS ON
|
|
70
|
-
GO
|
|
71
|
-
SET QUOTED_IDENTIFIER ON
|
|
72
|
-
GO
|
|
73
|
-
CREATE PROCEDURE [dbo].[xhs_sp_del_{table_name_lower}]
|
|
74
|
-
|
|
75
|
-
@ID int
|
|
76
|
-
|
|
77
|
-
AS
|
|
78
|
-
|
|
79
|
-
DELETE [dbo].[{table_name}]
|
|
80
|
-
WHERE
|
|
81
|
-
[ID] = @ID
|
|
82
|
-
GO
|
|
83
|
-
|
|
84
64
|
/****** Object: StoredProcedure [dbo].[xhs_sp_get_{table_name_lower}_all] Script Date: {datetime} ******/
|
|
85
65
|
IF EXISTS (select * from dbo.sysobjects where id = object_id(N'[dbo].[xhs_sp_get_{table_name_lower}_all]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
|
|
86
66
|
DROP PROCEDURE [dbo].[xhs_sp_get_{table_name_lower}_all]
|
|
@@ -128,5 +108,24 @@ AS
|
|
|
128
108
|
t1.[ID] = @ID
|
|
129
109
|
GO
|
|
130
110
|
|
|
111
|
+
/****** Object: StoredProcedure [dbo].[xhs_sp_soft_del_{table_name_lower}] Script Date: {datetime} ******/
|
|
112
|
+
IF EXISTS (select * from dbo.sysobjects where id = object_id(N'[dbo].[xhs_sp_soft_del_{table_name_lower}]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
|
|
113
|
+
DROP PROCEDURE [dbo].[xhs_sp_soft_del_{table_name_lower}]
|
|
114
|
+
GO
|
|
131
115
|
|
|
116
|
+
SET ANSI_NULLS ON
|
|
117
|
+
GO
|
|
118
|
+
SET QUOTED_IDENTIFIER ON
|
|
119
|
+
GO
|
|
120
|
+
CREATE PROCEDURE [dbo].[xhs_sp_soft_del_{table_name_lower}]
|
|
132
121
|
|
|
122
|
+
@ID int,
|
|
123
|
+
@UserAccountID int
|
|
124
|
+
|
|
125
|
+
AS
|
|
126
|
+
|
|
127
|
+
UPDATE [dbo].[{table_name}]
|
|
128
|
+
SET Record_Status = 2, Update_DateTime = GETUTCDATE(), Update_User_Account_ID = @UserAccountID
|
|
129
|
+
WHERE
|
|
130
|
+
[ID] = @ID
|
|
131
|
+
GO
|