From 52112b9432f807445945f026f1d78c76669f2ca1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halvard=20M=C3=B8rstad?= Date: Sun, 21 Apr 2024 19:58:19 +0200 Subject: [PATCH] cleanup and fixes --- deno.json | 3 +-- lib/client.ts | 4 ++-- lib/utils/errors.ts | 4 ++-- lib/utils/logger.ts | 4 ++-- lib/utils/query.ts | 2 +- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/deno.json b/deno.json index 56dc7d1..235c009 100644 --- a/deno.json +++ b/deno.json @@ -15,8 +15,7 @@ "db:stop": "docker compose down --remove-orphans --volumes" }, "imports": { - "@halvardm/sqlx": "../deno-sqlx/mod.ts", - "@halvardm/sqlx/testing": "../deno-sqlx/lib/testing.ts", + "@halvardm/sqlx": "jsr:@halvardm/sqlx@0.0.0-11", "@std/assert": "jsr:@std/assert@^0.221.0", "@std/async": "jsr:@std/async@^0.221.0", "@std/crypto": "jsr:@std/crypto@^0.221.0", diff --git a/lib/client.ts b/lib/client.ts index 307976f..821f6dc 100644 --- a/lib/client.ts +++ b/lib/client.ts @@ -53,7 +53,7 @@ export class MysqlQueriable extends SqlxBase implements readonly queryOptions: MysqlQueryOptions; get connected(): boolean { - throw new Error("Method not implemented."); + return this.connection.connected; } constructor( @@ -181,9 +181,9 @@ export class MysqlPrepared extends SqlxBase implements ) { super(); this.connection = connection; - this.#queriable = new MysqlQueriable(connection); this.sql = sql; this.queryOptions = options; + this.#queriable = new MysqlQueriable(connection, this.queryOptions); } execute( diff --git a/lib/utils/errors.ts b/lib/utils/errors.ts index 2e68cd9..be73e89 100644 --- a/lib/utils/errors.ts +++ b/lib/utils/errors.ts @@ -1,4 +1,4 @@ -import { SqlxError } from "@halvardm/sqlx"; +import { isSqlxError, SqlxError } from "@halvardm/sqlx"; export class MysqlError extends SqlxError { constructor(msg: string) { @@ -46,5 +46,5 @@ export class MysqlTransactionError extends MysqlError { * Check if an error is a MysqlError */ export function isMysqlError(err: unknown): err is MysqlError { - return err instanceof MysqlError; + return isSqlxError(err) && err instanceof MysqlError; } diff --git a/lib/utils/logger.ts b/lib/utils/logger.ts index f70b71d..28830cd 100644 --- a/lib/utils/logger.ts +++ b/lib/utils/logger.ts @@ -1,4 +1,4 @@ -import { getLogger } from "@std/log"; +import { getLogger, type Logger } from "@std/log"; import { MODULE_NAME } from "./meta.ts"; /** @@ -7,6 +7,6 @@ import { MODULE_NAME } from "./meta.ts"; * * @see {@link https://deno.land/std/log/mod.ts} */ -export function logger() { +export function logger(): Logger { return getLogger(MODULE_NAME); } diff --git a/lib/utils/query.ts b/lib/utils/query.ts index 4179d1c..1d4e5fc 100644 --- a/lib/utils/query.ts +++ b/lib/utils/query.ts @@ -58,7 +58,7 @@ export function replaceParams( })`; } case "string": - return `"${escapeString(val)}"`; + return `"${escapeString(val as string)}"`; case "undefined": return "NULL"; case "number":