Skip to content

Commit 148a345

Browse files
author
Parth Shah
committed
fixes count bug
1 parent ffd01cc commit 148a345

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ALTER TABLE projects ADD COLUMN "projectFullText" text;
2+
UPDATE projects SET "projectFullText" = lower(name || ' ' || coalesce(description, '') || ' ' || coalesce(details#>>'{utm, code}', ''));
3+
CREATE EXTENSION IF NOT EXISTS pg_trgm;
4+
CREATE INDEX project_text_search_idx ON projects USING GIN("projectFullText" gin_trgm_ops);
5+
6+
CREATE OR REPLACE FUNCTION project_text_update_trigger() RETURNS trigger AS $$
7+
begin
8+
new."projectFullText" :=
9+
lower(new.name || ' ' || coalesce(new.description, '') || ' ' || coalesce(new.details#>>'{utm, code}', ''));
10+
return new;
11+
end
12+
$$ LANGUAGE plpgsql;
13+
14+
DROP TRIGGER IF EXISTS project_text_update ON projects;
15+
CREATE TRIGGER project_text_update BEFORE INSERT OR UPDATE ON projects FOR EACH ROW EXECUTE PROCEDURE project_text_update_trigger();

src/models/project.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,15 @@ module.exports = function(sequelize, DataTypes) {
137137
raw: true
138138
})
139139
.then(function(count) {
140+
count = count[0].count
140141
// select project attributes
141142
return sequelize.query(`SELECT ${attributesStr} FROM projects WHERE ${query} ORDER BY ${orderStr} LIMIT ${parameters.limit} OFFSET ${parameters.offset}`,
142143
{ type: sequelize.QueryTypes.SELECT,
143144
logging: (str) => { log.debug(str); },
144145
raw: true
145146
})
146147
.then(function(projects) {
147-
return {rows: projects, count: count.count};
148+
return {rows: projects, count: count};
148149
});
149150
});
150151
}

0 commit comments

Comments
 (0)