Hi all, I am looking for a way to query storage entities with sorting by date.
Assume I have structure:
attributes:
status:
type: integer
timestamp:
type: integer
I want to make a query which will find me entries with status 0 or 1 and sort by timestamp ASC. How to write it with new storage entieties and what kind of index is needed.
Thank you for any help
I am also beginner and I used the following code to get it done as my understanding.
Define your entity like this,
storage:
entities:
- name: employee
attributes:
status:
type: integer
timestamp:
type: integer
indexes:
- name: by-timestamp-per-status
partition:
- status
range:
- timestamp
And then use this code to retrieve:
await storage
.entity("employee")
.query()
.index("by-timestamp-per-status", {
partition: ["status"]
})
.sort(SortOrder.ASC)
.getMany()
1 Like
Thank you. It’s correct answer. For those who will enouvour to this post might be nice to know timestamp can’t be defined as integer, but should be rather as float because of the 32byte range limit.