Back

[CLOSED] Query.between

  • 0
  • Databases
Guille
16 Aug, 2023, 18:11

Cant between filter collection with a dateTime attribute?

TypeScript
const query = [Query.between("dateTimeAttribute", "ISOString", "ISOString")]

Currently I'm getting the error Query not valid: Query type does not match expected: datetime. I'm confusing if the errors refers to isn't possible to query datetime attributes, or the value sen't isn't right

TL;DR
The support thread discusses an issue with the `between` method in the Utopia-PHP database module. The problem lies in the parsing of values as a string array. The bug exists in other SDKs as well. The issue has been identified and a bug report has been created. A temporary solution is proposed to manually force the method to use three parameters instead of an array. The full ISO string of the date is provided as an example. It is unclear what exactly is causing the error message "Query not valid: Query type does not match expected: datetime." No solution is provided in the thread.
Binyamin
17 Aug, 2023, 00:03

I've just tests it Can you share the full ISOString you've send?

Binyamin
17 Aug, 2023, 00:04

I've send something like this

TypeScript
const query = [
  Query.between('date','2022-08-17T00:03:13.182Z','2024-08-17T00:03:13.182Z');
]

And it gave me indeed anything in between

Guille
17 Aug, 2023, 12:56

The full ISO string is this:

TypeScript
const start = "2023-08-15T04:00:13.989Z";
const end = "2023-08-15T07:00:21.100Z";

Query.between("date", start, end);

when I print the query, it looks like this: between("date", ["2023-08-15T04:00:13.989Z","2023-08-15T07:00:21.100Z"])

I don't see what is wrong 🤔

Binyamin
17 Aug, 2023, 13:20

It should work It's interesting that the query put the values into arrays Can you try this

TypeScript
const query = [
  ...
  `between("data", "2023-08-15T04:00:13.989Z","2023-08-15T07:00:21.100Z")`,
]

This way we try to force it to use 3 parameters one

Guille
17 Aug, 2023, 16:58

Yes, that solved the problem.

Seems like there is a bug in the library: https://github.com/appwrite/sdk-for-web/blob/master/src/query.ts#L31

Guille
17 Aug, 2023, 16:58

I'll create an issue

Binyamin
17 Aug, 2023, 16:59

I think it has to do with all other SDKs

Binyamin
17 Aug, 2023, 16:59

I saw it in other

Guille
17 Aug, 2023, 16:59

You mean in others sdk it's working?

Binyamin
17 Aug, 2023, 16:59

No, They have the bug as well

Guille
17 Aug, 2023, 17:00

Oh, yes I saw it in the sdk generator repo and it's the same for all

Binyamin
17 Aug, 2023, 17:00

Exactly

Guille
17 Aug, 2023, 17:40

The problem seems to be here

TypeScript
static addQuery = (attribute, method, value) =>
    value instanceof Array
      ? `${method}("${attribute}", [${value
          .map((v) => Query.parseValues(v))
          .join(",")}])`
      : `${method}("${attribute}", [${Query.parseValues(value)}])`;

It always parse the values as string array

Binyamin
17 Aug, 2023, 17:46

Yes, and in Utopia-PHP database module it seems like it should be change either to array or to the fix you've suggested

https://github.com/utopia-php/database/blob/main/src/Database/Query.php#L350

Guille
17 Aug, 2023, 17:49

I think isn't possible to make a change in the SDK repo, as there are cases like when you send multiples values in an array, so in theory the query is valid. The problem is the between method

Guille
17 Aug, 2023, 19:17

[CLOSED] Query.between

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more