{"library":"odbc","title":"ODBC for Node.js","description":"The `odbc` package provides asynchronous Node.js bindings to the `unixODBC` driver manager, enabling Node.js applications to connect and interact with various databases via their respective ODBC drivers. The current stable version, 2.5.0, indicates active development with a consistent release cadence of minor and patch updates every few months. Key differentiators include comprehensive Promise support for modern asynchronous programming patterns, significant performance enhancements achieved by leveraging `SQLBindCol` for efficient result set binding, and a complete rewrite using `N-API` for improved stability and compatibility across supported Node.js LTS versions. This package is designed for robust, high-performance enterprise database connectivity in Node.js environments.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install odbc"],"cli":null},"imports":["import odbc from 'odbc';","import { Connection } from 'odbc';","import { Result } from 'odbc';","import { Cursor } from 'odbc';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import odbc from 'odbc';\n\nasync function runQuery() {\n  let connection: odbc.Connection | null = null;\n  try {\n    // Ensure your DSN is configured in odbc.ini and odbcinst.ini\n    // For example, if you have a DSN named 'my-db-dsn' configured to connect to your database.\n    // Or you can pass a full connection string directly.\n    const connectionString = process.env.ODBC_CONNECTION_STRING ?? 'DSN=my-db-dsn';\n\n    connection = await odbc.connect(connectionString);\n    console.log('Successfully connected to the database.');\n\n    const result = await connection.query('SELECT 1 AS MyColumn, \\'Hello, World!\\' AS MyText');\n    console.log('Query result:', result.length ? result[0] : 'No rows returned.');\n\n    const insertResult = await connection.query(`INSERT INTO MyTable (id, name) VALUES (?, ?)`, [2, 'Test User']);\n    console.log('Insert result:', insertResult.count + ' rows affected.');\n\n    // Example of calling a stored procedure (replace with actual procedure and parameters)\n    // const procedureResult = await connection.callProcedure('MySchema', 'MyProcedure', [1, 'param2']);\n    // console.log('Procedure result:', procedureResult);\n\n  } catch (err: any) {\n    console.error('Database operation failed:', err.message);\n  } finally {\n    if (connection) {\n      try {\n        await connection.close();\n        console.log('Connection closed.');\n      } catch (closeErr: any) {\n        console.error('Failed to close connection:', closeErr.message);\n      }\n    }\n  }\n}\n\nrunQuery();\n","lang":"typescript","description":"Demonstrates connecting to an ODBC data source, executing a simple SELECT query, an INSERT statement with parameters, and gracefully closing the connection using async/await and Promises.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}