feat(db): support SearchDirection in QueryTransactionsParams#1536
feat(db): support SearchDirection in QueryTransactionsParams#1536EvanYan1024 wants to merge 1 commit intohyperledger-labs:mainfrom
Conversation
|
Hi @EvanYan1024 , thanks for submitting this and for the effort. I'll review ASAP. |
|
Hi @EvanYan1024 , thanks for creating the issue. Please, have a look at the unit-tests. There must be something there that if fixed might solve also the integration tests. |
4888046 to
27f5385
Compare
@adecaro Hi,I have fixed all CI errors. thanks |
QueryTransactions previously hard-coded ORDER BY stored_at ASC, making it impossible for callers to request newest-first ordering. Add a *SearchDirection field (pointer) to QueryTransactionsParams. When nil (zero value), the query defaults to ASC for backward compatibility with all existing callers. Set explicitly to &FromLast for descending or &FromBeginning for ascending. This is consistent with the existing SearchDirection field in QueryMovementsParams, while preserving backward compatibility. Signed-off-by: Evan <evanyan@sign.global>
27f5385 to
6e1d50a
Compare
| // SearchDirection is the direction of the search. | ||
| // If nil, defaults to FromBeginning (ascending by stored_at) for backward compatibility. | ||
| // Set explicitly to override: &FromLast for descending, &FromBeginning for ascending. | ||
| SearchDirection *SearchDirection |
There was a problem hiding this comment.
I think we don't need the pointer here because 0 (the default value) represents searching from last. No?
|
Hi @EvanYan1024 , I think we can remove the pointer and then we are good. |
Closes #1539
Summary
QueryTransactionspreviously hard-codedORDER BY stored_at ASC, making itimpossible for callers to request newest-first ordering.
This PR adds a
*SearchDirectionfield (pointer) toQueryTransactionsParams:nil(default): ascending order — preserves backward compatibility with all existing callers&FromLast: descending order (newest first)&FromBeginning: ascending order (oldest first, explicit)Using a pointer avoids the zero-value ambiguity (
FromLast = 0), ensuringexisting code that uses
QueryTransactionsParams{}continues to work unchanged.Changes
driver/common.go: Add*SearchDirectionfield toQueryTransactionsParamssql/common/transactions.go: AddtransactionOrderBy()helper that defaults to ASC when direction is nildbtest/transactions.go: AddSearchDirection ASC/DESCtest cases using records with distinct timestampsTest plan
go testpasses for memory, SQLite, and PostgreSQL backends locallyTestQueryTransactions) confirms default query usesORDER BY stored_at ASC