使用更新时,Slick 3.0.0警告

时间:2015-11-04 15:39:05

标签: scala slick

我有一个简单的更新,尝试更新特定行的两列。以下是我的工作:(我使用的是Scala 2.11.7)

val update =
  (id: Long, state: MyState) =>
    myTable.filter(_.id === id)
      .map(tbl =>(tbl.name, tbl.updateDate))
      .update(state.name, DateTime.now(DateTimeZone.UTC))

以下是我的编译器告诉我的内容:

[warn] /Users/joe/vpp-projects/app/my/project/services/database/MySchema.scala:40: Adapting argument list by creating a 2-tuple: this may not be what you want.
[warn]         signature: UpdateActionExtensionMethodsImpl.update(value: T): JdbcActionComponent.this.DriverAction[Int,slick.dbio.NoStream,slick.dbio.Effect.Write]
[warn]   given arguments: state.name, DateTime.now(DateTimeZone.UTC)
[warn]  after adaptation: UpdateActionExtensionMethodsImpl.update((state.name, DateTime.now(DateTimeZone.UTC)): (String, org.joda.time.DateTime))
[warn]           .update(state.name, DateTime.now(DateTimeZone.UTC))
[warn]          

    ^

有关这里发生的事情的任何线索?我没有得到警告对我有用,所以我可以摆脱它!

1 个答案:

答案 0 :(得分:3)

update需要Tuple - 如果没有采用多个参数的方法,scala有一个功能可以将带有多个参数的方法调用转换为元组:

def anExample(value: (Int, Int, String)): Int = value._3.length

// This is how it is properly called
anExample((1, 2, "hi"))

// But this also works
anExample(1, 2, "hi")

你可以:

  • 更新通话

    // Note the added tuple parenthesis
    .update((state.name, DateTime.now(DateTimeZone.UTC)))
    
  • -Yno-adapted-args添加到scalacOptions以完全删除警告:

    // If using SBT
    scalacOptions in Compile += "-Yno-adapted-args"