graphql-engine icon indicating copy to clipboard operation
graphql-engine copied to clipboard

Add date operators (particularly Extract function)

Open florent1933 opened this issue 6 years ago • 7 comments

For now I am filtering all my data in the client but datasets are growing so, I really need something like this: https://www.postgresql.org/docs/11/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT

It will help me to do all the hard work in server side and not downloading the whole dataset.

florent1933 avatar Apr 01 '19 10:04 florent1933

@florent1933 For now you can create a view with the extracted component. If we support this at graphql-engine how do you expect the api to be?

0x777 avatar Apr 04 '19 06:04 0x777

@0x777 , thanks for your answer.

My usecase is a query like: get all datas between dateA and dateB (year/month/day granularity).

I don't know enough of graphQl to suggest you an API.

florent1933 avatar Apr 04 '19 09:04 florent1933

I am not sure if the following is what you needed, but I'll write down what is possible currently. (It is not the extract function from postgres)

You can do the following:

query {
  article(
    where: {
      _and: [
        {created_at: {_gt: "2019-01-01"}},
        {created_at: {_lt: "2019-04-10"}}
      ]
    }
  ) {
    title
    content
    created_at
  }
}

Assuming there is an article table with title, content and created_at fields.

Is this what you are looking for?

ecthiender avatar Apr 04 '19 10:04 ecthiender

Yeah, that's perfect. That's what I planned to do 🙂

florent1933 avatar Apr 04 '19 15:04 florent1933

Any news on this?

About how the api could look, something like this comes to mind.

query test {
  todos(where: {
    created_at: { _extract: "month", _eq: 12 }
  }) {
    id
    created_at
  }
}

or maybe something like this is better

query test {
  todos(where: {
    created_at: [ 
        { _extract: "month" }, 
        { _eq: 12 }
    ]
  }) {
    id
    created_at
  }
}

Fanarito avatar Oct 09 '19 12:10 Fanarito

.

phamquyhai avatar Jun 30 '21 03:06 phamquyhai

+1

christian-predebon avatar Sep 02 '21 14:09 christian-predebon