Is there an API or method for querying the first and last data in this project?

50 Views Asked by At

Is there an API or method for querying the first and last data in objectbox-go.

Similar to the First() and Last() methods in Gorm.

I need to use this method to query one by one and then send the data to the server.But I haven't found any relevant methods in objectbox-go.

2

There are 2 best solutions below

0
Markus Junginger On

Several possibilities:

  1. Get all relevant objects at once and iterate over them to send them one-by-one. Typically you use a Query to get data.
  2. Get all IDs, iterate over them: in each iteration, get the actual object for the ID and send it to the server; E.g. use query.FindIds()
  3. Use queries with offset and limit for pagination.

The ID based approach is likely the most resource friendly if you have lots of objects. If you have only a couple of hundred objects or less, you can go with the first approach, which is the simplest one.

0
ezaspi On

This is an Object-box query that works for me.

final query = _studyBox.query().order(Study_.date).build();
Study? aStudy = query.find().lastOrNull;