-
Notifications
You must be signed in to change notification settings - Fork 0
/
connection.js
72 lines (67 loc) · 2.37 KB
/
connection.js
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
const colog = require('./lib/colog-noindent');
const {parseSettingsFile} = require('./lib/config-parser');
const {validateConnectionsConfig} = require('./lib/config-validator');
const SETTINGS_FILE_NAME = 'sqade-settings.json';
/**
* ADD YOUR CONNECTIONS TO sqade-settings.json
* SEE https://github.com/TDress/sql-aide
*
* Parse connections from sqade-settings.json
* Below is some documentation on how to set
* configuration settings for your database connections
* in that file.
* TO DO: clean up the example below and add
* another one for a different database management system
*
* Connection object properties are validated for correct form
* and type on every run from the command line in order to
* catch typos and other simple mistakes.
* Additionally, you can set the `verifyOnValidate` key to
* true to run a trivial test query against the database
* to ensure that the connection is working.
* Note that this verification is only performed for the
* currently active database, and will be run on every command.
*
* connection keys:
* type {string} The type of SQL database management system.
* Case insensitive.
* Valid types: `mysql`, `mssql`.
* host {string} The host of the database server.
* port {integer} The port number of the database server.
* database {string} The name of the database to connect to.
* login {string} The login string to authenticate with.
* password: {string} The password to use for authentication.
* verifyOnValidate {Boolean} True to run a basic connection
* health check on each command. This is NOT a health
* check of the database in any way -- only a
* verification that the connection to the database
* engine is good.
*
* E.G.
* myDb: {
* type: mssql
* host: localhost,
* port: 400,
* database: db1,
* login: username,
* password: weakPassword,
* verifyOnValidate: true
* }
*/
const settings = parseSettingsFile(SETTINGS_FILE_NAME);
const configMap = settings && settings.connections
? new Map(Object.entries(settings.connections))
: null;
const isValid = validateConnectionsConfig(configMap);
const active = settings
&& settings.activeDb;
module.exports = {
configMap,
isValid,
active,
updateActive: name => {
this.active = name;
// TO DO: update the actual settings file
},
SETTINGS_FILE_NAME
}