-
Notifications
You must be signed in to change notification settings - Fork 3
feat: view list metadata by height #1141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e820e72
feat: view list metadata by height
williamrusdyputra 12ebc94
chore: uncomment actions
williamrusdyputra c8c6aa7
feat: test
williamrusdyputra ddca28e
feat: complete tests
williamrusdyputra 304efdf
chore: put the new metadata action into separate migration file
williamrusdyputra 71e8c20
chore: add column exclusion for table markdown
williamrusdyputra d69f9d5
chore: update assert
williamrusdyputra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| /** | ||
| * list_metadata_by_height: Queries metadata within a specific block height range. | ||
| * Supports pagination. | ||
| * Supports filtering by key and ref. | ||
| * | ||
| * Parameters: | ||
| * $key: filter by metadata key. | ||
| *. $ref: filter by value reference. | ||
| * $from_height: Start height (inclusive). If NULL, uses earliest available. | ||
| * $to_height: End height (inclusive). If NULL, uses current height. | ||
| * $limit: Maximum number of results to return. | ||
| * $offset: Number of results to skip for pagination. | ||
| * | ||
| * Returns: | ||
| * Table with metadata entries matching the criteria. | ||
| */ | ||
| CREATE OR REPLACE ACTION list_metadata_by_height( | ||
| $key TEXT, | ||
| $ref TEXT, | ||
| $from_height INT8, | ||
| $to_height INT8, | ||
| $limit INT, | ||
| $offset INT | ||
| ) PUBLIC view returns table( | ||
| stream_ref INT, | ||
| row_id uuid, | ||
| value_i INT, | ||
| value_f NUMERIC(36,18), | ||
| value_b bool, | ||
| value_s TEXT, | ||
| value_ref TEXT, | ||
| created_at INT8 | ||
| ) { | ||
| -- Set defaults for pagination and validate values | ||
| if $limit IS NULL { | ||
| $limit := 1000; | ||
| } | ||
| if $offset IS NULL { | ||
| $offset := 0; | ||
| } | ||
|
|
||
| -- Ensure non-negative values for PostgreSQL compatibility | ||
| if $limit < 0 { | ||
| $limit := 0; | ||
| } | ||
| if $offset < 0 { | ||
| $offset := 0; | ||
| } | ||
|
|
||
| -- Get current block height for default behavior | ||
| $current_block INT8 := @height; | ||
|
|
||
| -- Determine effective height range, if none given, get all metadata | ||
| $effective_from INT8 := COALESCE($from_height, 0); | ||
| $effective_to INT8 := COALESCE($to_height, $current_block); | ||
|
|
||
| -- Validate height range | ||
| if $effective_from > $effective_to { | ||
| ERROR('Invalid height range: from_height (' || $effective_from::TEXT || ') > to_height (' || $effective_to::TEXT || ')'); | ||
| } | ||
|
|
||
| RETURN SELECT | ||
| stream_ref, | ||
| row_id, | ||
| value_i, | ||
| value_f, | ||
| value_b, | ||
| value_s, | ||
| value_ref, | ||
| created_at | ||
| FROM metadata | ||
| WHERE metadata_key = $key | ||
| AND disabled_at IS NULL | ||
| -- do not use LOWER on value_ref, or it will break the index lookup | ||
| AND ($ref IS NULL OR value_ref = LOWER($ref)) | ||
| AND created_at >= $effective_from | ||
| AND created_at <= $effective_to | ||
| ORDER BY created_at ASC | ||
| LIMIT $limit OFFSET $offset; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.