Skip to content

Commit

Permalink
remove constants
Browse files Browse the repository at this point in the history
Signed-off-by: Musilah <[email protected]>
  • Loading branch information
Musilah committed Feb 26, 2024
1 parent c7d3afa commit 867d3c2
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions readers/timescale/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ func (tr timescaleRepository) ReadAll(chanID string, rpm readers.PageMetadata) (
q = fmt.Sprintf(`
SELECT
channel, publisher, protocol, name, unit,
EXTRACT(epoch FROM time_bucket('1 hour', to_timestamp(time))) AS time,
MAX(value) AS value
EXTRACT(epoch FROM time_bucket('%s', to_timestamp(time))) AS time,
%s(value) AS value
FROM
messages
%s
WHERE
%s
GROUP BY
Expand All @@ -55,6 +55,9 @@ func (tr timescaleRepository) ReadAll(chanID string, rpm readers.PageMetadata) (
LIMIT
:limit OFFSET :offset;
`,
rpm.Interval,
rpm.Aggregation,
format,
fmtCondition(chanID, rpm),
order,
)
Expand Down Expand Up @@ -131,15 +134,13 @@ func (tr timescaleRepository) ReadAll(chanID string, rpm readers.PageMetadata) (
GROUP BY
time
) AS subquery;
`, rpm.Interval,
format,
`, rpm.Interval,
format,
fmtCondition(chanID, rpm),
)
} else {
countQuery = fmt.Sprintf(`SELECT COUNT(*) FROM %s WHERE %s;`, format, fmtCondition(chanID, rpm))
}
fmt.Println("countquery:", countQuery)
fmt.Println("query:", q)

countRows, err := tr.db.NamedQuery(countQuery, params)
if err != nil {
Expand Down

0 comments on commit 867d3c2

Please sign in to comment.