Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
hkjang committed Aug 29, 2020
1 parent 256e09e commit 92e3da2
Show file tree
Hide file tree
Showing 6 changed files with 203 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea
node_modules
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2020 hkjang

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Binary file added icons/xmysql.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 62 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"_from": "node-red-contrib-xmysql@0.0.1",
"_id": "node-red-contrib-xmysql@0.0.1",
"_inBundle": false,
"_integrity": "sha512-j13oKWNs/L7zktt1F24wpnHH0W60Gg1lBQ7CuPsOLqlR3VUZ8cPwa+7hb05rT1yxOaZPsrIHqMi6mGUnFuY6AA==",
"_location": "/node-red-contrib-xmysql",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "node-red-contrib-xmysql@0.0.1",
"name": "node-red-contrib-xmysql",
"escapedName": "node-red-contrib-xmysql",
"rawSpec": "0.0.1",
"saveSpec": null,
"fetchSpec": "0.0.1"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmjs.org/node-red-contrib-xmysql/-/node-red-contrib-xmysql-0.0.1.tgz",
"_shasum": "ed92af3e3bdeefc1c2baf0370ae93b00399b920b",
"_spec": "node-red-contrib-xmysql@0.0.1",
"_where": "C:\\Users\\user\\.node-red",
"author": {
"name": "hkjang",
"email": "gagagiga@naver.com"
},
"bugs": {
"url": "https://github.com/hkjang/node-red-contrib-xmysql/issues"
},
"bundleDependencies": false,
"dependencies": {
"querystring": "^0.2.0",
"request": "^2.51.0"
},
"deprecated": false,
"description": "A node-red module to get to your xmysql server",
"homepage": "https://github.com/hkjang/node-red-contrib-xmysql#readme",
"keywords": [
"node-red",
"xmysql",
"get"
],
"license": "MIT",
"main": "xmysql.js",
"name": "node-red-contrib-xmysql",
"node-red": {
"nodes": {
"xmysql": "xmysql.js"
}
},
"repository": {
"type": "git",
"url": "git://github.com/hkjang/node-red-contrib-xmysql.git"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"version": "0.0.1"
}
41 changes: 41 additions & 0 deletions xmysql.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

<script type="text/x-red" data-template-name="xmysql">
<div class="form-row">
<label for="node-input-xmysqlAPIURL"><i class="fa fa-link"></i> API URL</label>
<input type="text" id="node-input-xmysqlAPIURL" placeholder="http://localhost:3000" style=" vertical-align: top;">
</div>

<div class="form-row">
<label for="node-input-tableName"><i class="fa fa-table"></i> TableName </label>
<input type="text" id="node-input-tableName" placeholder="TableName">
</div>

</script>

<script type="text/x-red" data-help-name="xmysql">
<p>Request <b>msg.payload</b> params to xmysql API.</p>
<p>Simple way to get to xmysql API.</p>
<p><a href="https://github.com/o1lab/xmysql" target="_new">ref this</a></p>
</script>

<script type="text/javascript">
RED.nodes.registerType('xmysql',{
category: 'function',
defaults: {
xmysqlAPIURL: {value:"", required:true},
tableName: {value:"", required:false}
},
color:"#01bbff",
icon: "xmysql.png",
align: "left",
inputs:1,
outputs:1,
label: function() {
return this.name||"xmysql";
},
labelStyle: function() {
return this.name?"node_label_italic":"";
}
});

</script>
76 changes: 76 additions & 0 deletions xmysql.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// var axios = require('axios');
var qs = require('querystring');
var request = require('request');

module.exports = function(RED) {
"use strict";

// set this to true to spam your console with stuff.
var xmysqlDebug = true;

function xmysqlOut(n) {
RED.nodes.createNode(this,n);
var self = this;

this.xmysqlAPIURL = n.xmysqlAPIURL;
this.tableName = n.tableName || "";
var node = this;

this.on('input', function (msg) {
var xmysqlAPIURL = node.xmysqlAPIURL || msg.xmysqlAPIURL;
var tableName = node.tableName || msg.tableName;
var method = node.method || msg.method;
var data = msg.payload;
var api = msg.payload.api;
var id = msg.payload.id;

if (xmysqlDebug) { node.log(JSON.stringify(data)); }
try {
var options = {};
options.uri = xmysqlAPIURL + '/api/';
options.method = method;

if(tableName){
options.uri += tableName;
}else{}
// node.error(msg.payload.id);
// node.error(msg.payload.api);
if(id){
options.uri += '/' + id;
}else{}
if(api){
options.uri += '/' +api;
}else{}
if(method === 'get'){
options.uri += '?'+qs.stringify(data);
options.query = JSON.stringify(data);
options.headers = {
};
}else if(method === 'post' || method === 'put' || method === 'delete'){
options.body = JSON.stringify(data);
options.headers = {
'Content-Type': 'application/json',
'Content-Length': data.length
};
node.log(options.body);
}
node.log(options.uri);
request(options, function (err, res, body) {
if(err){
console.trace();
node.log(err,msg);
}else{
msg.payload = body;
msg.res = res;
self.send(msg);
}
});
}
catch (err) {
node.log(err,msg);
console.trace();
}
});
}
RED.nodes.registerType("xmysql", xmysqlOut);
};

0 comments on commit 92e3da2

Please sign in to comment.