-
Notifications
You must be signed in to change notification settings - Fork 221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Binding/Prepared Statements #169
Comments
Not yet. This is something we'd like to add. |
isn't this supported by using knex (or some other query builder) out of the box ? |
whilst pretty much any DB layer supports it, yes, join-monster doesn't support generating it yet. |
wouldn't it be better to use some query builder instead of raw strings to support this ? Like using a composable sql query builder api to do a better sql query building than strings or template litterals ? Or instead of building it as a hardcoded query building capacity within knex, (which at the moment is done by pure text composition if I remember correctly) ? I don't know if this is already possible, perhaps doing something like: sqlExpr: (table) => knex.raw(`COALESCE(:table:.key, 'ok')`, {table}) is already enough ? I mean, as far as I understand, join monster is doing query composition, why bother with the building side |
that's the reason this issue is left open. This means that there is currently no way to use truely parameterized queries with JM (as you can't return a string and a map of parameter keys to parameter values). That being said, there's no reason you can't pre-sanitize your values (and you certainly should). Knex's At my company, we run sqlstring over each query argument before returning it from a Whilst these methods works fine (as long as there are no issues with the library's security!), you lose out on a big part of DB level optimisation. By hard inserting the query arguments, it means (as far as the DB is concerned) you are sending a completely new SQL request every time. |
I see, but my point is join monster should not be responsible for how the sql is parsed and passed to the db-engine, it should only expect an interface. I mean, instead of the sql ast, there should probably be an ast type (the type being a parameter, like knex for instance). The reason why I say this is because, composing knex objects together to build a query (even if those objects are knex.raw) does yield Prepared Statements in the db when executed. The fact that the above example is not yielding parametrized query is simply because we go through the custom join monster ast (which enforces string types as you said)... In essence, I think join monster should manipulate sql query part objects, not parsing any real sql per say, just composing. Then the end user would be expected to use an interface/library that is composable.
|
JM does generate its own AST before passing this to a builder to generate the SQL as per your configured implementation. Right now the supported implementations are (at least..) MySQL, Postgres, Oracle, SQLite, MariaDB. However, I doubt that form would be useful beyond whatever library you design it for (each library would probably have its own flavours of "query part objects" with no common standard). JM ultimately is designed to be library agnostic. By generating a raw SQL statement by default, it means that it's easily interoperable with pretty much any DB library in node. Parameterized queries are something difficult because not only does their syntax and nuances differ per SQL flavour, some libraries within the same SQL flavour handle them differently (i.e. within mysql some libraries support only |
Yeah I know I was just making a case for the argument: "it shouldn't, let the query-builder type of libraries do this".
Again, what I'm saying is: a lot of work for things that have already been done. If, the expected metadata was returning a query object type (defined as a configuration at the beginning), this would not be necessary, it would be expected from the user in his metadata creation in the schemas
Except if it's a parameter itself, that's why I was talking about interfaces. This would defacto solve the issue with prepared statements and hugely simplify the extensibility of the lib. But in the end this is a huge amount of work though, with little practical benefits in the short term. @acarl005 perhaps you have any reflections on this ? |
Has plan to do this? Here is my solution #360 , but may need add more test |
Am I missing something? Because from what I know, some queries are very slow without bindings.
So from this point of view I would put this issue pretty big priority and try to merge something like @s97712 is suggesting asap. |
As far as I can tell, join-monster does not use bind variables in oracle or otherwise. Is there any way within join-monster to allow bind variables (in oracle) or some other way of making sure that the database doesn't need to recreate the query plan every time?
(I'm stuck with Oracle, but open question on the same issue with PostgreSQL as well.)
The text was updated successfully, but these errors were encountered: