2012-01-04 7 views
1

FirstExampleは、次の構文で挿入したバッチの例を提供します。scalaquery:<a href="https://github.com/szeiger/scalaquery-examples" rel="nofollow">scalaquery-examples project</a> でダイナミックBatchInsert

それは、このためにことを考えるとInsertAll方法でタプルの動的に構築リストを渡すことができますどのように
Coffees.insertAll(
    ("Colombian", 101, 7.99, 0, 0), 
    ("French_Roast",49, 8.99, 0, 0), 
    ("Espresso",150, 9.99, 0, 0), 
    ("Colombian_Decaf",101, 8.99, 0, 0), 
    ("French_Roast_Decaf", 49, 9.99, 0, 0) 
) 

例えば、関数の定義は次のとおりです。

def insertAll(values: (String, Int, Double, Int, Int)*)(implicit session: org.scalaquery.session.Session): Option[Int] 

答えて

3

あなたはこのような可変長引数にリストを変換することができます:

insertAll(tuplesList.toSeq:_*) 
+0

Cool Thks!魅力のように動作します – krishnen

+0

+1実際には、ケースクラスインスタンスのリストでもうまく動作します;-) – virtualeyes

関連する問題