meadow-connection-mysql 1.0.10 → 1.0.13
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 +1 -1
- package/source/Meadow-Connection-MySQL.js +79 -120
- package/source/Meadow-Schema-MySQL.js +1127 -0
- package/test/MySQL_tests.js +833 -0
- package/test/docker-init/02-chinook-schema.sql +190 -0
package/package.json
CHANGED
|
@@ -6,6 +6,8 @@ const libFableServiceProviderBase = require('fable-serviceproviderbase');
|
|
|
6
6
|
|
|
7
7
|
const libMySQL = require('mysql2');
|
|
8
8
|
|
|
9
|
+
const libMeadowSchemaMySQL = require('./Meadow-Schema-MySQL.js');
|
|
10
|
+
|
|
9
11
|
/*
|
|
10
12
|
Das alt muster:
|
|
11
13
|
|
|
@@ -88,149 +90,105 @@ class MeadowConnectionMySQL extends libFableServiceProviderBase
|
|
|
88
90
|
this._ConnectionPool = false;
|
|
89
91
|
this.connected = false;
|
|
90
92
|
|
|
93
|
+
// Schema provider handles DDL operations (create, drop, index, etc.)
|
|
94
|
+
this._SchemaProvider = new libMeadowSchemaMySQL(this.fable, this.options, `${this.Hash}-Schema`);
|
|
95
|
+
|
|
91
96
|
if (this.options.MeadowConnectionMySQLAutoConnect)
|
|
92
97
|
{
|
|
93
98
|
this.connect();
|
|
94
99
|
}
|
|
95
100
|
}
|
|
96
101
|
|
|
102
|
+
get schemaProvider()
|
|
103
|
+
{
|
|
104
|
+
return this._SchemaProvider;
|
|
105
|
+
}
|
|
106
|
+
|
|
97
107
|
generateDropTableStatement(pTableName)
|
|
98
108
|
{
|
|
99
|
-
return
|
|
109
|
+
return this._SchemaProvider.generateDropTableStatement(pTableName);
|
|
100
110
|
}
|
|
101
111
|
|
|
102
112
|
generateCreateTableStatement(pMeadowTableSchema)
|
|
103
113
|
{
|
|
104
|
-
this.
|
|
114
|
+
return this._SchemaProvider.generateCreateTableStatement(pMeadowTableSchema);
|
|
115
|
+
}
|
|
105
116
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
for (let j = 0; j < pMeadowTableSchema.Columns.length; j++)
|
|
111
|
-
{
|
|
112
|
-
let tmpColumn = pMeadowTableSchema.Columns[j];
|
|
117
|
+
createTables(pMeadowSchema, fCallback)
|
|
118
|
+
{
|
|
119
|
+
return this._SchemaProvider.createTables(pMeadowSchema, fCallback);
|
|
120
|
+
}
|
|
113
121
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
122
|
+
createTable(pMeadowTableSchema, fCallback)
|
|
123
|
+
{
|
|
124
|
+
return this._SchemaProvider.createTable(pMeadowTableSchema, fCallback);
|
|
125
|
+
}
|
|
119
126
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
case 'ID':
|
|
125
|
-
// if (this.options.AllowIdentityInsert)
|
|
126
|
-
// {
|
|
127
|
-
// tmpCreateTableStatement += ` [${tmpColumn.Column}] INT NOT NULL PRIMARY KEY`;
|
|
128
|
-
// }
|
|
129
|
-
// else
|
|
130
|
-
// {
|
|
131
|
-
// There is debate on whether IDENTITY(1,1) is better or not.
|
|
132
|
-
tmpCreateTableStatement += ` ${tmpColumn.Column} INT UNSIGNED NOT NULL AUTO_INCREMENT`;
|
|
133
|
-
//}
|
|
134
|
-
tmpPrimaryKey = tmpColumn.Column;
|
|
135
|
-
break;
|
|
136
|
-
case 'GUID':
|
|
137
|
-
let tmpSize = tmpColumn.hasOwnProperty('Size') ? tmpColumn.Size : 36;
|
|
138
|
-
if (isNaN(tmpSize))
|
|
139
|
-
{
|
|
140
|
-
// Use the old default if Size is improper
|
|
141
|
-
tmpSize = 36;
|
|
142
|
-
}
|
|
143
|
-
tmpCreateTableStatement += ` ${tmpColumn.Column} CHAR(${tmpSize}) DEFAULT '0xDe'`;
|
|
144
|
-
break;
|
|
145
|
-
case 'ForeignKey':
|
|
146
|
-
tmpCreateTableStatement += ` ${tmpColumn.Column} INT UNSIGNED NOT NULL DEFAULT '0'`;
|
|
147
|
-
tmpPrimaryKey = tmpColumn.Column;
|
|
148
|
-
break;
|
|
149
|
-
case 'Numeric':
|
|
150
|
-
tmpCreateTableStatement += ` ${tmpColumn.Column} INT NOT NULL DEFAULT '0'`;
|
|
151
|
-
break;
|
|
152
|
-
case 'Decimal':
|
|
153
|
-
tmpCreateTableStatement += ` ${tmpColumn.Column} DECIMAL(${tmpColumn.Size})`;
|
|
154
|
-
break;
|
|
155
|
-
case 'String':
|
|
156
|
-
tmpCreateTableStatement += ` ${tmpColumn.Column} CHAR(${tmpColumn.Size}) NOT NULL DEFAULT ''`;
|
|
157
|
-
break;
|
|
158
|
-
case 'Text':
|
|
159
|
-
tmpCreateTableStatement += ` ${tmpColumn.Column} TEXT`;
|
|
160
|
-
break;
|
|
161
|
-
case 'DateTime':
|
|
162
|
-
tmpCreateTableStatement += ` ${tmpColumn.Column} DATETIME`;
|
|
163
|
-
break;
|
|
164
|
-
case 'Boolean':
|
|
165
|
-
tmpCreateTableStatement += ` ${tmpColumn.Column} TINYINT NOT NULL DEFAULT '0'`;
|
|
166
|
-
break;
|
|
167
|
-
default:
|
|
168
|
-
break;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
if (tmpPrimaryKey)
|
|
172
|
-
{
|
|
173
|
-
tmpCreateTableStatement += `,\n\n PRIMARY KEY (${tmpPrimaryKey})`;
|
|
174
|
-
}
|
|
175
|
-
tmpCreateTableStatement += `\n ) DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;`;
|
|
127
|
+
getIndexDefinitionsFromSchema(pMeadowTableSchema)
|
|
128
|
+
{
|
|
129
|
+
return this._SchemaProvider.getIndexDefinitionsFromSchema(pMeadowTableSchema);
|
|
130
|
+
}
|
|
176
131
|
|
|
177
|
-
|
|
132
|
+
generateCreateIndexScript(pMeadowTableSchema)
|
|
133
|
+
{
|
|
134
|
+
return this._SchemaProvider.generateCreateIndexScript(pMeadowTableSchema);
|
|
135
|
+
}
|
|
178
136
|
|
|
179
|
-
|
|
137
|
+
generateCreateIndexStatements(pMeadowTableSchema)
|
|
138
|
+
{
|
|
139
|
+
return this._SchemaProvider.generateCreateIndexStatements(pMeadowTableSchema);
|
|
180
140
|
}
|
|
181
141
|
|
|
182
|
-
|
|
142
|
+
createIndex(pIndexStatement, fCallback)
|
|
183
143
|
{
|
|
184
|
-
|
|
185
|
-
this.fable.Utility.eachLimit(pMeadowSchema.Tables, 1,
|
|
186
|
-
(pTable, fCreateComplete) =>
|
|
187
|
-
{
|
|
188
|
-
return this.createTable(pTable, fCreateComplete)
|
|
189
|
-
},
|
|
190
|
-
(pCreateError) =>
|
|
191
|
-
{
|
|
192
|
-
if (pCreateError)
|
|
193
|
-
{
|
|
194
|
-
this.log.error(`Meadow-MySQL Error creating tables from Schema: ${pCreateError}`,pCreateError);
|
|
195
|
-
}
|
|
196
|
-
this.log.info('Done creating tables!');
|
|
197
|
-
return fCallback(pCreateError);
|
|
198
|
-
});
|
|
144
|
+
return this._SchemaProvider.createIndex(pIndexStatement, fCallback);
|
|
199
145
|
}
|
|
200
146
|
|
|
201
|
-
|
|
147
|
+
createIndices(pMeadowTableSchema, fCallback)
|
|
202
148
|
{
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
149
|
+
return this._SchemaProvider.createIndices(pMeadowTableSchema, fCallback);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
createAllIndices(pMeadowSchema, fCallback)
|
|
153
|
+
{
|
|
154
|
+
return this._SchemaProvider.createAllIndices(pMeadowSchema, fCallback);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Database Introspection delegation
|
|
158
|
+
|
|
159
|
+
listTables(fCallback)
|
|
160
|
+
{
|
|
161
|
+
return this._SchemaProvider.listTables(fCallback);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
introspectTableColumns(pTableName, fCallback)
|
|
165
|
+
{
|
|
166
|
+
return this._SchemaProvider.introspectTableColumns(pTableName, fCallback);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
introspectTableIndices(pTableName, fCallback)
|
|
170
|
+
{
|
|
171
|
+
return this._SchemaProvider.introspectTableIndices(pTableName, fCallback);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
introspectTableForeignKeys(pTableName, fCallback)
|
|
175
|
+
{
|
|
176
|
+
return this._SchemaProvider.introspectTableForeignKeys(pTableName, fCallback);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
introspectTableSchema(pTableName, fCallback)
|
|
180
|
+
{
|
|
181
|
+
return this._SchemaProvider.introspectTableSchema(pTableName, fCallback);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
introspectDatabaseSchema(fCallback)
|
|
185
|
+
{
|
|
186
|
+
return this._SchemaProvider.introspectDatabaseSchema(fCallback);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
generateMeadowPackageFromTable(pTableName, fCallback)
|
|
190
|
+
{
|
|
191
|
+
return this._SchemaProvider.generateMeadowPackageFromTable(pTableName, fCallback);
|
|
234
192
|
}
|
|
235
193
|
|
|
236
194
|
connect()
|
|
@@ -257,6 +215,7 @@ class MeadowConnectionMySQL extends libFableServiceProviderBase
|
|
|
257
215
|
{
|
|
258
216
|
this.fable.log.info(`Meadow-Connection-MySQL connecting to [${this.options.MySQL.host} : ${this.options.MySQL.port}] as ${this.options.MySQL.user} for database ${this.options.MySQL.database} at a connection limit of ${this.options.MySQL.connectionLimit}`);
|
|
259
217
|
this._ConnectionPool = libMySQL.createPool(tmpConnectionSettings);
|
|
218
|
+
this._SchemaProvider.setConnectionPool(this._ConnectionPool);
|
|
260
219
|
this.connected = true;
|
|
261
220
|
}
|
|
262
221
|
}
|