relate
relate copied to clipboard
Support #$ query interpolation
https://github.com/lucidsoftware/relate/issues/20
Has this been benchmarked?
@matthew-lucidchart, we do need to fix relate-benchmarks.
They don't work out-of-the-box, and currently there are no instructions on getting them to work. And though there are a lot of tests, a lot of them are never run (e.g. we only ever parameterize with ints, nothing else).
I'm agreed that this (and all other changes) should be benchmarked.
Yeah, it's too bad we didn't keep up on them, but their primary purpose was to make sure we were headed down the right path from the start.
Simpler benchmarking can be done without that project.
On Fri, Mar 13, 2015 at 1:35 AM, Paul Draper [email protected] wrote:
@matthew-lucidchart https://github.com/matthew-lucidchart, we do need to fix relate-benchmarks.
They don't work out-of-the-box, and currently there are no instructions on getting them to work. And though there are a lot of tests, a lot of them are never run (e.g. we only ever parameterize with ints, nothing else).
I'm agreed that this (and all other changes) should be benchmarked.
— Reply to this email directly or view it on GitHub https://github.com/lucidsoftware/relate/pull/21#issuecomment-78849610.
Please let me know if anything else I need to get this merged?
Benchmarking them would go a long way in my view. Either via relate-benchmarks or your own make.
using #$ appears to be quite a bit faster than using .toSql.
The left is:
val s = "SELECT".toSql
val f = "FROM".toSql
val w = "WHERE".toSql
sql"$s * $f table $w 1 = 1"
The right is:
val s = "SELECT"
val f = "FROM"
val w = "WHERE"
sql"#$s * #$f table #$w 1 = 1"
what about:
sql"${"SELECT".toSQL} * ${"FROM".toSQL} ......
On Wed, Feb 3, 2016 at 2:44 PM, Gregg Hernandez [email protected] wrote:
using #$ appears to be quite a bit faster than using .toSql.
[image: interpolation] https://camo.githubusercontent.com/5919e91b40976c3df9e45e7993e98b5666248594/687474703a2f2f692e696d6775722e636f6d2f734c35525a6e392e706e67
The left is:
val s = "SELECT".toSql val f = "FROM".toSql val w = "WHERE".toSql sql"$s * $f table $w 1 = 1"
The right is:
val s = "SELECT" val f = "FROM" val w = "WHERE" sql"#$s * #$f table #$w 1 = 1"
— Reply to this email directly or view it on GitHub https://github.com/lucidsoftware/relate/pull/21#issuecomment-179485825.
what lucidchart said is the same as the original toSql benchmark.
We should probably have some unit tests on this that check to make sure the output is what we expect.
@rbanikaz If you're still interested in getting this merged, you'll need to update the PR (merge conflicts) and please include some unit tests as well.
I'm inclined to reject this, because it can encourage writing code that is vulnerable to SQL injection. That said, I think having better syntax for thing like table and column names would be a good thing.
I think the proper way to do this would be to escape the name as an identifier before interpolating it. So for example, in mysql the string "foo bar" would be interpolated as `foo bar`
.
Note that the escaping is different in different SQL implementations, and the quoting character needs to be escaped.