Create a WixDataQuery from JSON

I wonder if there is any support built in for this. I kind of doubt it, but I thought I’d ask, in case I’m missing something.

I need to create a WixDataQuery on the browser side (user clicks on UI widgets that set filters, etc to create the query object)

For performance reasons, I need to run that query on the backend. When run on the front end, the query…at its worst…takes 10 seconds. The same query, run on the back end, takes 2 seconds.

In addition to performance gains, I would like to massage the query result on the back end before sending the results back to the front end. This helps me avoid sending a lot of unnecessary data to the front end.

If I pass the query object from front end code to back end code, it is a JSON blob. Deserializing it only produces a generic Object, not a WixDataQuery object, so there’s no find method.

Is there any way to create a WixDataQuery object from a deserialized JSON blob?

Has anyone built something to do this?

Or do I need to roll my own deserializer? (in which case, deserializing filters becomes a bit painful)


Why can’t you create the query in the backend based on the filter data in the frontend?

This would be in the realm of “rolling my own”, which I can do if I have to. But I just wanted to know if there was any way to serialize the whole query object, then deserialize it to create a WixDataQuery object from it. There is more to a query than just the filter, so I’d love it if there was built in support for this.

I have written serializer/deserializer code for the filters, for another purpose. I save a serialized filter in memory storage so that when the user goes back to the search page, the filters are already selected. I could re-use this code, but again…I just secretly hoped that Wix could do this auto-magically. :slight_smile:

@polkaset You can request new features on the Wishlist Page . On your next birthday, while blowing out your candles… Who knows, maybe someday your wish will come true.

@polkaset BTW - the serializer/deserializer that you built sounds intriguing. Would be a good idea for a post in the Tips, Tutorials, Examples category.

@yisrael-wix My birthday is coming up in March! Sooooo…I’ll expect this to work by then. (totally just kidding :stuck_out_tongue_winking_eye: ).

Regarding putting code up in the tutorials section, I’ve been gradually cleaning up my code, commenting it, JSDoc-ing it, and putting it up on a POC site that I keep for interesting things I’ve seen or done. I haven’t opened up this site for duplicating by others, so you can’t see the code. You can only see the sample UIs. There are two examples there that I think are interesting enough to write a tutorial/example for. The Sliding Window example, and the MVVM example. (I don’t know how people write complicated UIs without Observables, so I rolled my own mini-framework)

I’ve always joked that my Javascript could make a grown man cry, so before I expose my (probably horrific) code to anyone, I need to clean it up.

OK. Here’s my wishlist entry . Everyone vote for it!

You got a vote for your BIRTHDAY :wink::v: