Database-js Wrapper for ADODB

1.1.3 · maintenance · verified Wed Apr 22

Database-js-adodb is a wrapper library designed to provide ADO (ActiveX Data Objects) connectivity for JavaScript applications, specifically integrating with the database-js abstraction layer. Currently at version 1.1.3, this package offers a standardized interface for interacting with various Microsoft data sources like Access and Excel, leveraging the underlying `node-adodb` package. Its primary differentiator is enabling ADO access within a Node.js environment, particularly useful for legacy Windows-based data systems. A key limitation is its strict dependency on Windows operating systems, as it relies on the Windows Script `cscript` for ADO operations. While it can be used standalone to leverage Promises with ADO, its main purpose is to extend `database-js` with ADO support. Release cadence is typically tied to updates in its upstream dependencies or bug fixes rather than frequent feature additions.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates connecting to both an Access database and an Excel spreadsheet using `database-js-adodb` through the `database-js2` abstraction layer, performing parameterized queries, and closing connections.

const Database = require('database-js2'); // database-js2 is a peer dependency for primary use case

(async () => {
    let connection, statement, rows;
    const dbPath = process.env.DB_PATH || 'C:\\Users\\me\\Desktop\\access_db.mdb'; // Example path, adjust as needed
    const connectionString = `database-js-adodb:///${dbPath}`;

    try {
        // Connect to the ADODB source via database-js
        connection = new Database(connectionString);
        
        // Prepare and execute a parameterized query
        statement = await connection.prepareStatement("SELECT * FROM tablea WHERE user_name = ?");
        rows = await statement.query('not_so_secret_user');
        console.log("Query Results for Access DB:", rows);

        // Example for Excel (version 8) connection
        const excelPath = process.env.EXCEL_PATH || 'C:\\Users\\me\\Desktop\\excel_file.xls'; // Example path, adjust as needed
        // Note: Extended Properties must be correctly escaped within the connection string
        const excelConnectionString = `database-js-adodb:///${excelPath}?Extended Properties='Excel 8.0;HDR=Yes;IMEX=1';`;
        const excelConnection = new Database(excelConnectionString);
        const excelStatement = await excelConnection.prepareStatement("SELECT * FROM [Sheet1$A1:C52] WHERE user_name = ?");
        const excelRows = await excelStatement.query('another_user');
        console.log("Excel Query Results:", excelRows);
        await excelConnection.close();

    } catch (error) {
        console.error("An error occurred:", error);
    } finally {
        if (connection) {
            await connection.close();
        }
    }
})();

view raw JSON →