REST API to query the last row ID in SQL database?


#1

Hi All,

I have added REST API to my SQL database using DreamFactory Services Platform to access SQL database from my android app.

On launching, the app downloads all the records in the table. I wish to place a refresh button in my app which downloads only the new records added to the table after the app was opened (and not all the records in the table).

How do I implement this functionality? Is there any API to retrieve the row ID of the last entry in the SQL database?

Many Thanks,
RS


#2

If your primary key is an auto-incrementing integer you can do a query that sorts by id in descending order with a limit of 1.

GET /rest/db/todo?order=id%20desc&limit=1

You can also sort by created_date, if that field exists.


#3

Thanks , your suggestion helped.