Skip to content
This repository has been archived by the owner on Jun 20, 2022. It is now read-only.

Commit

Permalink
fix: Correctly interpolate queries.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shogun committed May 17, 2018
1 parent 2e96b0b commit fda0ac3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
},
"husky": {
"hooks": {
"pre-commit": "npm run sanity"
"pre-push": "npm run sanity"
}
},
"workspaces": [
Expand Down
6 changes: 5 additions & 1 deletion packages/trail-core/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,17 @@ class TrailsManager {
// Perform the query
const sql = SQL`
SELECT
DISTINCT ON(${{__raw: type}}_id) ${{__raw: type}}_id AS entry
DISTINCT ON($type$_id) $type$_id AS entry
FROM trails
WHERE
("when" >= ${from.toISO()} AND "when" <= ${to.toISO()})
`

const strings = Array.from(sql.strings)
strings.splice(0, 1, strings[0].replace(/\$type\$/g, type))
sql.strings = strings

const footer = ` ORDER BY entry ${desc ? 'DESC' : 'ASC'} LIMIT ${pageSize} OFFSET ${(page - 1) * pageSize}`
sql.append(SQL([footer]))

Expand Down

0 comments on commit fda0ac3

Please sign in to comment.