From 98a3b79e9cc9797026927eb29961f93fed372341 Mon Sep 17 00:00:00 2001 From: SheetJS Date: Tue, 9 Apr 2024 23:39:12 -0400 Subject: [PATCH] sqlite3 and knexjs+sqlite3 demo refresh --- docz/docs/03-demos/23-data/11-sqlite.md | 8 ++-- docz/docs/03-demos/23-data/14-knex.md | 55 ++++++++++++++++++++++--- 2 files changed, 54 insertions(+), 9 deletions(-) diff --git a/docz/docs/03-demos/23-data/11-sqlite.md b/docz/docs/03-demos/23-data/11-sqlite.md index d6d4207..248b562 100644 --- a/docz/docs/03-demos/23-data/11-sqlite.md +++ b/docz/docs/03-demos/23-data/11-sqlite.md @@ -39,10 +39,10 @@ This demo was tested in the following environments: | Platform | Connector Library | Date | |:-----------------|:---------------------------|:-----------| -| Chromium 119 | `sql.js` (`1.8.0`) | 2023-12-04 | -| NodeJS `20.10.0` | `better-sqlite3` (`9.2.0`) | 2023-12-04 | -| BunJS `1.0.15` | (built-in) | 2023-12-04 | -| Deno `1.38.4` | `sqlite` (`3.8`) | 2023-12-04 | +| Chromium 122 | `sql.js` (`1.8.0`) | 2024-04-09 | +| NodeJS `20.12.1` | `better-sqlite3` (`9.4.5`) | 2024-04-09 | +| BunJS `1.1.3` | (built-in) | 2024-04-09 | +| Deno `1.42.1` | `sqlite` (`3.8`) | 2024-04-09 | ::: diff --git a/docz/docs/03-demos/23-data/14-knex.md b/docz/docs/03-demos/23-data/14-knex.md index 9ca3b7b..9038314 100644 --- a/docz/docs/03-demos/23-data/14-knex.md +++ b/docz/docs/03-demos/23-data/14-knex.md @@ -23,10 +23,12 @@ and how to add data from spreadsheets into a database. This demo was tested in the following environments: -| Version | Database | Connector Module | Date | -|:--------|:---------|:-----------------|:-----------| -| `2.5.1` | SQLite | `better-sqlite` | 2023-12-04 | -| `3.0.1` | SQLite | `better-sqlite` | 2023-12-04 | +| Version | Database | Connector Module | Date | +|:----------|:---------|:-----------------|:-----------| +| `0.21.20` | SQLite | `sqlite3` | 2024-04-09 | +| `2.4.2` | SQLite | `better-sqlite3` | 2024-04-09 | +| `2.5.1` | SQLite | `better-sqlite3` | 2024-04-09 | +| `3.1.0` | SQLite | `better-sqlite3` | 2024-04-09 | ::: @@ -185,6 +187,16 @@ let knex = Knex({ npm i --save https://cdn.sheetjs.com/xlsx-${current}/xlsx-${current}.tgz knex better-sqlite3`} +:::note pass + +For KnexJS version `0.21.20`, the `sqlite3` module must be installed: + +{`\ +npm i --save https://cdn.sheetjs.com/xlsx-${current}/xlsx-${current}.tgz knex sqlite3`} + + +::: + 2) Download the [test file](https://sheetjs.com/pres.numbers) ```bash @@ -197,7 +209,6 @@ curl -LO https://sheetjs.com/pres.numbers curl -LO https://docs.sheetjs.com/knex/SheetJSKnexTest.js ``` - This script will: - read and parse the test file `pres.numbers` - create a connection to a SQLite database stored at `SheetJSKnex.db` @@ -226,6 +237,40 @@ npx xlsx-cli SheetJSKnex.xlsx sqlite3 SheetJSKnex.db 'select * from Test_Table' ``` +:::caution pass + +Older versions of KnexJS will throw an error: + +``` +Error: knex: Unknown configuration option 'client' value better-sqlite3. Note that it is case-sensitive, check documentation for supported values. +``` + +Older versions of KnexJS do not support the `better-sqlite3` module. The +`SheetJSKnexTest.js` script must be edited to use `sqlite3`: + +```js title="SheetJSKnexTest.js (edit highlighted lines)" +(async() => { + /* open connection to SheetJSKnex.db */ + // highlight-next-line + let knex = Knex({ client: 'sqlite3', connection: { filename: "SheetJSKnex.db" }, useNullAsDefault: true }); + + try { + /* generate array of objects from worksheet */ + const aoo = XLSX.utils.sheet_to_json(oldws); + + /* create table and load data */ + await aoo_to_knex_table(knex, aoo, "Test_Table"); + } finally { + /* disconnect */ + knex.destroy(); + } + + /* reconnect to SheetJSKnex.db */ + // highlight-next-line + knex = Knex({ client: 'sqlite3', connection: { filename: "SheetJSKnex.db" }, useNullAsDefault: true }); +``` +::: + [^1]: See [`select`](https://knexjs.org/guide/query-builder.html#select) in the KnexJS query builder documentation. [^2]: See [`json_to_sheet` in "Utilities"](/docs/api/utilities/array#array-of-objects-input) [^3]: See ["Sheet Objects"](/docs/csf/sheet) in "SheetJS Data Model" for more details.