-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathapplyToInstanceHelper.js
More file actions
40 lines (34 loc) · 1.07 KB
/
applyToInstanceHelper.js
File metadata and controls
40 lines (34 loc) · 1.07 KB
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
const connectionHelper = require('../../reverse_engineering/helpers/connectionHelper');
const execute = async (bigquery, query, location) => {
const response = await bigquery.createJob({
configuration: {
query: {
query: query,
useLegacySql: false,
},
},
location,
});
const job = response[0];
const result = await job.getQueryResults(job);
return result;
};
const applyToInstance = async (connectionInfo, logger, app) => {
const _ = app.require('lodash');
const async = app.require('async');
const connection = connectionHelper.connect(connectionInfo);
const dataLocation = connectionInfo.containerData?.[0]?.dataLocation;
const location = dataLocation === 'default' ? '' : dataLocation;
const queries = connectionInfo.script
.split('\n\n')
.map(query => {
return _.trim(query);
})
.filter(Boolean);
await async.mapSeries(queries, async query => {
const message = 'Query: ' + query.split('\n').shift().substr(0, 150);
logger.progress({ message });
await execute(connection, query, location);
});
};
module.exports = { applyToInstance };