From 142ede2317c76be037ffcc60983d477c4da8a137 Mon Sep 17 00:00:00 2001 From: Jeff Raymakers Date: Wed, 18 Dec 2024 09:58:38 -0800 Subject: [PATCH 1/4] updates for node neo --- .../nodejs/{sql-query.js => sql-query.mjs} | 17 ++++++----------- .../nodejs/web-service-integration.js | 17 ----------------- .../nodejs/web-service-integration.mjs | 13 +++++++++++++ _includes/quick_installation.html | 2 +- data/installation-data-1.1.yml | 2 +- docs/api/node_neo/overview.md | 4 +++- index.html | 4 ++-- 7 files changed, 26 insertions(+), 33 deletions(-) rename _includes/landing-page/nodejs/{sql-query.js => sql-query.mjs} (50%) delete mode 100644 _includes/landing-page/nodejs/web-service-integration.js create mode 100644 _includes/landing-page/nodejs/web-service-integration.mjs diff --git a/_includes/landing-page/nodejs/sql-query.js b/_includes/landing-page/nodejs/sql-query.mjs similarity index 50% rename from _includes/landing-page/nodejs/sql-query.js rename to _includes/landing-page/nodejs/sql-query.mjs index 8df3833ba04..ffb415f6176 100644 --- a/_includes/landing-page/nodejs/sql-query.js +++ b/_includes/landing-page/nodejs/sql-query.mjs @@ -1,18 +1,13 @@ // Get the top-3 busiest train stations in May -const duckdb = require('duckdb'); -const db = new duckdb.Database(':memory:'); -db.all( +import { DuckDBInstance } from '@duckdb/node-api'; +const instance = await DuckDBInstance.create(); +const connection = await instance.connect(); +const reader = await connection.runAndReadAll( `SELECT station_name, count(*) AS num_services FROM 'http://blobs.duckdb.org/train_services.parquet' WHERE monthname(date) = 'May' GROUP BY ALL ORDER BY num_services DESC - LIMIT 3;`, - (err, res) => { - if (err) { - console.log("Error", err); - } else { - console.table(res); - } - } + LIMIT 3;` ); +console.table(reader.getRows()); diff --git a/_includes/landing-page/nodejs/web-service-integration.js b/_includes/landing-page/nodejs/web-service-integration.js deleted file mode 100644 index e30e3d0ab93..00000000000 --- a/_includes/landing-page/nodejs/web-service-integration.js +++ /dev/null @@ -1,17 +0,0 @@ -// Web Service Integration: -// create endpoint to generate numbers -const express = require("express"); -const duckdb = require("duckdb"); -const app = express(); -const db = new duckdb.Database(":memory:"); -app.get("/getnumbers", (req, res) => { - db.all("SELECT random() AS num FROM range(10)", (a, b) => { - if (a) { - console.warn(a); - res.end("Error " + a); - } - res.end(JSON.stringify(b)); - }); -}); - -app.listen(8082, () => console.log("Go to: http://localhost:8082/getnumbers")); diff --git a/_includes/landing-page/nodejs/web-service-integration.mjs b/_includes/landing-page/nodejs/web-service-integration.mjs new file mode 100644 index 00000000000..b087849c22f --- /dev/null +++ b/_includes/landing-page/nodejs/web-service-integration.mjs @@ -0,0 +1,13 @@ +// Web Service Integration: +// create endpoint to generate numbers +import express from "express"; +import { DuckDBInstance } from '@duckdb/node-api'; +const app = express(); +const instance = await DuckDBInstance.create(); +const connection = await instance.connect(); +app.get("/getnumbers", async (req, res) => { + const reader = await connection.runAndReadAll("SELECT random() AS num FROM range(10)"); + res.end(JSON.stringify(reader.getRows())); +}); + +app.listen(8082, () => console.log("Go to: http://localhost:8082/getnumbers")); diff --git a/_includes/quick_installation.html b/_includes/quick_installation.html index f6c469bea68..b685207f851 100644 --- a/_includes/quick_installation.html +++ b/_includes/quick_installation.html @@ -76,7 +76,7 @@

Installation

{% highlight bash %} -npm install duckdb +npm install @duckdb/node-api {% endhighlight %}
diff --git a/data/installation-data-1.1.yml b/data/installation-data-1.1.yml index dfd8385e216..53e543413a1 100644 --- a/data/installation-data-1.1.yml +++ b/data/installation-data-1.1.yml @@ -134,7 +134,7 @@ platform: all download_method: Package manager architecture: universal - installation_code: npm install duckdb + installation_code: npm install @duckdb/node-api - variant: stable environment: Rust platform: all diff --git a/docs/api/node_neo/overview.md b/docs/api/node_neo/overview.md index aebb4ab5b40..3c2268ca1bf 100644 --- a/docs/api/node_neo/overview.md +++ b/docs/api/node_neo/overview.md @@ -5,7 +5,7 @@ title: Node.js API (Neo) An API for using [DuckDB](https://duckdb.org/) in [Node.js](https://nodejs.org/). -This is a high-level API meant for applications. +The primary package, [@duckdb/duckdb-api](https://www.npmjs.com/package/@duckdb/node-api), is a high-level API meant for applications. It depends on low-level bindings that adhere closely to [DuckDB's C API](https://duckdb.org/docs/api/c/overview), available separately as [@duckdb/duckdb-bindings](https://www.npmjs.com/package/@duckdb/node-bindings). @@ -32,8 +32,10 @@ Some features are not yet complete: ### Supported Platforms +- Linux arm64 (experimental) - Linux x64 - Mac OS X (Darwin) arm64 (Apple Silicon) +- Mac OS X (Darwin) x64 (Intel) - Windows (Win32) x64 ## Examples diff --git a/index.html b/index.html index 119b7fa71a2..6432393f6cc 100644 --- a/index.html +++ b/index.html @@ -311,13 +311,13 @@

{{ event.title }}

{% highlight javascript %} -{% include landing-page/nodejs/sql-query.js %} +{% include landing-page/nodejs/sql-query.mjs %} {% endhighlight %}
{% highlight javascript %} -{% include landing-page/nodejs/web-service-integration.js %} +{% include landing-page/nodejs/web-service-integration.mjs %} {% endhighlight %}
From 4716457a03f5e4b2eca1e7904b4373fc8eafa55a Mon Sep 17 00:00:00 2001 From: Gabor Szarnyas Date: Wed, 18 Dec 2024 20:21:21 +0100 Subject: [PATCH 2/4] Install page: Add note to Node.js nightly --- data/installation-data-1.1.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/data/installation-data-1.1.yml b/data/installation-data-1.1.yml index 53e543413a1..bb3d408746e 100644 --- a/data/installation-data-1.1.yml +++ b/data/installation-data-1.1.yml @@ -302,6 +302,7 @@ download_method: Package manager architecture: universal installation_code: npm install duckdb@next + note: The nightly release of the Node.js driver installs the old Node.js driver and not DuckDB Node Neo. For the Node Neo driver, the nightly release is currently not available. If you require this driver, consider compiling it from source. - variant: nightly environment: C/C++ platform: Windows From a34babf88a19a41f54ea4f1db1a7b59ad1b6c58f Mon Sep 17 00:00:00 2001 From: Gabor Szarnyas Date: Wed, 18 Dec 2024 20:23:41 +0100 Subject: [PATCH 3/4] Update Node Neo links --- index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 6432393f6cc..f0f6745807e 100644 --- a/index.html +++ b/index.html @@ -309,13 +309,13 @@

{{ event.title }}

-
+
{% highlight javascript %} {% include landing-page/nodejs/sql-query.mjs %} {% endhighlight %}
-
+
{% highlight javascript %} {% include landing-page/nodejs/web-service-integration.mjs %} {% endhighlight %} From cae0bed8afa961de0930e613e808919e935a2297 Mon Sep 17 00:00:00 2001 From: Gabor Szarnyas Date: Wed, 18 Dec 2024 20:37:56 +0100 Subject: [PATCH 4/4] Install page: Fix Node.js note --- data/installation-data-1.1.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/installation-data-1.1.yml b/data/installation-data-1.1.yml index bb3d408746e..74017f054e7 100644 --- a/data/installation-data-1.1.yml +++ b/data/installation-data-1.1.yml @@ -302,7 +302,7 @@ download_method: Package manager architecture: universal installation_code: npm install duckdb@next - note: The nightly release of the Node.js driver installs the old Node.js driver and not DuckDB Node Neo. For the Node Neo driver, the nightly release is currently not available. If you require this driver, consider compiling it from source. + note: The nightly release of the Node.js driver installs the old Node.js driver and not DuckDB Node Neo. For the Node Neo driver, the nightly release is currently not available. - variant: nightly environment: C/C++ platform: Windows