从 scalaquery 到 Slick 3.1 - .list 已删除?
From scalaquery to Slick 3.1 - .list removed?
我正在尝试从 scalaquery 迁移到 slick 3,但在编译时出现以下错误:
Error:(107, 19) No matching Shape found.
Slick does not know how to map the given types.
Possible causes: T in Table[T] does not match your * projection. Or you use an unsupported type in a Query (e.g. scala List).
Required level: slick.lifted.FlatShapeLevel
Source type: slick.lifted.ProvenShape[TestData]
Unpacked type: T
Packed type: G
(for (test <- testTable)
^
这是改动前的相关代码:
case class TestData(id: Int, test_double: Double)
object TestTable extends Table[TestData]("Test_Table") {
var test_value = ""
def id = column[Int]("ID_Test", O.PrimaryKey, O.AutoInc)
def nep_column = column[Double](test_value)
def * = id ~ nep_column <> (TestData, TestData.unapply _)
}
def get_data = {
db withSession {
for (test <- testTable)
yield test.*
}.list
}
这是我修改后的:
case class TestData(id: Int, test_double: Double)
class TestTable(tag: Tag) extends Table[TestData](tag, "Test_Table") {
def id = column[Int]("ID_Test", O.PrimaryKey, O.AutoInc)
def nep_column = column[Double](test_value)
def * = (id, nep_column) <> ((TestData.apply _).tupled, TestData.unapply)
}
object testTable extends TableQuery(new TestTable(_)) {
var test_value = ""
}
def get_data = {
Await.result(db.run(
(for (test <- testTable)
yield test.*).result), Duration.Inf)
}
因此,简单地将 .list
替换为 .result
似乎不起作用。我再也找不到 Slick 3 中对 .list
的任何引用。被移除了吗?
有谁知道我这里有什么问题以及如何解决?
你根本不需要使用 for comprehension:
def get_data: Seq[TestData] = Await.result(db.run(testTable.result), Duration.Inf)
我正在尝试从 scalaquery 迁移到 slick 3,但在编译时出现以下错误:
Error:(107, 19) No matching Shape found.
Slick does not know how to map the given types.
Possible causes: T in Table[T] does not match your * projection. Or you use an unsupported type in a Query (e.g. scala List).
Required level: slick.lifted.FlatShapeLevel
Source type: slick.lifted.ProvenShape[TestData]
Unpacked type: T
Packed type: G
(for (test <- testTable)
^
这是改动前的相关代码:
case class TestData(id: Int, test_double: Double)
object TestTable extends Table[TestData]("Test_Table") {
var test_value = ""
def id = column[Int]("ID_Test", O.PrimaryKey, O.AutoInc)
def nep_column = column[Double](test_value)
def * = id ~ nep_column <> (TestData, TestData.unapply _)
}
def get_data = {
db withSession {
for (test <- testTable)
yield test.*
}.list
}
这是我修改后的:
case class TestData(id: Int, test_double: Double)
class TestTable(tag: Tag) extends Table[TestData](tag, "Test_Table") {
def id = column[Int]("ID_Test", O.PrimaryKey, O.AutoInc)
def nep_column = column[Double](test_value)
def * = (id, nep_column) <> ((TestData.apply _).tupled, TestData.unapply)
}
object testTable extends TableQuery(new TestTable(_)) {
var test_value = ""
}
def get_data = {
Await.result(db.run(
(for (test <- testTable)
yield test.*).result), Duration.Inf)
}
因此,简单地将 .list
替换为 .result
似乎不起作用。我再也找不到 Slick 3 中对 .list
的任何引用。被移除了吗?
有谁知道我这里有什么问题以及如何解决?
你根本不需要使用 for comprehension:
def get_data: Seq[TestData] = Await.result(db.run(testTable.result), Duration.Inf)