meadow-connection-mssql 1.0.13 → 1.0.14
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/package.json +2 -2
- package/source/Meadow-Connection-MSSQL.js +78 -145
- package/source/Meadow-Schema-MSSQL.js +1027 -0
- package/test/MSSQL_tests.js +840 -1
- package/test/docker-init/02-chinook-schema.sql +203 -0
- package/test/docker-init/init-db.js +44 -37
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "meadow-connection-mssql",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.14",
|
|
4
4
|
"description": "Meadow MSSQL Plugin",
|
|
5
5
|
"main": "source/Meadow-Connection-MSSQL.js",
|
|
6
6
|
"scripts": {
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
},
|
|
49
49
|
"homepage": "https://github.com/stevenvelozo/meadow-connection-mssql",
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"fable": "^3.1.
|
|
51
|
+
"fable": "^3.1.63",
|
|
52
52
|
"quackage": "^1.0.59"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
@@ -6,6 +6,8 @@ const libFableServiceProviderBase = require('fable-serviceproviderbase');
|
|
|
6
6
|
|
|
7
7
|
const libMSSQL = require('mssql');
|
|
8
8
|
|
|
9
|
+
const libMeadowSchemaMSSQL = require('./Meadow-Schema-MSSQL.js');
|
|
10
|
+
|
|
9
11
|
/*
|
|
10
12
|
Das alt muster:
|
|
11
13
|
|
|
@@ -30,170 +32,100 @@ class MeadowConnectionMSSQL extends libFableServiceProviderBase
|
|
|
30
32
|
|
|
31
33
|
this.connected = false;
|
|
32
34
|
|
|
33
|
-
|
|
34
|
-
{
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
{
|
|
41
|
-
this.options.port = this.fable.settings.MSSQL.port;
|
|
42
|
-
}
|
|
43
|
-
else
|
|
44
|
-
{
|
|
45
|
-
this.options.port = 1433;
|
|
46
|
-
}
|
|
47
|
-
if (this.fable.settings.MSSQL.hasOwnProperty('user'))
|
|
48
|
-
{
|
|
49
|
-
this.options.user = this.fable.settings.MSSQL.user;
|
|
50
|
-
}
|
|
51
|
-
if (this.fable.settings.MSSQL.hasOwnProperty('password'))
|
|
52
|
-
{
|
|
53
|
-
this.options.password = this.fable.settings.MSSQL.password;
|
|
54
|
-
}
|
|
55
|
-
if (this.fable.settings.MSSQL.hasOwnProperty('database'))
|
|
56
|
-
{
|
|
57
|
-
this.options.database = this.fable.settings.MSSQL.database;
|
|
58
|
-
}
|
|
59
|
-
if (this.fable.settings.MSSQL.hasOwnProperty('MeadowConnectionMSSQLAutoConnect'))
|
|
60
|
-
{
|
|
61
|
-
this.options.MeadowConnectionMSSQLAutoConnect = this.fable.settings.MSSQL.MeadowConnectionMSSQLAutoConnect;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
35
|
+
// Schema provider handles DDL operations (create, drop, index, etc.)
|
|
36
|
+
this._SchemaProvider = new libMeadowSchemaMSSQL(this.fable, this.options, `${this.Hash}-Schema`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
get schemaProvider()
|
|
40
|
+
{
|
|
41
|
+
return this._SchemaProvider;
|
|
64
42
|
}
|
|
65
43
|
|
|
66
44
|
generateDropTableStatement(pTableName)
|
|
67
45
|
{
|
|
68
|
-
|
|
69
|
-
tmpDropTableStatement += ` DROP TABLE dbo.[${pTableName}];\n`;
|
|
70
|
-
tmpDropTableStatement += `GO`;
|
|
71
|
-
return tmpDropTableStatement;
|
|
46
|
+
return this._SchemaProvider.generateDropTableStatement(pTableName);
|
|
72
47
|
}
|
|
73
48
|
|
|
74
49
|
generateCreateTableStatement(pMeadowTableSchema)
|
|
75
50
|
{
|
|
76
|
-
this.
|
|
51
|
+
return this._SchemaProvider.generateCreateTableStatement(pMeadowTableSchema);
|
|
52
|
+
}
|
|
77
53
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
{
|
|
83
|
-
let tmpColumn = pMeadowTableSchema.Columns[j];
|
|
54
|
+
createTables(pMeadowSchema, fCallback)
|
|
55
|
+
{
|
|
56
|
+
return this._SchemaProvider.createTables(pMeadowSchema, fCallback);
|
|
57
|
+
}
|
|
84
58
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
59
|
+
createTable(pMeadowTableSchema, fCallback)
|
|
60
|
+
{
|
|
61
|
+
return this._SchemaProvider.createTable(pMeadowTableSchema, fCallback);
|
|
62
|
+
}
|
|
90
63
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
case 'ID':
|
|
96
|
-
// if (this.options.AllowIdentityInsert)
|
|
97
|
-
// {
|
|
98
|
-
// tmpCreateTableStatement += ` [${tmpColumn.Column}] INT NOT NULL PRIMARY KEY`;
|
|
99
|
-
// }
|
|
100
|
-
// else
|
|
101
|
-
// {
|
|
102
|
-
// There is debate on whether IDENTITY(1,1) is better or not.
|
|
103
|
-
tmpCreateTableStatement += ` [${tmpColumn.Column}] INT NOT NULL IDENTITY PRIMARY KEY`;
|
|
104
|
-
//}
|
|
105
|
-
tmpPrimaryKey = tmpColumn.Column;
|
|
106
|
-
break;
|
|
107
|
-
case 'GUID':
|
|
108
|
-
tmpCreateTableStatement += ` [${tmpColumn.Column}] VARCHAR(254) DEFAULT '00000000-0000-0000-0000-000000000000'`;
|
|
109
|
-
break;
|
|
110
|
-
case 'ForeignKey':
|
|
111
|
-
tmpCreateTableStatement += ` [${tmpColumn.Column}] INT UNSIGNED NOT NULL DEFAULT 0`;
|
|
112
|
-
tmpPrimaryKey = tmpColumn.Column;
|
|
113
|
-
break;
|
|
114
|
-
case 'Numeric':
|
|
115
|
-
tmpCreateTableStatement += ` [${tmpColumn.Column}] INT NOT NULL DEFAULT 0`;
|
|
116
|
-
break;
|
|
117
|
-
case 'Decimal':
|
|
118
|
-
tmpCreateTableStatement += ` [${tmpColumn.Column}] DECIMAL(${tmpColumn.Size})`;
|
|
119
|
-
break;
|
|
120
|
-
case 'String':
|
|
121
|
-
tmpCreateTableStatement += ` [${tmpColumn.Column}] VARCHAR(${tmpColumn.Size}) DEFAULT ''`;
|
|
122
|
-
break;
|
|
123
|
-
case 'Text':
|
|
124
|
-
tmpCreateTableStatement += ` [${tmpColumn.Column}] TEXT`;
|
|
125
|
-
break;
|
|
126
|
-
case 'DateTime':
|
|
127
|
-
tmpCreateTableStatement += ` [${tmpColumn.Column}] DATETIME`;
|
|
128
|
-
break;
|
|
129
|
-
case 'Boolean':
|
|
130
|
-
tmpCreateTableStatement += ` [${tmpColumn.Column}] TINYINT DEFAULT 0`;
|
|
131
|
-
break;
|
|
132
|
-
default:
|
|
133
|
-
break;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
if (tmpPrimaryKey)
|
|
137
|
-
{
|
|
138
|
-
// tmpCreateTableStatement += `,\n\n PRIMARY KEY (${tmpPrimaryKey$})`;
|
|
139
|
-
}
|
|
140
|
-
tmpCreateTableStatement += `\n );`;
|
|
64
|
+
getIndexDefinitionsFromSchema(pMeadowTableSchema)
|
|
65
|
+
{
|
|
66
|
+
return this._SchemaProvider.getIndexDefinitionsFromSchema(pMeadowTableSchema);
|
|
67
|
+
}
|
|
141
68
|
|
|
142
|
-
|
|
69
|
+
generateCreateIndexScript(pMeadowTableSchema)
|
|
70
|
+
{
|
|
71
|
+
return this._SchemaProvider.generateCreateIndexScript(pMeadowTableSchema);
|
|
72
|
+
}
|
|
143
73
|
|
|
144
|
-
|
|
74
|
+
generateCreateIndexStatements(pMeadowTableSchema)
|
|
75
|
+
{
|
|
76
|
+
return this._SchemaProvider.generateCreateIndexStatements(pMeadowTableSchema);
|
|
145
77
|
}
|
|
146
78
|
|
|
147
|
-
|
|
79
|
+
createIndex(pIndexStatement, fCallback)
|
|
148
80
|
{
|
|
149
|
-
|
|
150
|
-
this.fable.Utility.eachLimit(pMeadowSchema.Tables, 1,
|
|
151
|
-
(pTable, fCreateComplete) =>
|
|
152
|
-
{
|
|
153
|
-
return this.createTable(pTable, fCreateComplete)
|
|
154
|
-
},
|
|
155
|
-
(pCreateError) =>
|
|
156
|
-
{
|
|
157
|
-
if (pCreateError)
|
|
158
|
-
{
|
|
159
|
-
this.log.error(`Meadow-MSSQL Error creating tables from Schema: ${pCreateError}`,pCreateError);
|
|
160
|
-
}
|
|
161
|
-
this.log.info('Done creating tables!');
|
|
162
|
-
return fCallback(pCreateError);
|
|
163
|
-
});
|
|
81
|
+
return this._SchemaProvider.createIndex(pIndexStatement, fCallback);
|
|
164
82
|
}
|
|
165
83
|
|
|
166
|
-
|
|
84
|
+
createIndices(pMeadowTableSchema, fCallback)
|
|
167
85
|
{
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
86
|
+
return this._SchemaProvider.createIndices(pMeadowTableSchema, fCallback);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
createAllIndices(pMeadowSchema, fCallback)
|
|
90
|
+
{
|
|
91
|
+
return this._SchemaProvider.createAllIndices(pMeadowSchema, fCallback);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Database Introspection delegation
|
|
95
|
+
|
|
96
|
+
listTables(fCallback)
|
|
97
|
+
{
|
|
98
|
+
return this._SchemaProvider.listTables(fCallback);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
introspectTableColumns(pTableName, fCallback)
|
|
102
|
+
{
|
|
103
|
+
return this._SchemaProvider.introspectTableColumns(pTableName, fCallback);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
introspectTableIndices(pTableName, fCallback)
|
|
107
|
+
{
|
|
108
|
+
return this._SchemaProvider.introspectTableIndices(pTableName, fCallback);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
introspectTableForeignKeys(pTableName, fCallback)
|
|
112
|
+
{
|
|
113
|
+
return this._SchemaProvider.introspectTableForeignKeys(pTableName, fCallback);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
introspectTableSchema(pTableName, fCallback)
|
|
117
|
+
{
|
|
118
|
+
return this._SchemaProvider.introspectTableSchema(pTableName, fCallback);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
introspectDatabaseSchema(fCallback)
|
|
122
|
+
{
|
|
123
|
+
return this._SchemaProvider.introspectDatabaseSchema(fCallback);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
generateMeadowPackageFromTable(pTableName, fCallback)
|
|
127
|
+
{
|
|
128
|
+
return this._SchemaProvider.generateMeadowPackageFromTable(pTableName, fCallback);
|
|
197
129
|
}
|
|
198
130
|
|
|
199
131
|
connect()
|
|
@@ -249,6 +181,7 @@ class MeadowConnectionMSSQL extends libFableServiceProviderBase
|
|
|
249
181
|
this.log.info(`Meadow-Connection-MSSQL successfully connected to MSSQL at [${tmpConnectionSettings.server} : ${tmpConnectionSettings.port}] as ${tmpConnectionSettings.user} for database ${tmpConnectionSettings.database} at a connection limit of ${tmpConnectionSettings.pool.max}.`);
|
|
250
182
|
this._ConnectionPool = pConnectionPool;
|
|
251
183
|
this.connected = true;
|
|
184
|
+
this._SchemaProvider.setConnectionPool(this._ConnectionPool);
|
|
252
185
|
return tmpCallback(null, this._ConnectionPool)
|
|
253
186
|
})
|
|
254
187
|
.catch(
|