Skip to content

Commit

Permalink
Update dex, sqlite, mysql, mongodb, postgres deps
Browse files Browse the repository at this point in the history
dex: update to the version that uses [email protected], instead
     of the latest version of jspm-core, which could be dangerous
     when jspm-core pushes the latest braking code.
     aghussb/dex#3
sqlite: update to v3.1.3, it contains braking changes
        so this PR fixes them too.
mysql: minor upgrade to v2.10.1 (from v2.10.0)
mongodb: update to v0.28.0, because the old version
         is not compatible with the latest deno.
postgres: update to v0.14.2 and fix update postgres-connectors,
          because the old version is not compatible with the
          latest deno.

The changes are tested on deno v1.16.2.
  • Loading branch information
Zhomart Mukhamejanov committed Nov 21, 2021
1 parent b7cd235 commit 1e63d85
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 45 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ design/*.sketch
examples/
.deno_plugins
.nova/*
tsconfig.json
tsconfig.json
.env
22 changes: 9 additions & 13 deletions deps.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
export * as ConsoleColor from "https://deno.land/x/[email protected]/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/[email protected]/mod.ts";

export {
Client as MySQLClient,
configLogger as configMySQLLogger,
Connection as MySQLConnection,
} from "https://deno.land/x/[email protected].0/mod.ts";
export type { LoggerConfig } from "https://deno.land/x/[email protected].0/mod.ts";
} from "https://deno.land/x/[email protected].1/mod.ts";
export type { LoggerConfig } from "https://deno.land/x/[email protected].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/[email protected]/mod.ts";
export type { ConnectOptions as MongoDBClientOptions } from "https://deno.land/x/[email protected]/mod.ts";
export type { Database as MongoDBDatabase } from "https://deno.land/x/[email protected]/src/database.ts";
export { MongoClient as MongoDBClient, Bson } from "https://deno.land/x/[email protected]/mod.ts";
export type { ConnectOptions as MongoDBClientOptions } from "https://deno.land/x/[email protected]/mod.ts";
export type { Database as MongoDBDatabase } from "https://deno.land/x/[email protected]/src/database.ts";
1 change: 1 addition & 0 deletions lib/connectors/mysql-connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class MySQLConnector implements Connector {
async query(
queryDescription: QueryDescription,
client?: MySQLClient | MySQLConnection,
// deno-lint-ignore no-explicit-any
): Promise<any | any[]> {
await this._makeConnection();

Expand Down
3 changes: 2 additions & 1 deletion lib/connectors/postgres-connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -68,6 +68,7 @@ export class PostgresConnector implements Connector {
}
}

// deno-lint-ignore no-explicit-any
async query(queryDescription: QueryDescription): Promise<any | any[]> {
await this._makeConnection();

Expand Down
45 changes: 17 additions & 28 deletions lib/connectors/sqlite3-connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,27 +48,24 @@ export class SQLite3Connector implements Connector {
}
}

// deno-lint-ignore no-explicit-any
query(queryDescription: QueryDescription): Promise<any | any[]> {
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,
Expand All @@ -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<string, FieldValue> = {};
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];
Expand Down
2 changes: 1 addition & 1 deletion tests/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const defaultMySQLOptions = {
};

const defaultSQLiteOptions = {
filepath: "test.db",
filepath: "test.sqlite",
};

const getMySQLConnection = (options = {}, debug = true): Database => {
Expand Down
2 changes: 1 addition & 1 deletion tests/deps.ts
Original file line number Diff line number Diff line change
@@ -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";

0 comments on commit 1e63d85

Please sign in to comment.