Skip to content

Commit b145541

Browse files
author
Renat Zubairov
authored
Merge pull request #3 from elasticio/zubairov_metadata
Templating for SQL SELECT query
2 parents 1c87289 + 49c4737 commit b145541

File tree

7 files changed

+3303
-98
lines changed

7 files changed

+3303
-98
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
language: node_js
22
node_js:
3+
- v8
34
- v7
45
- v6
56
script: npm test && npm run integration-test

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
# mssql-component
55
MSSQL Component component for the [elastic.io platform](http://www.elastic.io "elastic.io platform")
66

7-
![image](https://cloud.githubusercontent.com/assets/56208/22904377/89b611c4-f23c-11e6-8b5d-783d62cf5caf.png)
8-
7+
![image](https://user-images.githubusercontent.com/56208/29715706-b4930bdc-89a8-11e7-8a0d-969959d26dd6.png)
98

109
## Before you Begin
1110

@@ -26,6 +25,9 @@ other types of configuration parameters are also supported, more infromation and
2625
### SELECT Trigger and Action
2726

2827
With this action you may fetch data out of the database, e.g. using ``SELECT`` statement.
28+
29+
![image](https://user-images.githubusercontent.com/56208/29715706-b4930bdc-89a8-11e7-8a0d-969959d26dd6.png)
30+
2931
This trigger & action has no limitations on the number of rows so you may expect to get all of these
3032
via sequential fetching that is implemented within the node.js ``mssql`` driver.
3133

@@ -41,7 +43,7 @@ where just before executing the statement the ``%%EIO_LAST_POLL%%`` will be repl
4143

4244
### INSERT/DELETE/UPDATE Action
4345

44-
![image](https://cloud.githubusercontent.com/assets/56208/22904204/cef8cb06-f23b-11e6-998f-3fe65ab81540.png)
46+
![image](https://user-images.githubusercontent.com/56208/29715914-9c369ee0-89a9-11e7-89cb-a559f4a8861f.png)
4547

4648
You may use this action to do the operations that are not producing output rows but do the database manipulations,
4749
e.g. ``INSERT``, ``UPDATE`` or ``DELETE`` statements. Internally we use prepared statements, so all incoming data is
@@ -86,8 +88,8 @@ Component supports dynamic incomig metadata - as soon as your query is in place
8688
No known issues are there yet.
8789

8890
## TODOs
89-
* Support for templating in SELECT query
9091
* Support for BULK upload
92+
* Support for DELETE and UPDATE statements
9193
* Support for binary attachments
9294

9395
## License

component.json

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,16 @@
3131
"title": "SELECT",
3232
"description": "Executes a SELECT statement that fetches potentially multiple database rows from the database",
3333
"main": "./lib/actions/select.js",
34-
"fields": {
35-
"query": {
36-
"label": "SQL Query",
37-
"required": true,
38-
"viewClass": "TextAreaWithNoteView",
39-
"placeholder": "SELECT * FROM films WHERE title LIKE ${'%' + query + '%'}",
40-
"note": "You can use properties of message body as <i>${values}</i> in your query"
34+
"metadata": {
35+
"in": {
36+
"type": "object",
37+
"properties": {
38+
"query": {
39+
"type": "string",
40+
"title": "SQL Query",
41+
"required": true
42+
}
43+
}
4144
}
4245
}
4346
}
@@ -48,13 +51,16 @@
4851
"description": "Executes a SELECT statement that fetches potentially multiple database rows from the database",
4952
"main": "./lib/actions/select.js",
5053
"type": "polling",
51-
"fields": {
52-
"query": {
53-
"label": "SQL Query",
54-
"required": true,
55-
"viewClass": "TextAreaWithNoteView",
56-
"placeholder": "SELECT * FROM films WHERE title LIKE ${'%' + query + '%'}",
57-
"note": "You can use properties of message body as <i>${values}</i> in your insert or update or delete"
54+
"metadata": {
55+
"in": {
56+
"type": "object",
57+
"properties": {
58+
"query": {
59+
"type": "string",
60+
"title": "SQL Query",
61+
"required": true
62+
}
63+
}
5864
}
5965
}
6066
}

lib/actions/select.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function init(cfg) {
3131
* @param cfg configuration that is account information and configuration field values
3232
*/
3333
function processAction(msg, cfg, snapshot = {}) {
34-
const originalSql = cfg.query;
34+
const originalSql = cfg.query || msg.body.query;
3535
const now = new Date().toISOString();
3636
// Last poll should come from Snapshot, if not it's beginning of time
3737
const lastPoll = snapshot.lastPoll || new Date(0).toISOString();

0 commit comments

Comments
 (0)