Skip to content

Commit

Permalink
Merge pull request #247 from stillalivx/master
Browse files Browse the repository at this point in the history
Fix (#223): In case of insertion, return empty array
  • Loading branch information
eveningkid authored Apr 26, 2021
2 parents 0133dee + d9edfd8 commit 0278c27
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/connectors/sqlite3-connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ export class SQLite3Connector implements Connector {
};
}

if (queryDescription.type === "select") {
return [];
}

return { affectedRows: this._client.changes };
}

Expand Down
17 changes: 17 additions & 0 deletions tests/units/queries/sqlite/response.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ Deno.test("SQLite: Response model", async () => {
"Insert response",
);

const selectResponse = await Article.select("id")
.where({ title: "Hello world!" }).get();

assertEquals(
JSON.stringify(selectResponse),
JSON.stringify([{ id: 1 }]),
"Expected one article",
);

const updateResponse = await Article.where({ id: 1 })
.update({ title: "Hello there!" });

Expand Down Expand Up @@ -84,5 +93,13 @@ Deno.test("SQLite: Response model", async () => {
"Delete many records response",
);

const selectEmptyResponse = await Article.all();

assertEquals(
JSON.stringify(selectEmptyResponse),
JSON.stringify([]),
"Select expected empty response",
);

await connection.close();
});

0 comments on commit 0278c27

Please sign in to comment.