Modeling intermittent fasting data

Hello everybody,

I’m trying to build a web app to track my fasts. I’m having trouble figuring out how to model a “fast”. I’ve attached a screenshot of how I currently log my data. I apologize if this is a basic question, but I couldn’t find anything in the forums regarding this type of temporal data.

Note: This is my first foray into web development, which is something I’ve always wanted to learn. I recognize that choosing AdonisJS may be overkill for something so basic. However, using a full stack framework seemed like it would hit all the high points while giving me some guidance through structure and convention. Additionally, the focus on “developer joy and stability” is appealing to me. Anyway, on to what matters.

I track two windows using UTC (I travel a lot and using local times made things difficult) date and time:

  • Total Feeding: Anything that breaks a water fast
  • Food: self-explanatory

For example:

  1. Example 1 - Coffee at 0800, first meal at 1200, finish last meal at 2000

    Total Feeding window: 12 hours (0800 to 2000)
    Food Feeding window: 8 hours (1200 to 2000)

  2. Example 2 - (One meal day) Coffee at 0700, first and only meal 1200-1300, finish last tea at 1600

    Total Feedingwindow: 9 hours (0700 to 1600)
    Food window: 1 hour (1200-1300)

I was planning to have one FeedingWindow model:

class FeedingWindowSchema extends Schema {
  up () {
    this.create('feedingwindow', (table) => {
      table.boolean('feeding closed')
      table.boolean('food closed')

  down () {

To calculate the duration, I was going to have another Postgres table and use the Interval type to get the intervals between the opening and closing time datetime for each individual “Feeding Window” row.

Am I doing too much in this one model? Should I break things up and have a FastingEvent model to note single events e.g. 2020-04-28 12:00 "open feeding", 2020-04-28 17:00 "close food", etc.? Then use functions to calculate and create total feeding windows separately?

Or should I scrap my plan completely as there is a much better way to do it?

Any help, feedback, or recommendations are greatly appreciated!

1 Like

Hello @okaythree. Welcome to the Forum!

Firstly, this is a very interesting piece of application you are building.

In my opinion, you should not send the calculations to a different table. I think all the columns can be managed on the same table are modelled already.

Make use of generated (virtual) columns to generate the ‘Total Window’, ‘Food Window’, ‘Pure Fast’, and ‘Food Fast’ columns based on your algorithms. So that once you add/edit the ‘Open’, ‘First Food’, ‘Last Food’, and ‘Close’ columns, the other columns will be automatically generated on the fly by your DB.

I do not think so. All the columns belong to the sample functionality - ‘Timing.’

If you intend to document the actual foods or drink, you can store those on a different table and reference them in the feedingwindow table.

You have multiple design issues there which are not related to Adonis.

Thanks so much for the helpful and actionable feedback! I’ve actually broken up the model as I realized the two “windows” I track are distinct. However, your suggestions of generated columns and referencing feedingWindow have made the models more clear in my mind. I’m still working through the code, but thanks again!

1 Like