(Lost) How to add calculated field on Database > API response ?

Answered

Hi everyone !

I'm a new Xano user and i use an api to return a simple database request :

  • In my table i have several entries named 'Tasks', each task is linked to a 'Person'.

  • The request i use in API call return all Tasks related to this person.

  • I use the database function 'Query all Records from' and return the result :

[
 0: {
   'id': 2 'created_at': 1693256023830    'blueprints_id': 21   'last_date': '2023-09-01'
   'next_date': '2023-09-30'
   'name': 'Task 1'
   'person_id': 2
 }
 1: {
   'id': 4 'created_at': 1694370471507    'blueprints_id': 3    'last_date': '2023-09-01'
   'next_date': '2023-09-30'
   'name': 'Task 2'
   'person_id': 2
 }
 ] 

Question: I would like to add a new field called 'since' to each item in the array and calculate the number of days from 'next_date' to today's date. I've tried different methods but none seem to solve my problem. Can you help me to find the most efficient in order to accomplish this within Xano ? 🙏

Expected result :

[
 0: {
   'id': 2 'created_at': 1693256023830    'blueprints_id': 21   'last_date': '2023-09-01'
   'next_date': '2023-09-30'   'since': -18
   'name': 'Task 1'
   'person_id': 2
 }
 1: {
   'id': 4 'created_at': 1694370471507    'blueprints_id': 3    'last_date': '2023-09-01'
   'next_date': '2023-09-30'   'since': 2
   'name': 'Task 2'
   'person_id': 2
 }
 ] 

Thanks a lot for your help,

Quentin

4 replies