The `database-js-xlsx` package provides a robust `database-js` compatible interface for interacting with Microsoft Excel XLSX files, acting as a crucial bridge between SQL-like queries and spreadsheet data. It is built upon the `xlsx-populate` library for efficient in-memory spreadsheet manipulation and utilizes `node-sqlparser` to interpret SQL commands. Currently stable at version 1.0.6, its release cadence is tied to its underlying dependencies and the `database-js` ecosystem, rather than a fixed schedule. A key advantage of `database-js-xlsx` is its cross-platform compatibility, a significant improvement over Windows-specific drivers within the `database-js` family, such as `database-js-adodb`. Developers should note that the library works with an in-memory copy of the spreadsheet; all changes are buffered and written back to disk only when the connection is explicitly closed. This design means any external modifications to the file during an active connection will be overwritten. The SQL capabilities are limited, supporting SELECT, UPDATE, INSERT, and DELETE statements with functional WHERE clauses, but explicitly prohibiting JOINs and currently lacking support for GROUP BY. Furthermore, LIMIT and OFFSET operations are consolidated into a single `LIMIT [offset,]number` syntax, requiring developers to adapt their pagination strategies accordingly. This package is ideal for Node.js applications needing to perform basic CRUD operations on Excel data programmatically without complex setup or platform restrictions.
npm install database-js-xlsxVerified import paths — ran on the pinned version, not inferred.
Demonstrates connecting to an XLSX file, performing CRUD (Create, Read, Update, Delete) operations, and properly closing the connection using `database-js-xlsx`. It also includes handling for initial file creation and path resolution.
Change `require('database-js2')` to `require('database-js')` in your code.Ensure exclusive access to the XLSX file while a connection is active, or implement a rigorous concurrency strategy if shared access is required (which is not directly supported by this library's design).
Refactor SQL queries to avoid `JOIN` and `GROUP BY`. Perform data aggregation or merging of results programmatically in JavaScript/TypeScript after fetching the base data.
Adjust pagination queries to use `LIMIT [offset,]number` where `offset` is optional. For example, `SELECT * FROM Sheet1 LIMIT 10` for the first 10 rows, or `SELECT * FROM Sheet1 LIMIT 10, 20` for 20 rows starting after the first 10.
Update your `require` statement from `require('database-js2')` to `require('database-js')`.Refactor your query to avoid `JOIN` operations. Instead, perform multiple `SELECT` statements and merge the results in your application logic.
Retrieve the necessary data without `GROUP BY` and then perform the aggregation (e.g., summing, counting) programmatically in your JavaScript/TypeScript code.
Ensure that `require('database-js-xlsx');` is executed early in your application's lifecycle, preferably before any `new Database(...)` calls, to register the XLSX driver.