Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
Soontao committed May 10, 2024
1 parent af22e9c commit afafc47
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ jest.config.js
.prettierignore
.prettierrc.json
src
renovate.json
tsconfig*
.whitesource
.env.example
6 changes: 4 additions & 2 deletions src/HDBClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import { Mutex } from "@newdash/newdash/functional/Mutex";
import * as hdb from "hdb";
import { inspect } from "node:util";
import { debuglog } from "util";
import { ResultSet } from "./ResultSet";
import { CUDStatement, DCL, DDL, DMLStatement, DQL, DQLStatement, NoParamMatcher, NoParamStatement, ProceduralStatement, ProcedureStatement, Statement, TransactionStatement } from "./Statement";
Expand Down Expand Up @@ -42,12 +43,12 @@ export class HDBClient {
logger("connecting");
const client = hdb.createClient(this.#options);
client.on("error", (err: Error) => {
logger(`network error: ${err}`);
logger(`hdb client error: ${inspect(err)}`);
});
return new Promise((resolve, reject) => {
client.connect((err: Error) => {
if (err) {
logger(`connect error ${err.message}`);
logger(`connect error ${inspect(err)}`);
reject(err);
} else {
logger("connected");
Expand All @@ -61,6 +62,7 @@ export class HDBClient {
}

}
return this;
}

/**
Expand Down
26 changes: 13 additions & 13 deletions test/statement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { run_with_client, run_with_table } from "./utils";


describe("Statement Test Suite", () => {
it("should support prepare for some specific statements", () => run_with_client(async(client) => {

it("should support prepare for some specific statements", () => run_with_client(async (client) => {

const commit = await client.prepare("commit");
expect(commit.functionCode).toBe(FunctionCode.COMMIT);

Expand All @@ -14,8 +14,8 @@ describe("Statement Test Suite", () => {

}));

it("should support consume list stream with sugar", () => run_with_table(
{ ID: "bigint not null", NAME: "nvarchar(255)" },
it("should support consume list stream with sugar", () => run_with_table(
{ ID: "bigint not null", NAME: "nvarchar(255)" },
async (client, table_name) => {
const stat = await client.prepare(`INSERT INTO ${table_name} VALUES (?,?)`);

Expand All @@ -25,21 +25,21 @@ describe("Statement Test Suite", () => {
expect(stat.functionCode).toBe(FunctionCode.INSERT);

const affectedRows = await stat.write([1, "Theo"], [2, "Neo"], [3, "Nano"], [4, "Jobs"]);

expect(affectedRows).toStrictEqual([1, 1, 1, 1]);

const queryStat = client.prepare(`SELECT ID, name from ${table_name} where id = ? and name = ?`);
const queryStat = await client.prepare(`SELECT ID, name from ${table_name} where id = ? and name = ?`);

let rows = [];
for await (const row of (await queryStat).streamQueryObject(1, "Theo")) {
for await (const row of queryStat.streamQueryObject(1, "Theo")) {
expect(row.ID).not.toBeUndefined();
expect(row.NAME).not.toBeUndefined();
rows.push(row);
}
expect(rows.length).toBe(1);

rows = [];
for await (const row of (await queryStat).streamQueryObject(2, "Theo")) {
for await (const row of queryStat.streamQueryObject(2, "Theo")) {
// in fact, this block not executed
expect(row.ID).not.toBeUndefined();
expect(row.NAME).not.toBeUndefined();
Expand All @@ -49,7 +49,7 @@ describe("Statement Test Suite", () => {


rows = [];
for await (const internalRows of (await queryStat).streamQueryList(1, "Theo")) {
for await (const internalRows of queryStat.streamQueryList(1, "Theo")) {
internalRows.forEach(row => {
expect(row.ID).not.toBeUndefined();
expect(row.NAME).not.toBeUndefined();
Expand All @@ -59,7 +59,7 @@ describe("Statement Test Suite", () => {
expect(rows.length).toBe(1);

rows = [];
for await (const internalRows of (await queryStat).streamQueryList(2, "Theo")) {
for await (const internalRows of queryStat.streamQueryList(2, "Theo")) {
// in fact, this block not executed
internalRows.forEach(row => {
expect(row.ID).not.toBeUndefined();
Expand All @@ -68,7 +68,7 @@ describe("Statement Test Suite", () => {
});
}
expect(rows.length).toBe(0);

})
);

Expand Down

0 comments on commit afafc47

Please sign in to comment.