Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bindings/nodejs): add more tests for native types #528

Merged
merged 11 commits into from
Dec 6, 2024
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
8 changes: 5 additions & 3 deletions .github/workflows/bindings.nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ on:
branches:
- main
paths:
- "core/**"
- "sql/**"
- "driver/**"
- "bindings/nodejs/**"
- ".github/workflows/bindings.nodejs.yml"

Expand All @@ -30,7 +32,7 @@ jobs:
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: "20"
node-version: "22"
- name: Corepack
working-directory: bindings/nodejs
run: corepack enable
Expand Down Expand Up @@ -72,7 +74,7 @@ jobs:
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: "20"
node-version: "22"
- name: Install ziglang
if: contains(matrix.target, '-unknown-linux-')
uses: goto-bus-stop/setup-zig@v2
Expand Down Expand Up @@ -121,7 +123,7 @@ jobs:
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: "20"
node-version: "22"
- name: Corepack
working-directory: bindings/nodejs
run: corepack enable
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/bindings.python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ on:
branches:
- main
paths:
- "core/**"
- "sql/**"
- "driver/**"
- "bindings/python/**"
- ".github/workflows/bindings.python.yml"

Expand Down Expand Up @@ -147,8 +149,7 @@ jobs:
pattern: bindings-python-*
merge-multiple: true
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
uses: pypa/gh-action-pypi-publish@unstable/v1
with:
skip-existing: true
verify-metadata: false
packages-dir: bindings/python/artifacts
2 changes: 1 addition & 1 deletion bindings/nodejs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ while (row) {
| `TINYINT` | `Number` |
| `SMALLINT` | `Number` |
| `INT` | `Number` |
| `BIGINT` | `Number` |
| `BIGINT` | `BigInt` |
| `FLOAT` | `Number` |
| `DOUBLE` | `Number` |
| `DECIMAL` | `String` |
Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "databend-driver",
"author": "Databend Authors <opensource@databendlabs.com>",
"author": "Databend Authors <opensource@databend.com>",
"version": "0.24.2",
"license": "Apache-2.0",
"main": "index.js",
Expand Down
1 change: 0 additions & 1 deletion bindings/nodejs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ extern crate napi_derive;
use std::collections::HashMap;

use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
use napi::tokio::time::Interval;
use napi::{bindgen_prelude::*, Env};
use once_cell::sync::Lazy;
use tokio_stream::StreamExt;
Expand Down
88 changes: 78 additions & 10 deletions bindings/nodejs/tests/binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,52 @@ Then("Select string {string} should be equal to {string}", async function (input
});

Then("Select types should be expected native types", async function () {
// Binary
// BOOLEAN
{
const row = await this.conn.queryRow("select to_binary('xyz')");
assert.deepEqual(row.values(), [Buffer.from("xyz")]);
const row = await this.conn.queryRow("SELECT true, false");
assert.deepEqual(row.values(), [true, false]);
}

// TINYINT
{
const row = await this.conn.queryRow("SELECT 1::TINYINT, 2::TINYINT");
assert.deepEqual(row.values(), [1, 2]);
}

// SMALLINT
{
const row = await this.conn.queryRow("SELECT 1::SMALLINT, 2::SMALLINT");
assert.deepEqual(row.values(), [1, 2]);
}

// INT
{
const row = await this.conn.queryRow("SELECT 1::INT, 2::INT");
assert.deepEqual(row.values(), [1, 2]);
}

// BIGINT
{
const row = await this.conn.queryRow("SELECT 14294967295::BIGINT, 1::BIGINT");
assert.deepEqual(row.values(), [14294967295n, 1n]);
}

// FLOAT
{
const row = await this.conn.queryRow("SELECT 1.11::FLOAT, 2.22::FLOAT");
assert.deepEqual(
row.values().map((v) => v.toFixed(2)),
[1.11, 2.22],
);
}

// DOUBLE
{
const row = await this.conn.queryRow("SELECT 1.11::DOUBLE, 2.22::DOUBLE");
assert.deepEqual(
row.values().map((v) => v.toFixed(2)),
[1.11, 2.22],
);
}

// Decimal
Expand All @@ -50,24 +92,50 @@ Then("Select types should be expected native types", async function () {
assert.deepEqual(row.values(), ["15.7563", "5.0"]);
}

// Array
// DATE
{
const row = await this.conn.queryRow(`SELECT [10::Decimal(15,2), 1.1+2.3]`);
assert.deepEqual(row.values(), [["10.00", "3.40"]]);
const row = await this.conn.queryRow("SELECT to_date('2020-01-01'), to_date('2020-01-02')");
assert.deepEqual(row.values(), [new Date("2020-01-01"), new Date("2020-01-02")]);
}

// Map
// TIMESTAMP
{
const row = await this.conn.queryRow(`SELECT {'xx':to_date('2020-01-01')}`);
assert.deepEqual(row.values(), [{ xx: new Date("2020-01-01") }]);
const row = await this.conn.queryRow(
"SELECT to_datetime('2020-01-01 12:34:56.789'), to_datetime('2020-01-02 12:34:56.789')",
);
assert.deepEqual(row.values(), [new Date("2020-01-01T12:34:56.789Z"), new Date("2020-01-02T12:34:56.789Z")]);
}

// VARCHAR
{
const row = await this.conn.queryRow("SELECT 'xyz', 'abc'");
assert.deepEqual(row.values(), ["xyz", "abc"]);
}

// Tuple
// BINARY
{
const row = await this.conn.queryRow("select to_binary('xyz')");
assert.deepEqual(row.values(), [Buffer.from("xyz")]);
}

// ARRAY
{
const row = await this.conn.queryRow(`SELECT [10::Decimal(15,2), 1.1+2.3]`);
assert.deepEqual(row.values(), [["10.00", "3.40"]]);
}

// TUPLE
{
const row = await this.conn.queryRow(`SELECT (10, '20', to_datetime('2024-04-16 12:34:56.789'))`);
assert.deepEqual(row.values(), [[10, "20", new Date("2024-04-16T12:34:56.789Z")]]);
}

// MAP
{
const row = await this.conn.queryRow(`SELECT {'xx':to_date('2020-01-01')}`);
assert.deepEqual(row.values(), [{ xx: new Date("2020-01-01") }]);
}

// Variant as String
{
const value =
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ tokio-stream = { workspace = true }

ctor = "0.2"
once_cell = "1.20"
pyo3 = { version = "0.23", features = ["abi3-py37", "chrono"] }
pyo3 = { version = "0.23.3", features = ["abi3-py37", "chrono"] }
pyo3-async-runtimes = { version = "0.23", features = ["tokio-runtime"] }
tokio = "1.42"
Loading