I have a structure like this
src
└── main
├── resources
│ └── inserts.sql
└── my.package
└── Main.scala
In Main.scala
I want to take the file inserts.sql
and use Slick 3.0.0 to execute it on my db.
Looks like there is no way to execute a sql file with Slick other then loading it into memory as a String and executing it with sql
, sqlu
or tsql
.
Beware that in this case the $
interpolation is meant to insert bind variables into the query. To splice literal values into the query you must use #$
instead. Since in this case the variable is the whole query, we have to do
val inserts_sql = Source.fromResource("inserts.sql").mkString
db.run(sqlu"#$query")