Skip to content

Commit

Permalink
Merge pull request #377 from DenisFerrero/master
Browse files Browse the repository at this point in the history
Revert #304 as discussed in #359
  • Loading branch information
icebob authored Feb 3, 2024
2 parents 072f1b6 + 2c62b5c commit bbf591f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
5 changes: 2 additions & 3 deletions packages/moleculer-db-adapter-sequelize/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,9 @@ class SequelizeDbAdapter {
* @returns {Promise}
*/
createCursor(params, isCounting) {
const strictCountRule = { distinct: true, col: `${this.model.name ||this.model.tableName}.${this.model.primaryKeyAttribute}` };
if (!params) {
if (isCounting)
return this.model.count(strictCountRule);
return this.model.count();

return this.model.findAll();
}
Expand Down Expand Up @@ -357,7 +356,7 @@ class SequelizeDbAdapter {
q.limit = params.limit;

if (isCounting)
return this.model.count(_.merge(q, strictCountRule));
return this.model.count(q);

return this.model.findAll(q);
}
Expand Down
14 changes: 2 additions & 12 deletions packages/moleculer-db-adapter-sequelize/test/unit/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ const { ServiceBroker } = require("moleculer");
jest.mock("sequelize");

const model = {
tableName: "posts",
primaryKeyAttribute: 'id',
sync: jest.fn(() => Promise.resolve()),
findAll: jest.fn(() => Promise.resolve()),
count: jest.fn(() => Promise.resolve()),
Expand Down Expand Up @@ -42,7 +40,6 @@ function protectReject(err) {
const fakeModel = {
name: "posts",
define: {
id: { type: "number", primaryKey: true },
a: 5
},
options: {
Expand Down Expand Up @@ -166,10 +163,7 @@ describe("Test SequelizeAdapter", () => {
adapter.model.findAll.mockClear();
adapter.createCursor(null, true);
expect(adapter.model.count).toHaveBeenCalledTimes(1);
expect(adapter.model.count).toHaveBeenCalledWith({
distinct: true,
col: `${model.tableName}.${model.primaryKeyAttribute}`
});
expect(adapter.model.count).toHaveBeenCalledWith();
});

it("call with query", () => {
Expand All @@ -185,11 +179,7 @@ describe("Test SequelizeAdapter", () => {
let query = {};
adapter.createCursor({ query }, true);
expect(adapter.model.count).toHaveBeenCalledTimes(1);
expect(adapter.model.count).toHaveBeenCalledWith({
distinct: true,
col: `${model.tableName}.${model.primaryKeyAttribute}`,
where: query
});
expect(adapter.model.count).toHaveBeenCalledWith({ where: query });
});

it("call with sort string", () => {
Expand Down

0 comments on commit bbf591f

Please sign in to comment.