[HN Gopher] Show HN: JAQT - JavaScript Queries and Transformations
       ___________________________________________________________________
        
       Show HN: JAQT - JavaScript Queries and Transformations
        
       Hi all,  I've made a javascript library to simplify
       searching/sorting/filtering in arrays of objects. Its inspired by
       both GraphQL and SQL, but implemented using javascript Proxies.
       Instead of creating a new language, its all just javascript.  I've
       made it as part of an experimental database, which uses javascript
       as the query engine. The normal javascript map/reduce/sort
       functions are quite difficult to master for junior developers. JAQT
       is easier to explain, and can still be used in combination with any
       existing array functions.  Please let me know what you think of the
       API and its ease of use!
        
       Author : Poefke
       Score  : 83 points
       Date   : 2024-09-16 09:08 UTC (13 hours ago)
        
 (HTM) web link (github.com)
 (TXT) w3m dump (github.com)
        
       | jansommer wrote:
       | Wouldn't the query for your example just be
       | 
       | data.filter(d => d.friends.includes("John")).map(d => ({name:
       | d.name+" "+d.lastName}))
       | 
       | Maybe I'm missing the bigger picture, but that doesn't seem so
       | bad
        
         | meiraleal wrote:
         | I liked JAQT API but it is not really good to create a layer on
         | top of already simple functional constructors.
        
           | austin-cheney wrote:
           | Why is that not good? JavaScript is full of layers of
           | unnecessary abstraction often for completely superficial
           | reasons and sometimes even irrationally applied at great cost
           | in defiance of evidence and simplicity. So, what makes this
           | specific example less good than all the other countless
           | examples of abstractions most JavaScript developers would
           | happily die to defend?
        
             | meiraleal wrote:
             | because in the past it didn't have those functional
             | constructors so things like underscore or lodash would be
             | needed but adding a layer as you mentioned. It is not good,
             | for me, to add a dependency for this again. But in the end
             | I have in my utils file a few functions that basically do
             | what JAQT does and I might copy a few more.
        
         | allannienhuis wrote:
         | one of the cases something like this is useful for is when you
         | have user configured saved 'filters' - you can simply pass the
         | stored object into the where clause. I agree if you're doing
         | hard-coded queries on arrays of objects, this may not add a
         | lot. That said, a consistent syntax for doing searches and
         | mapping is useful - projects like lodash have that as part of
         | their api too.
        
           | throwitaway1123 wrote:
           | This is actually a pretty decent use case for something like
           | this. You could technically convert a user provided filter
           | function to a string to serialize it, then recreate it using
           | the Function() constructor, but that requires adding 'unsafe-
           | eval' to your content security policy [1][2].
           | 
           | [1] https://developer.mozilla.org/en-
           | US/docs/Web/JavaScript/Refe...
           | 
           | [2] https://developer.mozilla.org/en-
           | US/docs/Web/JavaScript/Refe...
        
       | ssahoo wrote:
       | Looks like .net Linq. Many js projects use lodash and variants,
       | how do you compare that?
        
       | gryzzly wrote:
       | can a query like that be observable? so updating the array/object
       | would cause the results to update?
        
         | af3d wrote:
         | AFAICT this library generates "flat" JSON objects. Wouldn't be
         | too hard to implement it such that references to Javascript
         | objects are instead returned, where some sort of callback could
         | be invoked whenever the actual object is modified. I do rather
         | like this "query engine" approach, too. It's a much cleaner
         | interface IMO and doesn't seem to incur too much overhead
         | either....
        
         | jansommer wrote:
         | I don't know if RxJS has run out of fashion, but that would
         | give you observable js using map/filter/reduce etc.
        
       | porker wrote:
       | In a similar vein is https://pbeshai.github.io/tidy/ which I've
       | used for 3+ years. It's a really nice lightweight transformer.
       | 
       | I've also used https://github.com/uwdata/arquero once (better
       | performance for large datasets).
        
         | pdyc wrote:
         | any idea what does tidy uses internally? or is it iterating
         | over entire array for every operation?
        
       | iddan wrote:
       | This is everything i wanted
        
       | fbn79 wrote:
       | For the same purpouse I ofter use this https://github.com/calmm-
       | js/partial.lenses
        
       | e1g wrote:
       | There is another excellent write-up exploring the theory / use-
       | cases for such libraries https://www.inkandswitch.com/cambria/
       | (and a corresponding library at
       | https://github.com/inkandswitch/cambria-project)
        
       | kayo_20211030 wrote:
       | Thanks. Looks really useful.
        
       ___________________________________________________________________
       (page generated 2024-09-16 23:00 UTC)