diff --git a/bindings/nodejs/README.md b/bindings/nodejs/README.md index ab23c053..8ec5d0e6 100644 --- a/bindings/nodejs/README.md +++ b/bindings/nodejs/README.md @@ -42,20 +42,20 @@ while (row) { ### General Data Types -| Databend | Node.js | -| ----------- | --------------- | -| `BOOLEAN` | `Boolean` | -| `TINYINT` | `Number` | -| `SMALLINT` | `Number` | -| `INT` | `Number` | -| `BIGINT` | `Number` | -| `FLOAT` | `Number` | -| `DOUBLE` | `Number` | -| `DECIMAL` | `String` | -| `DATE` | `Date` | -| `TIMESTAMP` | `Date` | -| `VARCHAR` | `String` | -| `BINARY` | `Array(Number)` | +| Databend | Node.js | +| ----------- | --------- | +| `BOOLEAN` | `Boolean` | +| `TINYINT` | `Number` | +| `SMALLINT` | `Number` | +| `INT` | `Number` | +| `BIGINT` | `Number` | +| `FLOAT` | `Number` | +| `DOUBLE` | `Number` | +| `DECIMAL` | `String` | +| `DATE` | `Date` | +| `TIMESTAMP` | `Date` | +| `VARCHAR` | `String` | +| `BINARY` | `Buffer` | ### Semi-Structured Data Types diff --git a/bindings/nodejs/tests/binding.js b/bindings/nodejs/tests/binding.js index bbf68ff9..5d8a46b7 100644 --- a/bindings/nodejs/tests/binding.js +++ b/bindings/nodejs/tests/binding.js @@ -34,21 +34,35 @@ Then("Select string {string} should be equal to {string}", async function (input }); Then("Select types should be expected native types", async function () { - // NumberValue::Decimal - const row1 = await this.conn.queryRow(`SELECT 15.7563::Decimal(8,4), 2.0+3.0`); - assert.deepEqual(row1.values(), ["15.7563", "5.0"]); + // Binary + { + const row = await this.conn.queryRow("select to_binary('xyz')"); + assert.deepEqual(row.values(), [Buffer.from("xyz")]); + } + + // Decimal + { + const row = await this.conn.queryRow(`SELECT 15.7563::Decimal(8,4), 2.0+3.0`); + assert.deepEqual(row.values(), ["15.7563", "5.0"]); + } // Array - const row2 = await this.conn.queryRow(`SELECT [10::Decimal(15,2), 1.1+2.3]`); - assert.deepEqual(row2.values(), [["10.00", "3.40"]]); + { + const row = await this.conn.queryRow(`SELECT [10::Decimal(15,2), 1.1+2.3]`); + assert.deepEqual(row.values(), [["10.00", "3.40"]]); + } // Map - const row3 = await this.conn.queryRow(`SELECT {'xx':to_date('2020-01-01')}`); - assert.deepEqual(row3.values(), [{ xx: new Date("2020-01-01") }]); + { + const row = await this.conn.queryRow(`SELECT {'xx':to_date('2020-01-01')}`); + assert.deepEqual(row.values(), [{ xx: new Date("2020-01-01") }]); + } // Tuple - const row4 = await this.conn.queryRow(`SELECT (10, '20', to_datetime('2024-04-16 12:34:56.789'))`); - assert.deepEqual(row4.values(), [[10, "20", new Date("2024-04-16T12:34:56.789Z")]]); + { + 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")]]); + } }); Then("Select numbers should iterate all rows", async function () { diff --git a/bindings/python/tests/asyncio/steps/binding.py b/bindings/python/tests/asyncio/steps/binding.py index 3c2924b6..78fd7bcd 100644 --- a/bindings/python/tests/asyncio/steps/binding.py +++ b/bindings/python/tests/asyncio/steps/binding.py @@ -62,17 +62,17 @@ async def _(context, input, output): @then("Select types should be expected native types") @async_run_until_complete async def _(context): - # NumberValue::Decimal + # Binary + row = await context.conn.query_row("select to_binary('xyz')") + assert row.values() == (b"xyz",), f"Binary: {row.values()}" + + # Decimal row = await context.conn.query_row("SELECT 15.7563::Decimal(8,4), 2.0+3.0") assert row.values() == ( Decimal("15.7563"), Decimal("5.0"), ), f"Decimal: {row.values()}" - # Binary - row = await context.conn.query_row("select to_binary('xyz')") - assert row.values() == (b"xyz",), f"Binary: {row.values()}" - # Array row = await context.conn.query_row("select [10::Decimal(15,2), 1.1+2.3]") assert row.values() == ( diff --git a/bindings/python/tests/blocking/steps/binding.py b/bindings/python/tests/blocking/steps/binding.py index 15c4353e..7e8ed32a 100644 --- a/bindings/python/tests/blocking/steps/binding.py +++ b/bindings/python/tests/blocking/steps/binding.py @@ -57,17 +57,17 @@ def _(context, input, output): @then("Select types should be expected native types") async def _(context): - # NumberValue::Decimal + # Binary + row = context.conn.query_row("select to_binary('xyz')") + assert row.values() == (b"xyz",), f"Binary: {row.values()}" + + # Decimal row = context.conn.query_row("SELECT 15.7563::Decimal(8,4), 2.0+3.0") assert row.values() == ( Decimal("15.7563"), Decimal("5.0"), ), f"Decimal: {row.values()}" - # Binary - row = context.conn.query_row("select to_binary('xyz')") - assert row.values() == (b"xyz",), f"Binary: {row.values()}" - # Array row = context.conn.query_row("select [10::Decimal(15,2), 1.1+2.3]") assert row.values() == (