Skip to content

Commit 2c74008

Browse files
committed
Fixed RE of indexes and functions from PostgreSQL:10
1 parent b04051b commit 2c74008

File tree

14 files changed

+1596
-1537
lines changed

14 files changed

+1596
-1537
lines changed

reverse_engineering/api.js

Lines changed: 210 additions & 210 deletions
Large diffs are not rendered by default.

reverse_engineering/helpers/connectionHelper.js

Lines changed: 107 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -3,125 +3,125 @@ const ssh = require('tunnel-ssh');
33
const pg = require('pg');
44

55
const getSshConfig = info => {
6-
const config = {
7-
username: info.ssh_user,
8-
host: info.ssh_host,
9-
port: info.ssh_port,
10-
dstHost: info.host,
11-
dstPort: info.port,
12-
localHost: '127.0.0.1',
13-
localPort: info.port,
14-
keepAlive: true,
15-
};
16-
17-
if (info.ssh_method === 'privateKey') {
18-
return Object.assign({}, config, {
19-
privateKey: fs.readFileSync(info.ssh_key_file),
20-
passphrase: info.ssh_key_passphrase,
21-
});
22-
} else {
23-
return Object.assign({}, config, {
24-
password: info.ssh_password,
25-
});
26-
}
6+
const config = {
7+
username: info.ssh_user,
8+
host: info.ssh_host,
9+
port: info.ssh_port,
10+
dstHost: info.host,
11+
dstPort: info.port,
12+
localHost: '127.0.0.1',
13+
localPort: info.port,
14+
keepAlive: true,
15+
};
16+
17+
if (info.ssh_method === 'privateKey') {
18+
return Object.assign({}, config, {
19+
privateKey: fs.readFileSync(info.ssh_key_file),
20+
passphrase: info.ssh_key_passphrase,
21+
});
22+
} else {
23+
return Object.assign({}, config, {
24+
password: info.ssh_password,
25+
});
26+
}
2727
};
2828

2929
const connectViaSsh = info =>
30-
new Promise((resolve, reject) => {
31-
ssh(getSshConfig(info), (err, tunnel) => {
32-
if (err) {
33-
reject(err);
34-
} else {
35-
resolve({
36-
tunnel,
37-
info: Object.assign({}, info, {
38-
host: '127.0.0.1',
39-
}),
40-
});
41-
}
42-
});
43-
});
30+
new Promise((resolve, reject) => {
31+
ssh(getSshConfig(info), (err, tunnel) => {
32+
if (err) {
33+
reject(err);
34+
} else {
35+
resolve({
36+
tunnel,
37+
info: Object.assign({}, info, {
38+
host: '127.0.0.1',
39+
}),
40+
});
41+
}
42+
});
43+
});
4444

4545
const getSslOptions = (connectionInfo, logger) => {
46-
const sslType = mapSslType(connectionInfo.sslType);
47-
48-
if (!sslType || sslType === 'disable') {
49-
return false;
50-
}
51-
52-
if (sslType === 'allow') {
53-
return true;
54-
}
55-
56-
let sslOptions = {
57-
checkServerIdentity(hostname, cert) {
58-
logger.info('Certificate', {
59-
hostname,
60-
cert: {
61-
subject: cert.subject,
62-
issuer: cert.issuer,
63-
valid_from: cert.valid_from,
64-
valid_to: cert.valid_to,
65-
},
66-
});
67-
}
68-
};
69-
70-
if (fs.existsSync(connectionInfo.certAuthority)) {
71-
sslOptions.ca = fs.readFileSync(connectionInfo.certAuthority).toString();
72-
}
73-
74-
if (fs.existsSync(connectionInfo.clientCert)) {
75-
sslOptions.cert = fs.readFileSync(connectionInfo.clientCert).toString();
76-
}
77-
78-
if (fs.existsSync(connectionInfo.clientPrivateKey)) {
79-
sslOptions.key = fs.readFileSync(connectionInfo.clientPrivateKey).toString();
80-
}
81-
82-
return sslOptions;
46+
const sslType = mapSslType(connectionInfo.sslType);
47+
48+
if (!sslType || sslType === 'disable') {
49+
return false;
50+
}
51+
52+
if (sslType === 'allow') {
53+
return true;
54+
}
55+
56+
let sslOptions = {
57+
checkServerIdentity(hostname, cert) {
58+
logger.info('Certificate', {
59+
hostname,
60+
cert: {
61+
subject: cert.subject,
62+
issuer: cert.issuer,
63+
valid_from: cert.valid_from,
64+
valid_to: cert.valid_to,
65+
},
66+
});
67+
},
68+
};
69+
70+
if (fs.existsSync(connectionInfo.certAuthority)) {
71+
sslOptions.ca = fs.readFileSync(connectionInfo.certAuthority).toString();
72+
}
73+
74+
if (fs.existsSync(connectionInfo.clientCert)) {
75+
sslOptions.cert = fs.readFileSync(connectionInfo.clientCert).toString();
76+
}
77+
78+
if (fs.existsSync(connectionInfo.clientPrivateKey)) {
79+
sslOptions.key = fs.readFileSync(connectionInfo.clientPrivateKey).toString();
80+
}
81+
82+
return sslOptions;
8383
};
8484

8585
const mapSslType = sslType => {
86-
const oldToNewSslType = {
87-
Off: 'disable',
88-
TRUST_ALL_CERTIFICATES: 'allow',
89-
TRUST_CUSTOM_CA_SIGNED_CERTIFICATES: 'prefer',
90-
TRUST_SERVER_CLIENT_CERTIFICATES: 'verify-full',
91-
};
92-
93-
return oldToNewSslType[sslType] || sslType;
86+
const oldToNewSslType = {
87+
Off: 'disable',
88+
TRUST_ALL_CERTIFICATES: 'allow',
89+
TRUST_CUSTOM_CA_SIGNED_CERTIFICATES: 'prefer',
90+
TRUST_SERVER_CLIENT_CERTIFICATES: 'verify-full',
91+
};
92+
93+
return oldToNewSslType[sslType] || sslType;
9494
};
9595

9696
const createClient = async (connectionInfo, logger) => {
97-
let sshTunnel = null;
98-
99-
if (connectionInfo.ssh) {
100-
const { info, tunnel } = await connectViaSsh(connectionInfo);
101-
sshTunnel = tunnel;
102-
connectionInfo = info;
103-
}
104-
105-
const config = {
106-
host: connectionInfo.host,
107-
user: connectionInfo.userName,
108-
password: connectionInfo.userPassword,
109-
port: connectionInfo.port,
110-
keepAlive: true,
111-
ssl: getSslOptions(connectionInfo, logger),
112-
connectionTimeoutMillis: Number(connectionInfo.queryRequestTimeout) || 60000,
113-
query_timeout: Number(connectionInfo.queryRequestTimeout) || 60000,
114-
statement_timeout: Number(connectionInfo.queryRequestTimeout) || 60000,
115-
database: connectionInfo.database || connectionInfo.maintenanceDatabase,
116-
application_name: 'Hackolade',
117-
};
118-
119-
const client = new pg.Client(config);
120-
await client.connect();
121-
122-
return { client, sshTunnel };
97+
let sshTunnel = null;
98+
99+
if (connectionInfo.ssh) {
100+
const { info, tunnel } = await connectViaSsh(connectionInfo);
101+
sshTunnel = tunnel;
102+
connectionInfo = info;
103+
}
104+
105+
const config = {
106+
host: connectionInfo.host,
107+
user: connectionInfo.userName,
108+
password: connectionInfo.userPassword,
109+
port: connectionInfo.port,
110+
keepAlive: true,
111+
ssl: getSslOptions(connectionInfo, logger),
112+
connectionTimeoutMillis: Number(connectionInfo.queryRequestTimeout) || 60000,
113+
query_timeout: Number(connectionInfo.queryRequestTimeout) || 60000,
114+
statement_timeout: Number(connectionInfo.queryRequestTimeout) || 60000,
115+
database: connectionInfo.database || connectionInfo.maintenanceDatabase,
116+
application_name: 'Hackolade',
117+
};
118+
119+
const client = new pg.Client(config);
120+
await client.connect();
121+
122+
return { client, sshTunnel };
123123
};
124124

125125
module.exports = {
126-
createClient,
126+
createClient,
127127
};

reverse_engineering/helpers/db.js

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,56 +4,56 @@ let client = null;
44
let logger = null;
55

66
module.exports = {
7-
initializeClient(newClient, newLogger) {
8-
client = newClient;
9-
logger = newLogger;
7+
initializeClient(newClient, newLogger) {
8+
client = newClient;
9+
logger = newLogger;
1010

11-
client.on('error', error => newLogger.error(error));
12-
},
11+
client.on('error', error => newLogger.error(error));
12+
},
1313

14-
isClientInitialized() {
15-
return Boolean(client);
16-
},
14+
isClientInitialized() {
15+
return Boolean(client);
16+
},
1717

18-
releaseClient() {
19-
if (client) {
20-
return new Promise(resolve => {
21-
client.end(() => {
22-
client = null;
23-
resolve();
24-
});
25-
});
26-
}
18+
releaseClient() {
19+
if (client) {
20+
return new Promise(resolve => {
21+
client.end(() => {
22+
client = null;
23+
resolve();
24+
});
25+
});
26+
}
2727

28-
return Promise.resolve();
29-
},
28+
return Promise.resolve();
29+
},
3030

31-
async query(query, params, firstRow = false) {
32-
const queryName = queryConstants.getQueryName(query);
31+
async query(query, params, firstRow = false) {
32+
const queryName = queryConstants.getQueryName(query);
3333

34-
logger.info('Execute query', { queryName, params });
34+
logger.info('Execute query', { queryName, params });
3535

36-
const start = Date.now();
37-
const result = await client.query(query, params);
38-
const duration = Date.now() - start;
36+
const start = Date.now();
37+
const result = await client.query(query, params);
38+
const duration = Date.now() - start;
3939

40-
logger.info('Query executed', { queryName, params, duration, rowsCount: result.rowCount });
40+
logger.info('Query executed', { queryName, params, duration, rowsCount: result.rowCount });
4141

42-
const rows = result.rows || [];
42+
const rows = result.rows || [];
4343

44-
return firstRow ? rows[0] : rows;
45-
},
44+
return firstRow ? rows[0] : rows;
45+
},
4646

47-
async queryTolerant(query, params, firstRow = false) {
48-
try {
49-
return await this.query(query, params, firstRow);
50-
} catch (error) {
51-
error.query = query;
52-
error.params = params;
47+
async queryTolerant(query, params, firstRow = false) {
48+
try {
49+
return await this.query(query, params, firstRow);
50+
} catch (error) {
51+
error.query = query;
52+
error.params = params;
5353

54-
logger.error(error);
54+
logger.error(error);
5555

56-
return null;
57-
}
58-
},
56+
return null;
57+
}
58+
},
5959
};
Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
const getJsonSchema = columns => {
2-
const properties = columns.reduce((properties, column) => {
3-
if (column.properties) {
4-
return {
5-
...properties,
6-
[column.name]: {
7-
...column,
8-
...getJsonSchema(column.properties),
9-
},
10-
};
11-
}
2+
const properties = columns.reduce((properties, column) => {
3+
if (column.properties) {
4+
return {
5+
...properties,
6+
[column.name]: {
7+
...column,
8+
...getJsonSchema(column.properties),
9+
},
10+
};
11+
}
1212

13-
return {
14-
...properties,
15-
[column.name]: column,
16-
};
17-
}, {});
13+
return {
14+
...properties,
15+
[column.name]: column,
16+
};
17+
}, {});
1818

19-
const required = Object.entries(properties)
20-
.filter(([filedName, field]) => field.required)
21-
.map(([fieldName]) => fieldName);
19+
const required = Object.entries(properties)
20+
.filter(([filedName, field]) => field.required)
21+
.map(([fieldName]) => fieldName);
2222

23-
return { properties, required };
23+
return { properties, required };
2424
};
2525

2626
module.exports = {
27-
getJsonSchema,
27+
getJsonSchema,
2828
};

0 commit comments

Comments
 (0)