Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions .github/workflows/bindings.nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,19 @@ jobs:
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: "18"
node-version: "20"
- name: Corepack
working-directory: bindings/nodejs
run: corepack enable
- name: Install dependencies
working-directory: bindings/nodejs
run: |
yarn install --immutable
run: pnpm install
- name: Check format
working-directory: bindings/nodejs
run: yarn run prettier --check .
run: pnpm prettier --check .
- name: Build
working-directory: bindings/nodejs
run: yarn build:debug
run: pnpm run build:debug
- name: Check diff
run: git diff --exit-code
- run: make -C tests test-bindings-nodejs
Expand All @@ -59,9 +58,11 @@ jobs:
- { target: aarch64-unknown-linux-gnu, runner: ubuntu-20.04 }
- { target: aarch64-unknown-linux-musl, runner: ubuntu-latest }
- { target: x86_64-unknown-linux-musl, runner: ubuntu-latest }
- { target: x86_64-pc-windows-msvc, runner: windows-2019 }
- { target: x86_64-apple-darwin, runner: macos-13 }
- { target: aarch64-apple-darwin, runner: macos-14 }
# FIXME: tmp disable for build issue
# - { target: x86_64-pc-windows-msvc, runner: windows-latest }
# - { target: aarch64-pc-windows-msvc, runner: windows-latest }
- { target: x86_64-apple-darwin, runner: macos-latest }
- { target: aarch64-apple-darwin, runner: macos-latest }
steps:
- uses: actions/checkout@v4
- name: Setup Rust toolchain
Expand All @@ -72,8 +73,9 @@ jobs:
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: "18"
node-version: "20"
- name: Install ziglang
if: contains(matrix.target, '-unknown-linux-')
uses: goto-bus-stop/setup-zig@v2
with:
version: 0.11.0
Expand All @@ -82,16 +84,17 @@ jobs:
run: corepack enable
- name: Install dependencies
working-directory: bindings/nodejs
run: yarn install --immutable
run: pnpm install
- name: build
working-directory: bindings/nodejs
shell: bash
env:
NAPI_TARGET: ${{ matrix.target }}
run: |
export NAPI_TARGET=${{ matrix.target }}
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
yarn build:debug
pnpm run build:debug
else
yarn build
pnpm run build
fi
- name: strip for macos
if: endsWith(matrix.target, '-apple-darwin')
Expand All @@ -118,13 +121,13 @@ jobs:
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: "18"
node-version: "20"
- name: Corepack
working-directory: bindings/nodejs
run: corepack enable
- name: Install dependencies
working-directory: bindings/nodejs
run: yarn install --immutable
run: pnpm install
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
Expand All @@ -136,7 +139,7 @@ jobs:
working-directory: bindings/nodejs
run: |
ls -lRh artifacts
yarn run napi artifacts
pnpm napi artifacts
ls -lRh npm
- name: Add LICENSE
run: cp LICENSE ./bindings/nodejs
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/bindings.python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ jobs:
- os: windows
arch: x86_64
target: x86_64-pc-windows-msvc
runner: windows-2019
runner: windows-latest
- os: macos
arch: x86_64
target: x86_64-apple-darwin
runner: macos-13
runner: macos-latest
- os: macos
arch: aarch64
target: aarch64-apple-darwin
runner: macos-14
runner: macos-latest
steps:
- uses: actions/checkout@v4
- name: Get opts
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
matrix:
include:
- { os: ubuntu, arch: x86_64, target: x86_64-unknown-linux-gnu }
- { os: macos, arch: x86_64, target: x86_64-apple-darwin }
- { os: macos, arch: aarch64, target: aarch64-apple-darwin }
- { os: windows, arch: x86_64, target: x86_64-pc-windows-msvc }
steps:
- uses: actions/checkout@v4
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ jobs:

- name: Install dependencies
working-directory: frontend/
run: |
yarn install --immutable
run: pnpm install

- name: Build
working-directory: frontend/
run: |
yarn build
run: pnpm run build
12 changes: 3 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'

- uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
Expand Down Expand Up @@ -58,7 +52,7 @@ jobs:
include:
- { os: macos, target: aarch64-apple-darwin }
- { os: macos, target: x86_64-apple-darwin }
# - { os: windows, target: x86_64-pc-windows-gnu }
- { os: windows, target: aarch64-pc-windows-msvc }
- { os: windows, target: x86_64-pc-windows-msvc }
runs-on: ${{ matrix.os }}-latest
steps:
Expand Down Expand Up @@ -147,8 +141,8 @@ jobs:
- name: Package
shell: bash
run: |
export arch=${{ matrix.arch }}
export version=${{ github.ref_name }}
arch=${{ matrix.arch }}
version=${{ github.ref_name }}
nfpm package --packager ${{ matrix.packager }} --target dist/pkg/ -f <(envsubst '${arch} ${version}' < nfpm.yaml)

- name: Publish
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ build-frontend:
rm -rf cli/frontend
mkdir -p cli/frontend
cd frontend && \
if [ ! -d node_modules ]; then yarn install; fi && \
yarn build && cp -rf build ../cli/frontend/
if [ ! -d node_modules ]; then pnpm install; fi && \
pnpm build && cp -rf build ../cli/frontend/

run:
make build-frontend
Expand Down
4 changes: 2 additions & 2 deletions bindings/nodejs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ chrono = { workspace = true }
databend-driver = { workspace = true, features = ["rustls", "flight-sql"] }
tokio-stream = { workspace = true }

napi = { version = "2.14", default-features = false, features = [
napi = { version = "2.16", default-features = false, features = [
"napi6",
"async",
"serde-json",
"chrono_date",
] }
napi-derive = "2.14"
napi-derive = "2.16"
once_cell = "1.18"

[build-dependencies]
Expand Down
19 changes: 14 additions & 5 deletions bindings/nodejs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

```shell
cd bindings/nodejs
yarn install
yarn build
pnpm install
pnpm run build
```

## Usage
Expand All @@ -28,12 +28,21 @@ await conn.exec(`CREATE TABLE test (
t DateTime
);`);

// get rows of value array
const rows = await conn.queryIter("SELECT * FROM test");
let row = await rows.next();
while (row) {
console.log(row.values());
row = await rows.next();
}

// get rows of map
const rows = await conn.queryIterMap("SELECT * FROM test");
let row = await rows.next();
while (row) {
console.log(row.data());
row = await rows.next();
}
```

## Type Mapping
Expand Down Expand Up @@ -89,7 +98,7 @@ console.log(value);

```shell
cd bindings/nodejs
yarn install
yarn build:debug
yarn test
pnpm install
pnpm run build:debug
pnpm run test
```
4 changes: 3 additions & 1 deletion bindings/nodejs/generated.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,15 +268,17 @@ if (!nativeBinding) {
throw new Error(`Failed to load native binding`)
}

const { Client, Connection, ConnectionInfo, Schema, Field, RowIterator, RowIteratorExt, RowOrStats, Row, ServerStats } = nativeBinding
const { Client, Connection, ConnectionInfo, Schema, Field, RowIterator, NamedRowIterator, RowIteratorExt, RowOrStats, Row, NamedRow, ServerStats } = nativeBinding

module.exports.Client = Client
module.exports.Connection = Connection
module.exports.ConnectionInfo = ConnectionInfo
module.exports.Schema = Schema
module.exports.Field = Field
module.exports.RowIterator = RowIterator
module.exports.NamedRowIterator = NamedRowIterator
module.exports.RowIteratorExt = RowIteratorExt
module.exports.RowOrStats = RowOrStats
module.exports.Row = Row
module.exports.NamedRow = NamedRow
module.exports.ServerStats = ServerStats
12 changes: 12 additions & 0 deletions bindings/nodejs/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export class Connection {
queryAll(sql: string): Promise<Array<Row>>
/** Execute a SQL query, and return all rows. */
queryIter(sql: string): Promise<RowIterator>
/** Execute a SQL query, and return all rows keyed by column name. */
queryIterMap(sql: string): Promise<NamedRowIterator>
/** Execute a SQL query, and return all rows with schema and stats. */
queryIterExt(sql: string): Promise<RowIteratorExt>
/**
Expand Down Expand Up @@ -70,6 +72,13 @@ export class RowIterator {
/** Get Schema for rows. */
schema(): Schema
}
export class NamedRowIterator {
/**
* Fetch next row.
* Returns `None` if there are no more rows.
*/
next(): Promise<Error | NamedRow | null>
}
export class RowIteratorExt {
/**
* Fetch next row or stats.
Expand All @@ -86,6 +95,9 @@ export class RowOrStats {
export class Row {
values(): Array<any>
}
export class NamedRow {
data(): Record<string, any>
}
export class ServerStats {
get totalRows(): bigint
get totalBytes(): bigint
Expand Down
19 changes: 19 additions & 0 deletions bindings/nodejs/npm/win32-arm64-msvc/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "@databend-driver/lib-win32-arm64-msvc",
"repository": "https://github.com/databendlabs/bendsql.git",
"version": "0.23.2",
"os": [
"win32"
],
"cpu": [
"arm64"
],
"main": "databend-driver.win32-arm64-msvc.node",
"files": [
"databend-driver.win32-arm64-msvc.node"
],
"license": "Apache-2.0",
"engines": {
"node": ">= 10"
}
}
10 changes: 7 additions & 3 deletions bindings/nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
"triples": {
"defaults": true,
"additional": [
"x86_64-unknown-linux-gnu",
"aarch64-unknown-linux-gnu",
"x86_64-unknown-linux-musl",
"aarch64-unknown-linux-musl",
"x86_64-pc-windows-msvc",
"aarch64-pc-windows-msvc",
"x86_64-apple-darwin",
"aarch64-apple-darwin"
]
}
Expand Down Expand Up @@ -45,8 +49,8 @@
"node": ">= 10"
},
"scripts": {
"build": "napi build --platform --target \"${NAPI_TARGET:-}\" --release --js generated.js && node ./scripts/header.js",
"build:debug": "napi build --platform --target \"${NAPI_TARGET:-}\" --js generated.js && node ./scripts/header.js",
"build": "napi build --platform --target=$NAPI_TARGET --release --js generated.js && node ./scripts/header.js",
"build:debug": "napi build --platform --target=$NAPI_TARGET --js generated.js && node ./scripts/header.js",
"docs": "typedoc",
"format": "prettier --write .",
"test": "cucumber-js",
Expand All @@ -66,5 +70,5 @@
"registry": "https://registry.npmjs.org/",
"access": "public"
},
"packageManager": "[email protected]"
"packageManager": "[email protected]+sha512.6e2baf77d06b9362294152c851c4f278ede37ab1eba3a55fda317a4a17b209f4dbb973fb250a77abc463a341fcb1f17f17cfa24091c4eb319cda0d9b84278387"
}
Loading
Loading