Skip to content

Commit

Permalink
Fix sqlite promise issues and update dex to use latest std
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhomart Mukhamejanov committed Dec 13, 2021
1 parent 1e63d85 commit 2f74041
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
11 changes: 6 additions & 5 deletions deps.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
export * as ConsoleColor from "https://deno.land/x/[email protected]/mod.ts";

// NOTE: these changes fixes #303.
export { default as SQLQueryBuilder } from "https://raw.githubusercontent.com/Zhomart/dex/c452c40b365e73265a25c18cb7adf5d35c1dbb8b/mod-dyn.ts";
// NOTE: Migrate to the official https://github.com/aghussb/dex when it's updated to the
// latest deno version.
export { default as SQLQueryBuilder } from "https://raw.githubusercontent.com/Zhomart/dex/930253915093e1e08d48ec0409b4aee800d8bd0c/mod-dyn.ts";

export { camelCase, snakeCase } from "https://deno.land/x/[email protected]/mod.ts";

Expand All @@ -16,6 +17,6 @@ export { Client as PostgresClient } from "https://deno.land/x/[email protected]/m

export { DB as SQLiteClient } from "https://deno.land/x/[email protected]/mod.ts";

export { MongoClient as MongoDBClient, Bson } from "https://deno.land/x/[email protected].0/mod.ts";
export type { ConnectOptions as MongoDBClientOptions } from "https://deno.land/x/[email protected].0/mod.ts";
export type { Database as MongoDBDatabase } from "https://deno.land/x/[email protected].0/src/database.ts";
export { MongoClient as MongoDBClient, Bson } from "https://deno.land/x/[email protected].1/mod.ts";
export type { ConnectOptions as MongoDBClientOptions } from "https://deno.land/x/[email protected].1/mod.ts";
export type { Database as MongoDBDatabase } from "https://deno.land/x/[email protected].1/src/database.ts";
7 changes: 3 additions & 4 deletions lib/connectors/sqlite3-connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ export class SQLite3Connector implements Connector {
const query = this._translator.translateToQuery(queryDescription);
const subqueries = query.split(/;(?=(?:[^'"]|'[^']*'|"[^"]*")*$)/);

// deno-lint-ignore require-await
const results = subqueries.map(async (subquery, index) => {
const results = subqueries.map((subquery, index) => {
const preparedQuery = this._client.prepareQuery(subquery + ";");
const response = preparedQuery.allEntries();
preparedQuery.finalize();
Expand Down Expand Up @@ -84,7 +83,7 @@ export class SQLite3Connector implements Connector {
const result: Record<string, FieldValue> = {};
for (const [columnName, value] of Object.entries(row)) {
if (columnName === "count(*)") {
result.count = row[columnName] as FieldValue;
result.count = value as FieldValue;
} else if (columnName.startsWith("max(")) {
result.max = value as FieldValue;
} else if (columnName.startsWith("min(")) {
Expand All @@ -101,7 +100,7 @@ export class SQLite3Connector implements Connector {
});
});

return results[results.length - 1];
return Promise.resolve(results[results.length - 1]);
}

async transaction(queries: () => Promise<void>) {
Expand Down
4 changes: 4 additions & 0 deletions tests/units/queries/sqlite/response.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ Deno.test("SQLite: Response model", async () => {
"Update many records response",
);

const articleCount = await Article.where({ title: "hola mundo!" }).count();

assertEquals(articleCount, 2, "Return article count");

const deleteManyResponse = await Article.where({ title: "hola mundo!" })
.delete();

Expand Down

0 comments on commit 2f74041

Please sign in to comment.