diff --git a/.gitignore b/.gitignore index 964bc8a..2e4dcd6 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,5 @@ design/*.sketch examples/ .deno_plugins .nova/* -tsconfig.json \ No newline at end of file +tsconfig.json +.env diff --git a/deps.ts b/deps.ts index f371c15..b717535 100644 --- a/deps.ts +++ b/deps.ts @@ -1,8 +1,7 @@ export * as ConsoleColor from "https://deno.land/x/colorlog@v1.0/mod.ts"; -// NOTE(eveningkid): this has not be versioned because the Github releases are not up-to-date. -// Only master is valid at the moment. Seems safe for now since there is no commits being added -export { default as SQLQueryBuilder } from "https://raw.githubusercontent.com/aghussb/dex/master/mod.ts"; +// NOTE: these changes fixes #303. +export { default as SQLQueryBuilder } from "https://raw.githubusercontent.com/Zhomart/dex/c452c40b365e73265a25c18cb7adf5d35c1dbb8b/mod-dyn.ts"; export { camelCase, snakeCase } from "https://deno.land/x/case@v2.1.0/mod.ts"; @@ -10,16 +9,13 @@ export { Client as MySQLClient, configLogger as configMySQLLogger, Connection as MySQLConnection, -} from "https://deno.land/x/mysql@v2.10.0/mod.ts"; -export type { LoggerConfig } from "https://deno.land/x/mysql@v2.10.0/mod.ts"; +} from "https://deno.land/x/mysql@v2.10.1/mod.ts"; +export type { LoggerConfig } from "https://deno.land/x/mysql@v2.10.1/mod.ts"; -export { Client as PostgresClient } from "https://deno.land/x/postgres@v0.11.2/mod.ts"; +export { Client as PostgresClient } from "https://deno.land/x/postgres@v0.14.2/mod.ts"; -export { DB as SQLiteClient } from "https://deno.land/x/sqlite@v2.3.1/mod.ts"; +export { DB as SQLiteClient } from "https://deno.land/x/sqlite@v3.1.3/mod.ts"; -// NOTE(eveningkid): upgrading to 0.24.0 would raise an issue asking for the --unstable flag. -// This would be asked to anyone using denodb, not only mongodb users. -// Should wait on a version that isn't using any unstable API -export { MongoClient as MongoDBClient, Bson } from "https://deno.land/x/mongo@v0.22.0/mod.ts"; -export type { ConnectOptions as MongoDBClientOptions } from "https://deno.land/x/mongo@v0.22.0/mod.ts"; -export type { Database as MongoDBDatabase } from "https://deno.land/x/mongo@v0.22.0/src/database.ts"; +export { MongoClient as MongoDBClient, Bson } from "https://deno.land/x/mongo@v0.28.0/mod.ts"; +export type { ConnectOptions as MongoDBClientOptions } from "https://deno.land/x/mongo@v0.28.0/mod.ts"; +export type { Database as MongoDBDatabase } from "https://deno.land/x/mongo@v0.28.0/src/database.ts"; diff --git a/lib/connectors/mysql-connector.ts b/lib/connectors/mysql-connector.ts index 504b16b..866716a 100644 --- a/lib/connectors/mysql-connector.ts +++ b/lib/connectors/mysql-connector.ts @@ -65,6 +65,7 @@ export class MySQLConnector implements Connector { async query( queryDescription: QueryDescription, client?: MySQLClient | MySQLConnection, + // deno-lint-ignore no-explicit-any ): Promise { await this._makeConnection(); diff --git a/lib/connectors/postgres-connector.ts b/lib/connectors/postgres-connector.ts index dc992c1..c1c838f 100644 --- a/lib/connectors/postgres-connector.ts +++ b/lib/connectors/postgres-connector.ts @@ -59,7 +59,7 @@ export class PostgresConnector implements Connector { await this._makeConnection(); try { - const [{ result }] = ( + const [result] = ( await this._client.queryObject("SELECT 1 + 1 as result") ).rows; return result === 2; @@ -68,6 +68,7 @@ export class PostgresConnector implements Connector { } } + // deno-lint-ignore no-explicit-any async query(queryDescription: QueryDescription): Promise { await this._makeConnection(); diff --git a/lib/connectors/sqlite3-connector.ts b/lib/connectors/sqlite3-connector.ts index 1ec8542..5dd4abc 100644 --- a/lib/connectors/sqlite3-connector.ts +++ b/lib/connectors/sqlite3-connector.ts @@ -48,27 +48,24 @@ export class SQLite3Connector implements Connector { } } + // deno-lint-ignore no-explicit-any query(queryDescription: QueryDescription): Promise { this._makeConnection(); const query = this._translator.translateToQuery(queryDescription); const subqueries = query.split(/;(?=(?:[^'"]|'[^']*'|"[^"]*")*$)/); + // deno-lint-ignore require-await const results = subqueries.map(async (subquery, index) => { - const response = this._client.query(subquery + ";", []); + const preparedQuery = this._client.prepareQuery(subquery + ";"); + const response = preparedQuery.allEntries(); + preparedQuery.finalize(); if (index < subqueries.length - 1) { - response.return(); return []; } - const results = []; - let columns; - - try { - columns = response.columns(); - } catch { - // If there are no matching records, .columns will throw an error + if (response.length === 0) { if (queryDescription.type === "insert" && queryDescription.values) { return { affectedRows: this._client.changes, @@ -83,33 +80,25 @@ export class SQLite3Connector implements Connector { return { affectedRows: this._client.changes }; } - for (const row of response) { - const result: { [k: string]: FieldValue } = {}; - - let i = 0; - for (const column of row!) { - const columnName = columns[i].name; + return response.map(row => { + const result: Record = {}; + for (const [columnName, value] of Object.entries(row)) { if (columnName === "count(*)") { - result.count = column; + result.count = row[columnName] as FieldValue; } else if (columnName.startsWith("max(")) { - result.max = column; + result.max = value as FieldValue; } else if (columnName.startsWith("min(")) { - result.min = column; + result.min = value as FieldValue; } else if (columnName.startsWith("sum(")) { - result.sum = column; + result.sum = value as FieldValue; } else if (columnName.startsWith("avg(")) { - result.avg = column; + result.avg = value as FieldValue; } else { - result[columns[i].name] = column; + result[columnName] = value as FieldValue; } - - i++; } - - results.push(result); - } - - return results; + return result; + }); }); return results[results.length - 1]; diff --git a/tests/connection.ts b/tests/connection.ts index f6e473a..ba54c23 100644 --- a/tests/connection.ts +++ b/tests/connection.ts @@ -12,7 +12,7 @@ const defaultMySQLOptions = { }; const defaultSQLiteOptions = { - filepath: "test.db", + filepath: "test.sqlite", }; const getMySQLConnection = (options = {}, debug = true): Database => { diff --git a/tests/deps.ts b/tests/deps.ts index af241ea..b0012d2 100644 --- a/tests/deps.ts +++ b/tests/deps.ts @@ -1 +1 @@ -export { assertEquals } from "https://deno.land/std@0.56.0/testing/asserts.ts"; +export { assertEquals } from "https://deno.land/std@0.115.1/testing/asserts.ts";