UNPKG

3.3 kBJavaScriptView Raw
1/*
2
3 ----------------------------------------------------------------------------
4 | qewd-up: Rapid QEWD API Development |
5 | |
6 | Copyright (c) 2018-20 M/Gateway Developments Ltd, |
7 | Redhill, Surrey UK. |
8 | All rights reserved. |
9 | |
10 | http://www.mgateway.com |
11 | Email: rtweed@mgateway.com |
12 | |
13 | |
14 | Licensed under the Apache License, Version 2.0 (the "License"); |
15 | you may not use this file except in compliance with the License. |
16 | You may obtain a copy of the License at |
17 | |
18 | http://www.apache.org/licenses/LICENSE-2.0 |
19 | |
20 | Unless required by applicable law or agreed to in writing, software |
21 | distributed under the License is distributed on an "AS IS" BASIS, |
22 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
23 | See the License for the specific language governing permissions and |
24 | limitations under the License. |
25 ----------------------------------------------------------------------------
26
27 26 May 2020
28
29 Windows / IRIS/Cache: Installs the mg-dbx SQL interface
30
31*/
32
33module.exports = function() {
34 let https = require('https');
35 let fs = require('fs-extra');
36 let qewd_mg_dbx = require('qewd-mg-dbx');
37
38 let config_all = require('../../../configuration/config.json');
39
40 // dirname = C:\testing\node_modules\qewd\up
41
42 let params = config_all.qewd.database.params;
43 params.type = params.database;
44 let platform = params.type.toLowerCase();
45 delete params.database;
46 let db = new qewd_mg_dbx({database: params});
47 db.open();
48
49 let filename;
50 let url = 'https://raw.githubusercontent.com/chrisemunt/mg-dbx/master/m/zmgsi';
51 if (platform === 'iris') {
52 url = url + '_iris.xml';
53 filename = 'temp.xml';
54 }
55 else {
56 url = url + '_isc.ro';
57 filename = 'temp.ro';
58 }
59
60 filename = __dirname + '\\' + filename;
61
62 let file = fs.createWriteStream(filename);
63
64 console.log('fetching SQL Interface from ' + url);
65 let request = https.get(url, function(response) {
66 let st = response.pipe(file);
67
68 st.on('finish', function() {
69 try {
70 let result = db.dbx.classmethod('%SYSTEM.OBJ', 'Load', filename, 'ck');
71 console.log('mg-dbx SQL interface installed: ' + result);
72 }
73 catch(err) {
74 console.log('Error trying to install the mg-dbx SQL Interface:');
75 console.log(err);
76 }
77 fs.removeSync(filename);
78 db.close();
79 });
80 });
81};