Skip to content

Commit 568dcad

Browse files
authored
Sailor update (#12)
1 parent 15ecadb commit 568dcad

File tree

8 files changed

+365
-109
lines changed

8 files changed

+365
-109
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## 1.1.0 (January 30, 2020)
2+
3+
* Update sailor version to 2.6.1
4+
* Refactor console.log to built in sailor logger
5+
* Change build type to `docker`
6+
7+
## 1.0.0 (June 14, 2018)
8+
9+
* Initial release

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ MSSQL Component component for the [elastic.io platform](http://www.elastic.io)
66

77
![image](https://user-images.githubusercontent.com/56208/29715706-b4930bdc-89a8-11e7-8a0d-969959d26dd6.png)
88

9+
## Environment Variables
10+
1. LOG_LEVEL - controls verbosity of logger. Possible values: `trace`, `debug` `info`, `warn`, `error`. Default: `info`
11+
912
## Before you Begin
1013

1114
Before you can deploy any code into elastic.io **you must be a registered elastic.io platform user**. Please see our home page at [http://www.elastic.io](http://www.elastic.io) to learn how.

component.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"title": "SQL Server",
33
"description": "elastic.io integration component for Microsoft SQL Server",
4+
"buildType": "docker",
45
"credentials": {
56
"fields": {
67
"server": {
@@ -85,6 +86,15 @@
8586
"description": "Executes a SELECT statement that fetches potentially multiple database rows from the database",
8687
"main": "./lib/actions/select.js",
8788
"type": "polling",
89+
"fields": {
90+
"query": {
91+
"label": "SQL Query",
92+
"required": true,
93+
"viewClass": "TextAreaWithNoteView",
94+
"placeholder": "INSERT INTO films (code,title,kind) VALUES (@code:number,@title:string,@kind:string)",
95+
"note": "You can use parameters of message body as <i>@value:number</i> and type is <i>:type</i>"
96+
}
97+
},
8898
"metadata": {
8999
"in": {
90100
"type": "object",

lib/actions/insert.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
/*eslint no-invalid-this: 0 no-console: 0*/
1+
/*eslint no-invalid-this: 0 */
22
'use strict';
33
const co = require('co');
44
const cosql = require('co-mssql');
5+
const logger = require('@elastic.io/component-logger')();
56

67
let pstmt;
78

@@ -26,18 +27,18 @@ function init(cfg) {
2627
+ cfg.database
2728
+ ((cfg.domain) ? '?domain=' + cfg.domain + '&encrypt=' + cfg.encrypt
2829
: '?encrypt=' + cfg.encrypt);
29-
console.log(conString);
30+
logger.trace(conString);
3031
return co(function* gen() {
31-
console.log('Connecting to the database');
32+
logger.info('Connecting to the database');
3233
const connection = new cosql.Connection(conString);
3334
// Always attach an error listener
3435
connection.on('error', (err) => this.emit('error', err));
3536
let sql = cfg.query;
3637
yield connection.connect();
37-
console.log('Connection established');
38-
console.log('Preparing query=%s', sql);
38+
logger.info('Connection established');
39+
logger.trace('Preparing query=%s', sql);
3940
const vars = sql.match(VARS_REGEXP);
40-
console.log('Found following prepared variable:type pairs=%j', vars);
41+
logger.trace('Found following prepared variable:type pairs=%j', vars);
4142
pstmt = new cosql.PreparedStatement(connection);
4243
for (const tuple of vars) {
4344
const [placeholder, type] = tuple.split(':');
@@ -69,14 +70,14 @@ function init(cfg) {
6970
pstmt.input(name, cosql.BigInt);
7071
break;
7172
default:
72-
console.log('WARNING: Can figure out the type key=%s type=%s', name, type);
73+
logger.warn('WARNING: Can figure out the type key=%s type=%s', name, type);
7374
}
7475
// Now let's remove all :string :boolean :date etc to the name only
7576
sql = sql.replace(tuple, placeholder);
7677
}
77-
console.log('Resulting SQL=%s', sql);
78+
logger.trace('Resulting SQL=%s', sql);
7879
yield pstmt.prepare(sql);
79-
console.log('Preparing statement created');
80+
logger.info('Preparing statement created');
8081
}.bind(this));
8182
}
8283

@@ -132,10 +133,11 @@ function getMetaModel(cfg, cb) {
132133
* @param cfg configuration that is account information and configuration field values
133134
*/
134135
function processAction(msg) {
136+
const that = this;
135137
return co(function* gen() {
136-
console.log('Executing statement');
138+
that.logger.info('Executing statement');
137139
yield pstmt.execute(msg.body);
138-
console.log('Execution completed');
140+
that.logger.info('Execution completed');
139141
return msg;
140142
}.bind(this));
141143
}

lib/actions/select.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
/*eslint no-invalid-this: 0 no-console: 0*/
1+
/*eslint no-invalid-this: 0 */
22
'use strict';
33
const eioUtils = require('elasticio-node').messages;
44
const co = require('co');
55
const cosql = require('co-mssql');
6+
const logger = require('@elastic.io/component-logger')();
67

78
const LAST_POLL_PLACEHOLDER = '%%EIO_LAST_POLL%%';
89

@@ -27,11 +28,11 @@ function init(cfg) {
2728
+ ((cfg.domain) ? '?domain=' + cfg.domain + '&encrypt=' + cfg.encrypt
2829
: '?encrypt=' + cfg.encrypt);
2930
return co(function* gen() {
30-
console.log('Connecting to the database');
31+
logger.info('Connecting to the database');
3132
connection = new cosql.Connection(conString);
3233
connection.on('error', (err) => this.emit('error', err));
3334
yield connection.connect();
34-
console.log('Connection established');
35+
logger.info('Connection established');
3536
}.bind(this));
3637
}
3738

@@ -46,16 +47,17 @@ function processAction(msg, cfg, snapshot = {}) {
4647
const now = new Date().toISOString();
4748
// Last poll should come from Snapshot, if not it's beginning of time
4849
const lastPoll = snapshot.lastPoll || new Date(0).toISOString();
49-
console.log('Last polling timestamp=%s', lastPoll);
50+
this.logger.info('Last polling timestamp=%s', lastPoll);
5051
const sql = originalSql.split(LAST_POLL_PLACEHOLDER).join(lastPoll);
51-
console.log('Original query=%s', originalSql);
52-
console.log('Transformed query=%s', sql);
52+
this.logger.trace('Original query=%s', originalSql);
53+
this.logger.trace('Transformed query=%s', sql);
54+
const that = this;
5355
return co(function* gen() {
5456
const request = new cosql.Request(connection);
5557
request.stream = true;
5658

5759
request.on('recordset', (recordset) => {
58-
console.log('Have got recordset metadata=%j', recordset);
60+
that.logger.trace('Have got recordset metadata=%j', recordset);
5961
});
6062

6163
request.on('row', (row) => {
@@ -67,7 +69,7 @@ function processAction(msg, cfg, snapshot = {}) {
6769
});
6870

6971
request.on('done', (affected) => {
70-
console.log('Query execution completed, affected=%s', affected);
72+
that.logger.info('Query execution completed, affected=%s', affected);
7173
this.emit('snapshot', {
7274
lastPoll: now
7375
});

0 commit comments

Comments
 (0)