Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/codeql/codeql-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
paths-ignore:
- '**/test/**'
28 changes: 28 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: "CodeQL"

on:
push:
branches: [master]
pull_request:
# The branches below must be a subset of the branches above
branches: [master]
schedule:
- cron: '0 13 * * 6'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: 'javascript'
config-file: ./.github/codeql/codeql-config.yml

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
103 changes: 103 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: Continuous Integration

on:
push:
branches: [master]
pull_request:
# The branches below must be a subset of the branches above
branches: [master]
schedule:
- cron: '0 2 * * 1' # At 02:00 on Monday

env:
NODE_OPTIONS: --max-old-space-size=4096

jobs:
test:
name: Test
timeout-minutes: 15
strategy:
matrix:
os: [ubuntu-latest]
node-version: [8.9, 10, 12, 14, 16]
db2:
- image-tag: latest
port-num: 50000
- image-tag: '11.5.0.0'
port-num: 25000
fail-fast: false
runs-on: ${{ matrix.os }}
services:
db2:
image: ibmcom/db2:${{ matrix.db2.image-tag }}
env:
DBNAME: STRONGLOOP
DB2INSTANCE: db2inst1
DB2INST1_PASSWORD: CIDBPassword123
LICENSE: accept
ports: ['${{ matrix.db2.port-num }}:${{ matrix.db2.port-num }}']
# options: >-
# --health-cmd="db2 connect to STRONGLOOP USER db2inst1 USING CIDBPassword123 && db2 ping hostdb"
# --health-timeout=0
# --health-retries=100
env:
DB2_USERNAME: db2inst1
DB2_PASSWORD: CIDBPassword123
DB2_PORTNUM: ${{ matrix.db2.port-num }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Bootstrap project
if: ${{ matrix.node-version != '8.9' }}
run: npm ci
- name: Bootstrap project (Node v8.9)
if: ${{ matrix.node-version == '8.9' }}
run: npm install
- name: Run tests
run: |
npm run pretest --ignore-scripts
npm test --ignore-scripts

code-lint:
name: Code Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js 14
uses: actions/setup-node@v2
with:
node-version: 14
- name: Bootstrap project
if: ${{matrix.node-version != '8.9'}}
run: npm ci
- name: Bootstrap project (Node v8.9)
if: ${{matrix.node-version == '8.9'}}
run: npm install
- name: Verify code linting
run: npm run lint

commit-lint:
name: Commit Lint
runs-on: ubuntu-latest
if: ${{ github.event.pull_request }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Use Node.js 14
uses: actions/setup-node@v2
with:
node-version: 14
- name: Bootstrap project
if: ${{matrix.node-version != '8.9'}}
run: npm ci
- name: Bootstrap project (Node v8.9)
if: ${{matrix.node-version == '8.9'}}
run: npm install
- name: Verify commit linting
run: npx commitlint --from origin/master --to HEAD --verbose
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package-lock=true
scripts-prepend-node-path=true
47 changes: 47 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
arch:
- ppc64le
- s390x
dist: bionic
language: node_js
services: [docker]
node_js: [8.9, 9, 10, 12, 14, 16]

git:
depth: 1

env:
DB2_USERNAME: db2inst1
DB2_PASSWORD: CIDBPassword123
DB2_PORTNUM: 50000

matrix:
include:
env:
DB2_PORTNUM: 50000
DB2_IMAGE_TAG: latest
env:
DB2_PORTNUM: 25000
DB2_IMAGE_TAG: '11.5.0.0'

before_install:
- |-
docker pull ibmcom/db1:${DB2_IMAGE_TAG}
docker run -dit \
-p $DB2_PORTNUM:$DB2_PORTNUM \
-e DBNAME=testdb\
-e DB2INSTANCE=db2inst1 \
-e DB2INST1_PASSWORD=CIDBPassword123 \
-e LICENSE=accept
ibmcom/db2
# - |-
# docker pull ibmcom/db2:11.5.0.0
# docker run -dit \
# -p 25000:25000 \
# -e DBNAME=testdb\
# -e DB2INSTANCE=db2inst1 \
# -e DB2INST1_PASSWORD=CIDBPassword123 \
# -e LICENSE=accept \
# --health-cmd="db2 ping hostdb" \
# --health-timeout=0 \
# --health-retries=100 \
# ibmcom/db2
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# loopback-connector-db2

[![Build Status](https://travis-ci.com/loopbackio/loopback-connector-db2.svg?branch=master)](https://travis-ci.com/loopbackio/loopback-connector-db2)
[![Continuous Integration](https://github.com/loopbackio/loopback-connector-db2/actions/workflows/continuous-integration.yml/badge.svg)](https://github.com/loopbackio/loopback-connector-db2/actions/workflows/continuous-integration.yml)
[![CodeQL](https://github.com/loopbackio/loopback-connector-db2/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/loopbackio/loopback-connector-db2/actions/workflows/codeql-analysis.yml)

[IBM® DB2®](http://www.ibm.com/analytics/us/en/technology/db2/) is the database of choice for robust, enterprise-wide solutions handling high-volume workloads.
It is optimized to deliver industry-leading performance while lowering costs. The `loopback-connector-db2` module is the LoopBack connector for DB2.

Expand Down
20 changes: 20 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright IBM Corp. 2017,2018. All Rights Reserved.
// Node module: loopback-next
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
'use strict';

const isCI = process.env.CI;
module.exports = {
extends: [
'@commitlint/config-conventional',
],
rules: {
'header-max-length': [2, 'always', 100],
'body-leading-blank': [2, 'always'],
'footer-leading-blank': [0, 'always'],
// Only enforce the rule if CI flag is not set. This is useful for release
// commits to skip DCO
'signed-off-by': [isCI ? 0 : 2, 'always', 'Signed-off-by:'],
},
};
12 changes: 6 additions & 6 deletions example/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@

'use strict';

var DataSource = require('loopback-datasource-juggler').DataSource;
var DB2 = require('../'); // loopback-connector-db2
const DataSource = require('loopback-datasource-juggler').DataSource;
const DB2 = require('../'); // loopback-connector-db2

var config = {
const config = {
username: process.env.DB2_USERNAME,
password: process.env.DB2_PASSWORD,
hostname: process.env.DB2_HOSTNAME,
port: 50000,
database: 'SQLDB',
};

var db = new DataSource(DB2, config);
const db = new DataSource(DB2, config);

var User = db.define('User', {name: {type: String}, email: {type: String},
const User = db.define('User', {name: {type: String}, email: {type: String},
});

db.autoupdate('User', function(err) {
Expand All @@ -39,6 +39,6 @@ db.autoupdate('User', function(err) {
});

User.destroyAll(function() {
console.log('example complete');
console.log('example compconste');
});
});
34 changes: 17 additions & 17 deletions lib/db2.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
/*!
* DB2 connector for LoopBack
*/
var IBMDB = require('loopback-ibmdb').IBMDB;
var util = require('util');
var debug = require('debug')('loopback:connector:db2');
const IBMDB = require('loopback-ibmdb').IBMDB;
const util = require('util');
const debug = require('debug')('loopback:connector:db2');

/**
* Initialize the IBMDB connector for the given data source
Expand Down Expand Up @@ -48,10 +48,10 @@ util.inherits(DB2, IBMDB);
DB2.prototype.create = function(model, data, options, callback) {
debug('DB2.prototype.create: model=%s, data=%j, options=%j',
model, data, options);
var self = this;
var stmt = self.buildInsert(model, data, options);
var idName = self.idColumn(model);
var sql;
const self = this;
const stmt = self.buildInsert(model, data, options);
const idName = self.idColumn(model);
let sql;

if (!data[idName]) {
sql = 'SELECT \"' + idName + '\" FROM FINAL TABLE (' +
Expand Down Expand Up @@ -84,15 +84,15 @@ DB2.prototype.create = function(model, data, options, callback) {
DB2.prototype.update = function(model, where, data, options, cb) {
debug('DB2.prototype.update: model=%s, where=%j, data=%j options=%j',
model, where, data, options);
var self = this;
var stmt = self.buildUpdate(model, where, data, options);
var idName = self.idColumn(model);
var sql = 'SELECT COUNT(\"' + idName + '\") AS \"affectedRows\" ' +
const self = this;
const stmt = self.buildUpdate(model, where, data, options);
const idName = self.idColumn(model);
const sql = 'SELECT COUNT(\"' + idName + '\") AS \"affectedRows\" ' +
'FROM FINAL TABLE (' + stmt.sql + ')';
self.execute(sql, stmt.params, options, function(err, info) {
if (cb) {
if (!err && info && info.length > 0) {
var count = Number.parseInt(info[0].affectedRows, 10);
const count = Number.parseInt(info[0].affectedRows, 10);
return cb(null, {count: count});
}
cb(err);
Expand All @@ -111,15 +111,15 @@ DB2.prototype.update = function(model, where, data, options, cb) {
DB2.prototype.destroyAll = function(model, where, options, cb) {
debug('DB2.prototype.destroyAll: model=%s, where=%j, options=%j',
model, where, options);
var self = this;
var stmt = self.buildDelete(model, where, options);
var idName = self.idColumn(model);
var sql = 'SELECT COUNT(\"' + idName + '\") AS \"affectedRows\" ' +
const self = this;
const stmt = self.buildDelete(model, where, options);
const idName = self.idColumn(model);
const sql = 'SELECT COUNT(\"' + idName + '\") AS \"affectedRows\" ' +
'FROM OLD TABLE (' + stmt.sql + ')';
self.execute(sql, stmt.params, options, function(err, info) {
if (cb) {
if (!err && info && info.length > 0) {
var count = Number.parseInt(info[0].affectedRows, 10);
const count = Number.parseInt(info[0].affectedRows, 10);
return cb(null, {count: count});
}
cb(err);
Expand Down
Loading