-
Notifications
You must be signed in to change notification settings - Fork 215
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
Allow ?
for parameters
#1987
Comments
Thanks for the issue @linux-china . Are there any docs on the use of My initial hypothesis is that we should use one thing in PRQL and then the integrations can do the translation — for example if we decide to use (And if you have any feedback on #1929, I'm sure it will be well-received. I notice you already made an addition to the existing code to throw an error in Java rather than panic; that sort of thing might be useful advice in #1929 too) |
Javadoc for PreparedStatement: https://docs.oracle.com/javase/8/docs/api/java/sql/PreparedStatement.html JDBC spec only supports positional parameter with placeholder String sqlQuery = "INSERT INTO student VALUES(:id, :name, :department)"; Mono.from(connectionFactory.create())
.flatMapMany(connection -> connection
.createStatement("SELECT firstname FROM PERSON WHERE age > $age")
.bind("$age", 42)
.execute()) @PRQL("from user|filter id == ${id}")
User findUserById(Integer id); or you can wrapper JdbcTemplate to PrqlTemplate:
My option: |
But if some Java frameworks/libraries use named parameters, they must be translated to positional parameters before they hit the database. Because I know for a fact, that Postgres does not support named parameters. Could these frameworks/libraries translate named to positional before we compile PRQL to SQL? This way PRQL as a language does not need to support many ways to do the same thing. |
I'm not sure. A easy solution now is to wrap up these frameworks/libraries to accept PRQL, then compile PRQL to SQL, and finally call delegated APIs that accept SQL. With this way, you just need to replace named PRQL parameter from The following API is to wrap up Spring NamedParameterJdbcTemplate with PRQL support. @Test
public void testParameters() throws Exception {
prqlTemplate.query("from test2 | filter id == ${id}", Collections.singletonMap("id", 1), rs -> {
System.out.println(rs.getString("name"));
});
} To wrap up Spring JdbcTemplate, and it's easy, and now I can use PRQL directly to query database by wrapping up Spring JdbcTemplate. |
Good point @linux-china. I was thinking to add a Java parser which can address issue like this. Anyway, I think it's probably better to add an compile option in PRQL lib to recognize parameters based on given pattern. |
Wow @linux-china this is great! Are you using just the plain library from main branch or the PR for JDBC? But regarding using Take this example:
In the first In the second select, Sidenote: #1957 adds support for params of form It seems that the only way to make JDBC and other frameworks / libraries work correctly, would be to compile PRQL to SQL after |
See #1479 for how to work around this with s-strings. |
Just noticed prql-jdbc driver from #1929 and it's really useful. Just send PRQL over prql-jdbc and prql-jdbc will transpile PRQL to SQL transparently and fetch data from database.
A question here, Java JDBC/R2DBC use
?
as placeholder for parameters, and now PRQL uses$1
,$2
as parameters, and maybe Allow braces for parameters, but?
as parameter placeholder still very important because it's a standard in JDBC.An example for prql-jdbc:
With prql-jdbc and
?
as parameter placeholder, and I think most Java JDBC frameworks/libraries can use PRQL directly:The text was updated successfully, but these errors were encountered: