Reputation: 375
I am using tinyDB to store some data with python, and I am trying to get the last row that I inserted to the db. so I am doing this:
data = db.all() # get all data from db
last_row = data[len(data) - 1]
and this is how I get the last row, but it is not so efficient because I am getting all the db at the beginning.
is there a better way doing so?
Upvotes: 1
Views: 1259
Reputation: 1610
You can use doc_id
for that case since the last row will the largest index
last_row = db.get(doc_id=len(db))
Upvotes: 1