Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into belgianbeer/bugfi…
Browse files Browse the repository at this point in the history
…x-bulkinsert
  • Loading branch information
belgianbeer committed Oct 10, 2023
2 parents c7c3bf9 + b82522d commit b4721ef
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 23 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.git
.gitignore
48 changes: 48 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: CI

on:
# workflow_dispatch:
pull_request:
push:
# branches:
# - master
paths:
- ".github/**"
- ".npmignore"
- "src/**"
- "test/**"
- "package*.json"

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16, 18]

steps:
- uses: actions/checkout@v4

- name: config
run: cp .env.dev .env

- uses: isbang/[email protected]
with:
services: mssql

# - name: Start MSSQL containers
# working-directory: ./
# run: docker-compose up -d mssql

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
# cache: npm

- name: npm install and test
run: |
cp ./test/_config.docker.json ./test/config.json
npm install
npm test
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-contrib-mssql-plus",
"version": "0.12.0",
"version": "0.12.1",
"description": "A node-red node to execute queries, stored procedures and bulk inserts in Microsoft SQL Server and Azure Databases SQL2000 ~ SQL2022",
"main": "odbc.js",
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/locales/zh-TW/mssql.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"max_pool_size": "連線池最大連線數",
"parse_json": "支援 JSON?",
"arith_abort": "ARITHABORT?",
"arith_abort_tooltip": "Ends a query when an overflow or divide-by-zero error occurs during query execution. Should normally be enabled.",
"arith_abort_tooltip": "查詢執行期間發生溢位或除以零錯誤時結束查詢. 通常應該開啟.",
"read_only_intent": "ReadOnly Intent"
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/mssql.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ module.exports = function (RED) {
camelCaseColumns: (config.camelCaseColumns === 'true' || config.camelCaseColumns === true) ? true : undefined, //defaults to undefined.
parseJSON: !!((config.parseJSON === 'true' || config.parseJSON === true)), //defaults to true.
enableArithAbort: !((config.enableArithAbort === 'false' || config.enableArithAbort === false)), //defaults to true.
readOnlyIntent: !((config.readOnlyIntent === 'true' || config.readOnlyIntent === true)) //defaults to false.
readOnlyIntent: (config.readOnlyIntent === 'true' || config.readOnlyIntent === true) //defaults to false.
},
pool: {
max: safeParseInt(config.pool, 5),
Expand Down
89 changes: 69 additions & 20 deletions test/mssql-plus_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
const should = require('should');
const helper = require('node-red-node-test-helper');
const mssqlPlusNode = require('../src/mssql.js');

helper.init(require.resolve('node-red'));

let testConnectionConfig;
try {
testConnectionConfig = require('../test/config.json') || {};
Expand All @@ -11,22 +14,23 @@ try {

function getConfigNode (id, options) {
const defConf = {
'id': 'configNode',
'type': 'MSSQL-CN',
'tdsVersion': '7_4',
'name': 'MS SQL Server connection',
'server': '127.0.0.1',
'port': '1433',
'encyption': false,
'trustServerCertificate': true,
'database': 'testdb',
'useUTC': true,
'connectTimeout': '15000',
'requestTimeout': '15000',
'cancelTimeout': '5000',
'pool': '5',
'parseJSON': false,
'enableArithAbort': true
id: 'configNode',
type: 'MSSQL-CN',
tdsVersion: '7_4',
name: 'MS SQL Server connection',
server: '127.0.0.1',
port: '1433',
encyption: false,
trustServerCertificate: true,
database: 'testdb',
useUTC: true,
connectTimeout: '15000',
requestTimeout: '15000',
cancelTimeout: '5000',
pool: '5',
parseJSON: false,
enableArithAbort: true,
readOnlyIntent: false
};
const configNode = Object.assign({}, defConf, options);
configNode.id = id || configNode.id;
Expand All @@ -49,23 +53,27 @@ describe('Load MSSQL Plus Node', function () {
it('should be loaded', function (done) {
const cn = getConfigNode('configNode', testConnectionConfig);
const flow = [
cn,
{ id: 'helperNode', type: 'helper' },
{ 'id': 'sqlNode', 'type': 'MSSQL', 'name': 'mssql', 'mssqlCN': 'configNode', 'wires': [['helperNode']] },
cn
{ id: 'sqlNode', type: 'MSSQL', name: 'mssql', mssqlCN: cn.id, wires: [['helperNode']] }
];

helper.load(mssqlPlusNode, flow, function () {
const helperNode = helper.getNode('helperNode');
const sqlNode = helper.getNode('sqlNode');
const configNode = helper.getNode('configNode');

should(helperNode).not.be.undefined();
should(sqlNode).not.be.undefined();
should(configNode).not.be.undefined();

sqlNode.should.have.property('type', 'MSSQL');
sqlNode.should.have.property('modeOptType', 'query');

configNode.should.have.property('config');
configNode.should.have.property('pool');
configNode.should.have.property('type', 'MSSQL-CN');

done();
});
});
Expand All @@ -77,9 +85,9 @@ describe('Load MSSQL Plus Node', function () {

const cn = getConfigNode('configNode', testConnectionConfig);
const flow = [
{ id: 'helperNode', type: 'helper' },
cn,
{ 'id': 'sqlNode', 'type': 'MSSQL', 'name': 'mssql', 'mssqlCN': 'configNode', 'wires': [['helperNode']] }
{ id: 'helperNode', type: 'helper' },
{ id: 'sqlNode', type: 'MSSQL', name: 'mssql', mssqlCN: cn.id, wires: [['helperNode']] }
];

helper.load(mssqlPlusNode, flow, function () {
Expand Down Expand Up @@ -111,4 +119,45 @@ describe('Load MSSQL Plus Node', function () {
sqlNode.receive({ payload: query }); // fire input of testNode
});
});

it('should can create table and insert/select data', function (done) {
const cn = getConfigNode('configNode', testConnectionConfig);

const flow = [
cn,
{ id: 'helperNode', type: 'helper' },
{ id: 'sqlNode', type: 'MSSQL', name: 'mssql', mssqlCN: cn.id, wires: [['helperNode']] }
];

helper.load(mssqlPlusNode, flow, function () {
const query = "create table #t (id int PRIMARY KEY, data varchar(20)); insert into #t (id, data) values(1, 'a'); insert into #t (id, data) values(2, 'b'); select * from #t;";
const helperNode = helper.getNode('helperNode');
const sqlNode = helper.getNode('sqlNode');
const configNode = helper.getNode('configNode');

configNode.config.user = testConnectionConfig.username;
configNode.config.password = testConnectionConfig.password;
configNode.pool.config.user = testConnectionConfig.username;
configNode.pool.config.password = testConnectionConfig.password;

configNode.should.have.property('id', 'configNode');

helperNode.on('input', function (msg) {
try {
msg.should.have.property('query', query);
msg.should.have.property('payload');
should(Array.isArray(msg.payload)).be.true('payload must be an array');
should(msg.payload.length).eql(2, 'payload array must have 2 element');
msg.payload[0].should.have.property('id');
msg.payload[0].should.have.property('data');
should(msg.payload[0].id).not.be.undefined();
done();
} catch (error) {
done(error);
}
});

sqlNode.receive({ payload: query }); // fire input of testNode
});
});
});

0 comments on commit b4721ef

Please sign in to comment.