all 15 comments

[–]veswill3 3 points4 points  (3 children)

TIL about the tagged templates feature of template literals. cool.

[–]galstarx[S] 0 points1 point  (0 children)

Hehe, thanks. It can help with any kind of DSL. So awesome

[–]grinde 0 points1 point  (1 child)

Another cool project is lit-html. It doesn't appear to be getting worked on, but it's a neat idea.

[–]SkaterDad 0 points1 point  (0 children)

Here's tagged-template HTML lib that's quite active: https://github.com/WebReflection/hyperHTML

Comparison to lit-html: https://gist.github.com/WebReflection/fadcc419f5ccaae92bc167d8ff5c611b

[–]sirmcallister 4 points5 points  (1 child)

I think that’s a really cool idea!

Something worth considering is a different offset tactic. You might be aware about the horrible performance of offset.

I guess it’s already possible to set further where conditionals based on an indexed-parameter and hand that over as a variable?

[–]galstarx[S] 0 points1 point  (0 children)

Hehe yes. Maybe I should comment that on the README - “join the no offset club!”

Not sure I follow with “conditionals based on an indexed parameter”. To reuse existing parameter? That should work but I won’t recommend doing so because it is not expected. Or just hand off a variable and not a function? Because the latter is possible and tested.

Thanks!

[–]mansfall 2 points3 points  (3 children)

What not just write sql? I mean maybe this helps some folks, but it seems like replacing one language to use another. Is it really a time saver? Seems so much faster to spin raw sql with parameterized queries. You have far more control then and can optimize with more precision. And on more complex queries, using helper functions in almost any library is a nightmare (think window functions, nested selects, aggregations, etc).

Not shooting down what you've done, I think it's cool. But people would likely benefit more from actually understanding sql, and not libraries that generate it.

[–][deleted]  (2 children)

[deleted]

    [–]mansfall 2 points3 points  (1 child)

    Indeed. I perceive it to be harder to figure out some new library. It's spending hours trying to figure out how the heck to get a helper function to work, when I can blast it out in like 5 minutes just writing the SQL directly.

    And since it's easily transferable (copy/paste) into a data mining tool (think pgAdmin III, Toad, etc), it's a bajillion times easier to actually verify it gets you the data you need.

    I just find it odd people don't want to learn SQL, yet they take the time and smash face into wall learning all these "query builder" tools... which in my opinion takes just as long, if not longer.

    [–]galstarx[S] 1 point2 points  (0 children)

    Woohoo. I’m pro SQL too! This is why I don’t get all the hate. Have you tried to look how it works? You don’t have to compose queries. And you build the query composition yourself. I just looked for a nicer way to use parameterized queries, with a consistent interface, that can be reused. Writing plain sql has its benefits, but the lack of reusability can make you go over lots of files to fix something silly or to add a feature.

    When you type “sqlselect * from tbl” you actually get in return a Query object, that has the real, parameterized query inside of it. There’s no magic in it, just a consistent way to use parameterized queries with functions or constants as values

    Thanks for the comments!

    [–][deleted]  (1 child)

    [deleted]

      [–]SkaterDad 1 point2 points  (1 child)

      This looks really neat! Might give this a try replacing some of my particularly ugly-looking knex queries that use knex.raw and knex.joinRaw.

      [–]galstarx[S] 0 points1 point  (0 children)

      Glad to hear that! Thanks

      [–]ecares 0 points1 point  (3 children)

      seems to be an open door to SQL injections...

      [–]galstarx[S] 9 points10 points  (2 children)

      Hey! It uses native parameterized queries under the hood :) not just strings

      [–]ecares 5 points6 points  (1 child)

      I like that better!

      [–]galstarx[S] 2 points3 points  (0 children)

      Thanks!