-
Notifications
You must be signed in to change notification settings - Fork 8
/
CanvasDataDL_Schema_Latest.cdconfig
121 lines (106 loc) · 3.51 KB
/
CanvasDataDL_Schema_Latest.cdconfig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
var fs = require('fs');
var https = require('https');
//var json2csv = require('json2csv');
var CanvasDataAPICall = require('./CanvasDataAuth_Schema.js');
var sql = require("seriate");
var datetime = new Date();
var datetimeSimple = (datetime.getMonth() + 1) + '-' + datetime.getDate() + '-' + datetime.getFullYear();
var request = require('request');
var schKey=[];
var schVal=[];
var download = function(uri, filename, callback){
request.head(uri, function(err, res, body){
var r = request(uri).pipe(fs.createWriteStream(filename));
r.on('close', callback);
});
};
JSON.flatten = function(data) {
var flattenResult = {};
function recurse (cur, prop) {
if (Object(cur) !== cur) {
flattenResult[prop] = cur;
} else if (Array.isArray(cur)) {
for(var i=0, l=cur.length; i<l; i++)
recurse(cur[i], prop + "[" + i + "]");
if (l == 0)
flattenResult[prop] = [];
} else {
var isEmpty = true;
for (var p in cur) {
isEmpty = false;
recurse(cur[p], prop ? prop+"."+p : p);
}
if (isEmpty && prop)
flattenResult[prop] = {};
}
}
recurse(data, "");
//console.log(flattenResult)
return flattenResult;
}
var config = {
"server": "IRCDSVRREPLACEME",
"user": "IRCDSVRUSRREPLACEME",
"password": "IRCDSVRUSRPWREPLACEME",
"database": "CanvasDataStore"
};
sql.setDefaultConfig( config );
CanvasDataAPICall('', function(result) {
respAPIObj=result;
respAPIObjSchema=respAPIObj.schema
flattenResult = JSON.flatten(respAPIObjSchema);
//console.log(result);
//console.log(flattenResult);
for (var k in flattenResult){
if (flattenResult.hasOwnProperty(k)) {
//console.log(k);
//console.log(flattenResult[k]);
value0=JSON.stringify(k);
value1=JSON.stringify(flattenResult[k]);
schKey.push(k)
schVal.push(flattenResult[k])
}
}
console.log(schKey)
console.log(schVal)
sql.execute( {
query: "TRUNCATE TABLE RAWSchemaKey " +
"TRUNCATE TABLE RAWSchemaVal"
} ).then( function( results ) {
console.log( results );
}, function( err ) {
console.log( "Something bad happened:", err );
} );
//////////////
sql.execute( {
query: "INSERT INTO RawSchemaKey ([schKey]) " +
"SELECT value FROM @schKey",
params: {
schKey: {
val: schKey,
type: sql.VARCHAR(4096),
asTable: true
}
}
} ).then( function( results ) {
console.log( results );
}, function( err ) {
console.log( "Something bad happened:", err );
} );
//////////////
sql.execute( {
query: "INSERT INTO RawSchemaVal ([schVal]) " +
"SELECT value FROM @schVal",
params: {
schVal: {
val: schVal,
type: sql.VARCHAR(4096),
asTable: true
}
}
} ).then( function( results ) {
console.log( results );
}, function( err ) {
console.log( "Something bad happened:", err );
} );
});