I used a code, generated from slick code generator.
My table has more than 22 columns, hence it uses HList
It generates 1 type and 1 function:
type AccountRow def AccountRow(uuid: java.util.UUID, providerid: String, email: Option[String], ...):AccountRow
How do I write compiled insert code from generated code?
I tried this:
val insertAccountQueryCompiled = { def q(uuid:Rep[UUID], providerId:Rep[String], email:Rep[Option[String]], ...) = Account += AccountRow(uuid, providerId, email, ...) Compiled(q _) }
I need to convert Rep[T]
to T
for AccountRow function to work. How do I do that?
Thank you
;TLDR; Not possible
Explanation
There are two levels of abstraction in Slick: Query
s and DBIOAction
s.
When you're dealing with Query
s, you have to access your schema definitions, and rows, Rep
s and, basically, it's very constrained as it's the closest level of abstraction to the actual DB you're using. A Rep
refers to an hypothetical value in the database, not in your program.
Then you have DBIOActions, which are the next level... not just some definition of a query, but the execution of it. You usually get DBIOAction
s when getting information out of a query, like with the result
method or (TADAN!) when inserting rows.
Insert
s and Update
s are not queries and so what you're trying to do is not possible. You're dealing with DBIOAction (the +=
method), and Query
stuff (the Rep
types). The only way to get a Rep inside a DBIOAction is by executing a Query and obtaining a DBIOAction and then composing both Actions using flatMap
or for comprehensions (which is the same).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With