canjs / can-query-logic

Perform data queries and compare queries against each other. Provides logic useful for data caching and real-time behavior.

Home Page:https://canjs.com/doc/can-query-logic.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use the Query format for string representations of sets

bmomberger-bitovi opened this issue · comments

A previous design decision used the user format of list sets to represent lists in the can-connect list store.

I.e. if the user makes a Query with the feathers format like

            let query = {
              $limit: -1,
              $sort: { datetime: 1 },
              datetime: { $gt: new Date(since) },
              trackerId: this.tracker._id
            }

This object would be serialized into the key in the list store that stored the returned list.

There are some limitations to this approach. If query formats contain exotic objects or user defined types, we may have a problem with turning them into appropriate string representations. We already saw this happening when using raw Date objects, for example.

For robustness, we should instead key our list sets on the processed can-query-logic representation of queries instead of the "raw" user-supplied version. This will allow converters for exotic or complex data types to run before attempting to sort and stringify the object representation. The example above would be converted to a BasicQuery representation as such:

{
  filter: {
    $and: [
      {
        datetime: {
          $gt: "2019-05-20T18:52:16.818Z"
         }
       },
       {
         trackerId: "1001"
       }
    ]
  },
  page: {
    start: 0,
    end: -2
  },
  sort: "datetime"
}