Skip to content

Commit 06d4267

Browse files
committed
sqldb: fix end date filter when querying invoices
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.
1 parent b57910e commit 06d4267

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

invoices/sql_store.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,8 +925,10 @@ func (i *SQLStore) QueryInvoices(ctx context.Context,
925925
}
926926

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

sqldb/sqlc/invoices.sql.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sqldb/sqlc/queries/invoices.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ WHERE (
7676
created_at >= sqlc.narg('created_after') OR
7777
sqlc.narg('created_after') IS NULL
7878
) AND (
79-
created_at <= sqlc.narg('created_before') OR
79+
created_at < sqlc.narg('created_before') OR
8080
sqlc.narg('created_before') IS NULL
8181
) AND (
8282
CASE

0 commit comments

Comments
 (0)