Slick DBIO 序列编译失败
Slick DBIO sequence failing to compile
我正在尝试在数据库中保存模型 ProductCategory
对象。保存的时候,categoriesId
是一个Seq
。
case class ProductCategory(productItemId: ProductItemId, categoryies: CategoryId, filterName: FilterName)
/*Inside another object starts*/
def saveCategoriesId(productItemId: ProductItemId, categoryId: Seq[CategoryId], filterName: FilterName):
Future[Seq[ProductItemId]] =
db.run({
DBIO.sequence(categoryId.map(id => save(ProductCategory(productItemId, id, filterName))))
})
def save(productCategory: ProductCategory): DBIO[ProductItemId] =
query returning query.map(_.productItemId) += productCategory
出现以下错误:
[error] /Users/vish/Work/jd/app/service/ProductCategoryService.scala:20:35: type mismatch;
[error] found : Seq[slick.dbio.DBIOAction[models.ProductItemId,slick.dbio.NoStream,Nothing]]
[error] required: Seq[slick.dbio.DBIOAction[models.ProductItemId,slick.dbio.NoStream,E]]
[error] DBIO.sequence(categoryId.map(id => save(ProductCategory(productItemId, id, filterName))))
Playframework 版本为 2.6。这个问题不是的重复问题。这个问题阻碍了进一步的发展。回答时请评论它是否正确的保存方式 categoriesId
通常在 Scala 中编译错误 found: Nothing, required: E
表示编译器无法推断某些类型。尝试手动指定一些类型参数
db.run({
DBIO.sequence[ProductItemId, Seq, All](categoryId.map(id => save(ProductCategory(productItemId, id, filterName))))
})
或
db.run({
DBIO.sequence(categoryId.map[DBIO[ProductItemId], Seq[DBIO[ProductItemId]]](id => save(ProductCategory(productItemId, id, filterName))))
})
或者引入一个局部变量(这样编译器就可以自己推断类型了)
val actions = categoryId.map(id => save(ProductCategory(productItemId, id, filterName)))
db.run({
DBIO.sequence(actions)
})
我正在尝试在数据库中保存模型 ProductCategory
对象。保存的时候,categoriesId
是一个Seq
。
case class ProductCategory(productItemId: ProductItemId, categoryies: CategoryId, filterName: FilterName)
/*Inside another object starts*/
def saveCategoriesId(productItemId: ProductItemId, categoryId: Seq[CategoryId], filterName: FilterName):
Future[Seq[ProductItemId]] =
db.run({
DBIO.sequence(categoryId.map(id => save(ProductCategory(productItemId, id, filterName))))
})
def save(productCategory: ProductCategory): DBIO[ProductItemId] =
query returning query.map(_.productItemId) += productCategory
出现以下错误:
[error] /Users/vish/Work/jd/app/service/ProductCategoryService.scala:20:35: type mismatch;
[error] found : Seq[slick.dbio.DBIOAction[models.ProductItemId,slick.dbio.NoStream,Nothing]]
[error] required: Seq[slick.dbio.DBIOAction[models.ProductItemId,slick.dbio.NoStream,E]]
[error] DBIO.sequence(categoryId.map(id => save(ProductCategory(productItemId, id, filterName))))
Playframework 版本为 2.6。这个问题不是categoriesId
通常在 Scala 中编译错误 found: Nothing, required: E
表示编译器无法推断某些类型。尝试手动指定一些类型参数
db.run({
DBIO.sequence[ProductItemId, Seq, All](categoryId.map(id => save(ProductCategory(productItemId, id, filterName))))
})
或
db.run({
DBIO.sequence(categoryId.map[DBIO[ProductItemId], Seq[DBIO[ProductItemId]]](id => save(ProductCategory(productItemId, id, filterName))))
})
或者引入一个局部变量(这样编译器就可以自己推断类型了)
val actions = categoryId.map(id => save(ProductCategory(productItemId, id, filterName)))
db.run({
DBIO.sequence(actions)
})