OpenGamma / ElSql

Manage external SQL files in Java with a little DSL goodness
Other
101 stars 26 forks source link

Named parameters with symbols that represent a custom function #24

Closed davsclaus closed 9 years ago

davsclaus commented 9 years ago

Hi

As I developed the camel-elsql [1] component its based on an existing camel-sql component. In the latter we also support named parameters but the syntax is slightly different, we use :# as the marker for a named parameter. However we allow the named parameter to present a function that we evaluate at runtime to fetch the actual value.

for example

:#${body.user.firstName}

Where the function is represented using ${xxxx}

When using ElSql that does not work, as I cannot do in

SELECT *
FROM FOO
WHERE name = :${body.user.firstName}

At runtime that gives me a parameter name in the hasParameter callback with the value of :${body.user.firstName. Notice the last } is missing. I also noticed that in other combos that the value was empty.

I just logged this ticket here in the morning to ask whether ElSql would consider some kind of support for named parameters as functions. I guess the problem could be parsing the syntax.

Though I am considering in the next Camel release to consider the parameter name as a function if there is no direct hit, so you can do

SELECT *
FROM FOO
WHERE name = :body.user.firstName

Anyway just wanted to say thanks as well for this great SQL library. I love that it allows me to work with SQL externally and that they resemble actual SQL. That is why I also like MyBatis etc. But this library is even lighter.

jodastephen commented 9 years ago

Does this branch cover the need here?

davsclaus commented 9 years ago

Oh thanks @jodastephen I will build from the branch and test it in Camel

davsclaus commented 9 years ago

Perfect this worked like a charm.

I can do

@NAME(projectsByIdBody)
  SELECT *
  FROM projects
  WHERE license = :${body.license}
  ORDER BY id
jodastephen commented 9 years ago

Are you happy for me to merge this then?

davsclaus commented 9 years ago

+1 thanks alot for the speedy solution.