Skip to content

Commit

Permalink
sqldb: fix end date filter when querying invoices
Browse files Browse the repository at this point in the history
Previously, the SQL implementation of the invoice query simply
converted the start and end timestamps to time and used them
in SQL queries to check for inclusivity. However, this logic
failed when the start and end timestamps were equal.

This commit addresses and corrects this issue.
  • Loading branch information
bhandras committed Sep 3, 2024
1 parent b57910e commit 06d4267
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion invoices/sql_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -925,8 +925,10 @@ func (i *SQLStore) QueryInvoices(ctx context.Context,
}

if q.CreationDateEnd != 0 {
// We need to add 1 to the end date as we're
// checking less than the end date in SQL.
params.CreatedBefore = sqldb.SQLTime(
time.Unix(q.CreationDateEnd, 0).UTC(),
time.Unix(q.CreationDateEnd+1, 0).UTC(),
)
}

Expand Down
2 changes: 1 addition & 1 deletion sqldb/sqlc/invoices.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sqldb/sqlc/queries/invoices.sql
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ WHERE (
created_at >= sqlc.narg('created_after') OR
sqlc.narg('created_after') IS NULL
) AND (
created_at <= sqlc.narg('created_before') OR
created_at < sqlc.narg('created_before') OR
sqlc.narg('created_before') IS NULL
) AND (
CASE
Expand Down

0 comments on commit 06d4267

Please sign in to comment.