In Slick 3, how does one SQL compilation of inserts using the associated case class?

To compile a query SQL, you need to compile a function that accepts a arg: typeraised type parameter for each query parameter Rep[type].

I have a class JobRecordand TableQuery jobRecords.

So, to insert an instance of the JobRecord case class, I need to say something like:

val qMapToId = (jobRecords returning jobRecords.map(_.id))
def ucCreate(jobRecord: Rep[JobRecord]) = qMapToId += jobRecord
val cCreate = Compiled(ucCreate _)

But of course, this does not compile, because + = does not accept Rep, and I'm not sure if Rep [JobRecord] is also valid.

I tried many things that are not worth showing, including mixing in the guide to monomorphic case classes . I probably stepped back from the solution several times. A pointer to a working example would be great!

+5
2

, val qMapToId = (jobRecords returning jobRecords.map(_.id)) (.. ).

Compiled Parameters API , ( ) , . insert , +=.

+3

TableQuery [] .

# define TableQuery of JobRecord
case class JobRecordRow(...)
class JobRecord(tag:Tag) extends Table[JobRecordRow](tag, "JOB_TABLE_NAME") {
}
# define compiled query
val insert = Compiled( TableQuery[JobRecord].filter(_ => true:Rep[Boolean]))
val stmt = (insert += JobRecordRow(...))
db.run( stmt)

. , Compiled(TableQuery[JobRecord]) , . filter(), .

2019-07-21

filter() map(identity) map(identity).

TableQuery[JobRecord].map(identity)
0

All Articles