npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@bdkinc/knex-ibmi

v0.2.7

Published

Knex dialect for IBMi

Downloads

265

Readme

npm version

Please submit an issue for any bug encounter or any questions you have.

Description

This is an external dialect for knex. This library uses the ODBC (as recommended here https://ibmi-oss-docs.readthedocs.io/en/latest/odbc/README.html) driver and is only tested on IBMi.

For more information on IBMi OSS here are the docs

Supported functionality

  • Query building
  • Query execution (see Limitations)
  • Transactions

Limitations

  • No streaming support

Installation

npm install --save odbc knex @bdkinc/knex-ibmi

Requires Node v16 or higher.

Dependencies

npm install odbc see odbc

npm install knex see knex

Usage

This library can be used as commonjs, esm or TypeScript.

CommonJs

const knex = require("knex");
const { DB2Dialect } = require("@bdkinc/knex-ibmi");

const db = knex({
  client: DB2Dialect,
  connection: {
    host: "localhost", // hostname or ip address of server
    database: "*LOCAL", // usually named in your odbc.ini connection
    port: 50000, // default port
    user: "<user>", // IBMi username
    password: "<password>", // IBMi password
    driver: "IBM i Access ODBC Driver", // defined in odbcinst.ini
    connectionStringParams: { // DSN connection string parameters https://www.ibm.com/docs/en/i/7.5?topic=details-connection-string-keywords
      ALLOWPROCCALLS: 1, 
      CMT: 0,
      DBQ: 'MYLIB' // library or schema that holds the tables
    },
  },
  pool: {
    min: 2,
    max: 10,
  },
});

const query = db.select("*").from("table").where({ foo: "bar" });

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

ESM

import knex from "knex";
import { DB2Dialect } from "@bdkinc/knex-ibmi";

/**
 * @type {import("@bdkinc/knex-ibmi").DB2Config}
 */
const config = {
  client: DB2Dialect,
  connection: {
    host: "localhost", // hostname or ip address of server
    database: "*LOCAL", // usually named in your odbc.ini connection
    port: 50000, // default port
    user: "<user>", // IBMi username
    password: "<password>", // IBMi password
    driver: "IBM i Access ODBC Driver", // defined in odbcinst.ini
    connectionStringParams: { // DSN connection string parameters https://www.ibm.com/docs/en/i/7.5?topic=details-connection-string-keywords
      ALLOWPROCCALLS: 1,
      CMT: 0,
      DBQ: 'MYLIB' // library or schema that holds the tables
    },
  },
  pool: {
    min: 2,
    max: 10,
  },
}

const db = knex(config);

try {
  const data = await db.select("*").from("table").where({ foo: "bar" });
  console.log(data);
} catch (err) {
  throw new Error(err);
} finally {
  process.exit();
}

TypeScript

import { knex } from "knex";
import { DB2Dialect, DB2Config } from "@bdkinc/knex-ibmi";

const config: DB2Config = {
  client: DB2Dialect,
  connection: {
    host: "localhost", // hostname or ip address of server
    database: "*LOCAL", // usually named in your odbc.ini connection
    port: 50000, // default port
    user: "<user>", // IBMi username
    password: "<password>", // IBMi password
    driver: "IBM i Access ODBC Driver", // defined in odbcinst.ini
    connectionStringParams: { // DSN connection string parameters https://www.ibm.com/docs/en/i/7.5?topic=details-connection-string-keywords
      ALLOWPROCCALLS: 1,
      CMT: 0,
      DBQ: 'MYLIB' // library or schema that holds the tables
    },
  },
  pool: {
    min: 2,
    max: 10,
  },
};

const db = knex(config);

try {
  const data = await db.select("*").from("table").where({ foo: "bar" });
  console.log(data);
} catch (err) {
  throw new Error(err);
} finally {
  process.exit();
}

Configuring your driver

If you don't know the name of your installed driver, then 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] <== driver name in square brackets
Description=IBM i Access for Linux ODBC Driver
Driver=/opt/ibm/iaccess/lib/libcwbodbc.so
Setup=/opt/ibm/iaccess/lib/libcwbodbcs.so
Driver64=/opt/ibm/iaccess/lib64/libcwbodbc.so
Setup64=/opt/ibm/iaccess/lib64/libcwbodbcs.so
Threading=0
DontDLClose=1
UsageCount=1

[IBM i Access ODBC Driver 64-bit]
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 a case, override the path unixodbc looks in via the ODBCSYSINI and ODBCINI environment variables. E.g., ODBCINI=/etc ODBCSYSINI=/etc.