hugsql icon indicating copy to clipboard operation
hugsql copied to clipboard

does not work like hugsql?

Open kevinludwig opened this issue 5 years ago • 3 comments
trafficstars

Cool idea to port this to node.js. I've played with HugSQL before with Clojure. Most of the value however in HugSQL (for me) is in the fact that I can call the generated function passing in a db reference + parameters and have it actually execute the query. Have you considered extending the library in this way?

I would also note that if I was using node-pg library for postgres it expects the parameters to not be ? but rather $1, $2, etc. so I'm not sure this would be usable with postgres?

I realize that in the JVM ecosystem there's a standard around database access in JDBC so its easier for the library to just pass in a driver and then generate code, but to not do this strips a large part of the value of the library.

kevinludwig avatar Feb 25 '20 19:02 kevinludwig

Cool idea to port this to node.js

thanks :)

call the generated function passing in a db reference + parameters and have it actually execute the query. Have you considered extending the library in this way?

Yes I have considered it. Initially I designed hugsql to avoid that pattern simply because I didnt want to include 3rd party dependencies on the generated code. Although I still believe that no deps is a good thing I also see the value in having a more user friendly api.

I would also note that if I was using node-pg library for postgres it expects the parameters to not be ? but rather $1, $2, etc. so I'm not sure this would be usable with postgres?

This is already possible. See this example. Unfortunately I havent invested much time in the documentation which might explain why you didnt find this out. Pull request welcome 😃

carocad avatar Feb 25 '20 20:02 carocad

One option that remains dependency-less (at least without prod dependencies) would be to have the user do something like this

    const pg = require('pg');
    const hugsql = require('hugsq')('postgres', pg);
    ...

I.e. the user manages the dependency for whichever actual driver they want, and when they import hugsql they declare which one they're giving you. That way when I use your library I don't get "extra" deps and you don't have to manage library dependency bumps. I realize there are some drawbacks to this but might be preferable and it's pretty close to what clojure's lib does as well.

kevinludwig avatar Feb 25 '20 20:02 kevinludwig

if you have any interest, I created something similar (loosely inspired by hugsql) but is dependent on pg.

https://www.npmjs.com/package/sql-fn

kevinludwig avatar Jul 01 '20 03:07 kevinludwig