Skip to content

Commit 15ecadb

Browse files
kirill-levitskiyRenat Zubairov
authored andcommitted
Split URI to user-friendly configuration parameters (#7)
* split URI to user-friendly configuration parameters * added --exit flag to use pre-v4 behavior for mocha integration test command * added function encodeURIComponent for encoding special characters at username and password
1 parent aa32749 commit 15ecadb

File tree

9 files changed

+1750
-2456
lines changed

9 files changed

+1750
-2456
lines changed

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@ Before you can deploy any code into elastic.io **you must be a registered elasti
1414

1515
### Authentication
1616

17-
You may use following URI:
17+
You may use following properties to configure a connection:
1818

19-
```
20-
mssql://username:password@localhost:1433/database?encrypt=true
21-
```
19+
![image](https://user-images.githubusercontent.com/40201204/41356042-97e26406-6f2b-11e8-88fb-11cba846d143.png)
2220

2321
other types of configuration parameters are also supported, more infromation and samples you can find [here](https://www.npmjs.com/package/mssql#formats)
2422

@@ -33,7 +31,7 @@ via sequential fetching that is implemented within the node.js ``mssql`` driver.
3331

3432
#### Polling
3533

36-
Comopnent will remember last execution timestamp and let you build queries on it:
34+
Component will remember last execution timestamp and let you build queries on it:
3735

3836
```sql
3937
select * from Leads where Created >= '%%EIO_LAST_POLL%%'

component.json

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,45 @@
33
"description": "elastic.io integration component for Microsoft SQL Server",
44
"credentials": {
55
"fields": {
6-
"uri": {
7-
"label": "Connection URI",
6+
"server": {
7+
"label": "Server (you can use 'host\\\\instance' to connect to named instance)",
88
"required": true,
99
"viewClass": "TextFieldView",
10-
"placeholder": "mssql://username:password@localhost/database"
10+
"placeholder": "localhost"
11+
},
12+
"port": {
13+
"label": "Port (don't set when connecting to named instance)",
14+
"required": false,
15+
"viewClass": "TextFieldView",
16+
"placeholder": "1433"
17+
},
18+
"database": {
19+
"label": "Database Name",
20+
"required": true,
21+
"viewClass": "TextFieldView",
22+
"placeholder": "database"
23+
},
24+
"encrypt": {
25+
"label": "Encrypt (check this option if you're using Windows Azure)",
26+
"viewClass": "CheckBoxView"
27+
},
28+
"domain": {
29+
"label": "Domain (driver will connect to SQL Server using domain login)",
30+
"required": false,
31+
"viewClass": "TextFieldView",
32+
"placeholder": "domain"
33+
},
34+
"username": {
35+
"label": "Username",
36+
"required": true,
37+
"viewClass": "TextFieldView",
38+
"placeholder": "username"
39+
},
40+
"password": {
41+
"label": "Password",
42+
"required": true,
43+
"viewClass": "PasswordFieldView",
44+
"placeholder": "password"
1145
}
1246
}
1347
},

lib/actions/insert.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,19 @@ const VARS_REGEXP = /@([\w_$][\d\w_$]*(:(string|boolean|date|number|bigint|float
1414
* @returns {Promise}
1515
*/
1616
function init(cfg) {
17-
const conString = cfg.uri;
17+
const conString = 'mssql://'
18+
+ encodeURIComponent(cfg.username)
19+
+ ':'
20+
+ encodeURIComponent(cfg.password)
21+
+ '@'
22+
+ cfg.server
23+
+ ((cfg.port) ? ':' + cfg.port : '')
24+
+ ((cfg.instance) ? '/' + cfg.instance : '')
25+
+ '/'
26+
+ cfg.database
27+
+ ((cfg.domain) ? '?domain=' + cfg.domain + '&encrypt=' + cfg.encrypt
28+
: '?encrypt=' + cfg.encrypt);
29+
console.log(conString);
1830
return co(function* gen() {
1931
console.log('Connecting to the database');
2032
const connection = new cosql.Connection(conString);

lib/actions/select.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,18 @@ let connection;
1414
* @param cfg
1515
*/
1616
function init(cfg) {
17-
const conString = cfg.uri;
17+
const conString = 'mssql://'
18+
+ encodeURIComponent(cfg.username)
19+
+ ':'
20+
+ encodeURIComponent(cfg.password)
21+
+ '@'
22+
+ cfg.server
23+
+ ((cfg.port) ? ':' + cfg.port : '')
24+
+ ((cfg.instance) ? '/' + cfg.instance : '')
25+
+ '/'
26+
+ cfg.database
27+
+ ((cfg.domain) ? '?domain=' + cfg.domain + '&encrypt=' + cfg.encrypt
28+
: '?encrypt=' + cfg.encrypt);
1829
return co(function* gen() {
1930
console.log('Connecting to the database');
2031
connection = new cosql.Connection(conString);

0 commit comments

Comments
 (0)