Created
June 15, 2017 22:45
-
-
Save leifwickland/6a13bea7baa5d85a6a4c872b8fdcbd20 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object QueryUtil { | |
/** | |
* Generates an SQL comment that indicates where in Scala source the query originated. | |
*/ | |
def locationFragment(implicit file: sourcecode.File, line: sourcecode.Line): Fragment = { | |
Fragment.const(s"/* Query from ${file.value}:${line.value} */\n") | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object SomeDao { | |
def getSomeData = QueryUtil.locationFragment ++ fr"SELECT foo FROM BAR".query[Foo].list | |
} | |
// Generates a query that looks like: | |
// /* Query from usage.scala:2 */ | |
// SELECT foo FROM BAR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Neato! So, doobie already does some of this work with its
Pos
data type (which uses Haoyi's lib), and fragments already track their locations, so you should pass this information along and then the query checker can use it.