abstract class AbstractDBService[Mixin, RTable <: Table[_ <: AbstractRecord[Mixin]] with AbstractTable[AbstractRecord[Mixin]], NewTable <: Table[_ <: AbstractRecord[Mixin]] with AbstractNewTable[AbstractNewRecord[Mixin]]](override protected val dbConfigProvider: DatabaseConfigProvider)(implicit executionContext: ExecutionContext)
extends AbstractBaseDBService[Mixin, RTable, NewTable](dbConfigProvider) {
def create(newRecord: NewTable#TableElementType): Future[Option[RTable#TableElementType]] = db.run(
((newRecords returning records) += newRecord).asTry map {
case Success(record) => Some(record)
case Failure(_) => None
}
)
def update(record: RTable#TableElementType): Future[Int] = db.run(
records.filter(_.id === record.id).update(record)
)
}
我正在尝试使用scala和slick使通用数据库服务正常工作。上面给了我以下类型错误。
type mismatch;
found : newRecord.type (with underlying type _$2)
required: _$2
((newRecords returning newRecords) += newRecord).asTry
和
type mismatch;
found : _$1
required: RTable#TableElementType
(which expands to) _$1
records.filter(_.id === record.id).update(record)
如您所见,类型实际上是一致的,所以我不确定是什么导致了此错误。
以下内容是在超类中定义的
protected val records: TableQuery[RTable]
protected val newRecords: TableQuery[NewTable]
任何帮助将不胜感激