UNPKG

@teqed/interact-ibmi

Version:

Menus for interacting with IBMi AS400 using node-odbc.

25 lines (24 loc) 1.13 kB
/* This is the module for making ODBC database connections to the IBMi AS400. It has prepared statements as well as allowing custom statements from user input. */ import odbc from 'odbc'; export const getvalues = (query) => { // Iterate over the results. query.forEach(row => { // Iterate over the columns in the row. query.columns.forEach(column => { // Print the column name and value. console.log(`${column.name}: ${row[column.name]}`); }); }); }; let connection; // This accepts a username and password and logs into an IBM i system using ODBC. export const odbcLogin = async (loginId, loginPw, system = `PUB400.COM`) => { const connectionString = ` DRIVER=IBM i Access ODBC Driver;SYSTEM='${system}';UID=${loginId};PWD=${loginPw};`; connection = await odbc.connect(connectionString); return connection; }; // queryOdbc is a function that takes a query and returns a promise that resolves to the result of the query. // It does not show the result of the query to the user. export const queryOdbc = async (statement) => connection.query(statement);