2

This code:

def insAll(values: MyRdt*) {
  Db.withTransaction(session => { // Db is an org.scalaquery.session.Database instance
    MyTable.insertAll(values: _*)(session)
  })
}

doesn't compile. The error is

... missing parameter type
[error]     Db.withTransaction(session => {
                               ^

Any ideas why?

It compiles ok if I access a pre-defined Query instead of MyTable.insertAll(values: _*).

Curiously, if I split it up into 2 functions like

def insAllS(values: MyRdt*)(session: Session) {
  MyTable.insertAll(values: _*)(session)
}

def insAll(values: MyRdt*) {
  Db.withTransaction(session => {
    insAllS(values: _*)(session)
  })
}

it compiles without errors.

PS: MyRdt is a type alias for a table record tuple.

Ivan
  • 63,011
  • 101
  • 250
  • 382

2 Answers2

1

On way is the less typesafe (runtime) session handler; if you have in scope threadLocalSession, then the following should work:

import org.scalaquery.session.Database.threadLocalSession

def insAll(values: MyRdt*) {
  Db.withTransaction { implicit ss: session =>
    MyTable.insertAll(values: _*)
  }
}

However, as far as answering your question re: compile time session handler, assume you have tried specifying that the type passed into the block is Session:

import org.scalaquery.session._

def insertAll(values: MyRdt*) {
  Db.withTransaction { ss: Session =>
    Foo.insertAll(values: _*)(ss)
  }
}
virtualeyes
  • 11,147
  • 6
  • 56
  • 91
1

Overloading is to blame. Signatures similar to withTransaction method:

scala> def om[T](f: Int => T): T = f(0)
om: [T](f: (Int) => T)T

scala> def om[T](f: => T): T = f
om: [T](f: => T)T

scala> om(x => 'x)
<console>:80: error: missing parameter type
  om(x => 'x)
  ^

scala> def m[T](f: Int => T): T = f(0)
m: [T](f: (Int) => T)T

scala> m(x => 'x)
res46: Symbol = 'x
elbowich
  • 1,941
  • 1
  • 13
  • 12