Giter Club home page Giter Club logo

knex-db2's Introduction

npm version Known Vulnerabilities

Disclaimer: this library is in early stages of development. Use at your own risk. Please submit an issue for any bugs encounter or any questions you have.

Looking for new maintainers

If anyone would like to take ownership of this project, please contact me. I built this to simplify my life at my previous employer, but I no longer have a need for it.

Description

This is an external dialect for knex.

Limitations

Currently this dialect has limited functionality compared to the Knex built-in dialects. Below are some of the limitations:

  • No transaction support
  • No streaming support
  • Possibly other missing functionality

Supported functionality

Installing

npm install knex-db2

Requires Node v6 or higher.

Dependencies

npm install odbc see ODBC dependencies if you run into any issues

npm install knex

Usage

const Knex = require('knex')
const Db2Dialect = require('knex-db2')

const knex = Knex({
	client: Db2Dialect,
	connection: {
		host: 'localhost',
		database: 'knextest',
		port: 50000,
		user: 'db2inst1',
		password: 'db2inst1-pwd',
		driver: '{IBM Cli Driver}',
		connectionStringParams: {
			ALLOWPROCCALLS: 1,
			CMT: 0
		}
	},
	pool: {
		min: 2,
		max: 10
	}
})

const query = knex
	.select('*')
	.from('table1')
	.where('x', 'y')


query
	.then(result => console.log(result))
	.catch(err => console.error(err))
	.finally(() => process.exit())

ODBC dependencies

  • make: sudo apt install make
  • g++: sudo apt install g++
  • unix odbc: sudo apt-get install unixodbc unixodbc-dev

Configuring your driver

If you don't know the name of your installed driver, then look in look in odbcinst.ini. You can find the full path of the file by running odbcinst -j. There you should see an entry like the one below:

[IBM i Access ODBC Driver 64-bit]       <= driver name enclosed in square brackets
Description=IBM i Access for Linux 64-bit ODBC Driver
Driver=/opt/ibm/iaccess/lib64/libcwbodbc.so
Setup=/opt/ibm/iaccess/lib64/libcwbodbcs.so
Threading=0
DontDLClose=1
UsageCount=1

If that still doesn't work, then unixodbc is probably looking for the config files in the wrong directory. A common case is that the configs are in /etc but your system expects them to be somewhere else. In such case, override the path unixodbc looks in via the ODBCSYSINI and ODBCINI environment variables. E.g., ODBCINI=/etc ODBCSYSINI=/etc.

Installing default driver

Download driver

https://github.com/ibmdb/node-ibm_db#-download-clidriver-based-on-your-platform--architecture-from-the-below-ibm-hosted-url

Install driver

  • Extract downloaded file. This will create a clidriver folder with the driver contents
  • Copy this folder to wherever your system keeps drivers. If you're not sure where to put it, just copy it to /opt/ibm.
  • Add the configuration your /etc/odbcinst.ini file. Below is what the contents of the file should look like if your odbc path is /opt
[IBM Cli Driver]
Description=IBM CLI Driver for Linux 64-bit
Driver=/opt/ibm/clidriver/lib/libdb2.soSetup=libdb2.so.1
hreading=0
DontDLClose=1
UsageCount=1

knex-db2's People

Contributors

cmarkwell avatar henryjw avatar henryjw1 avatar kerumen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

knex-db2's Issues

Knex currently always returns `{ rowCount: -1 }` for raw queries

Example

const rawResult = await knex.raw('select * from mytable')
console.log(JSON.stringify(rawResult)) // prints "{ rowCount: -1 }"

const result = await knex.select().from('mytable')
console.log(JSON.stringify(result)) // prints "[...]"

Expectation
Running a raw query returns the same result as running a Knex query.

Are migrations supported?

Are migrations supported by knex-db2?

I am trying to apply migrations but get following error
Exception has occurred: TypeError TypeError: Cannot read property 'apply' of undefined at SchemaCompiler.toSQL (/home/adk/src/easyviz/easyviz-backend/node_modules/knex/lib/schema/compiler.js:50:26) at SchemaBuilder.toSQL (/home/adk/src/easyviz/easyviz-backend/node_modules/knex/lib/schema/builder.js:68:43) at /home/adk/src/easyviz/easyviz-backend/node_modules/knex/lib/runner.js:37:34 at tryCatcher (/home/adk/src/easyviz/easyviz-backend/node_modules/bluebird/js/release/util.js:16:23) at /home/adk/src/easyviz/easyviz-backend/node_modules/bluebird/js/release/using.js:185:26

Here is the line from compiler.js:50:
this[query.method].apply(this, query.args);

where query.method is "hasTable" and query.args is "knex_migrations".

Debug entries should only show if DEBUG=1

Using logger.debug() should not produce output in the published build unless DEBUG environment variable is explicitly set to 1. Currently the entries are always logged.

Look into using ibm_db instead of node-odbc

Using ibm_db would simplify driver installation and (potentially) development. ibm_db also supports ODBC drivers, so users can continue to use their configured ODBC drivers.

This would resolve #4.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.