除了编写大量样板文件之外,我不知道如何克服这个“找不到匹配的形状”错误。
要点中说明的基本思想是,我有一个非常基本的方法版本(有效,但非常具体),然后是一个采用mapper
参数并且更通用(也可以工作,但特定于一种特定类型),然后是第三个版本,它采用类型参数并且非常有用,但由于此错误而无法编译。
基本方法:
def updatePD_FirstNames(id: ids.PersonalDetailsId, firstNames: StringLtd30): Future[Int] = {
更好的方法:
def updatePD_SL(id: ids.PersonalDetailsId, mapper: tables.PersonalDetails => tables.profile.api.Rep[StringLtd30], sl: StringLtd30): Future[Int] = {
理想的方法(但不能编译):
def updatePD_X[X](id: ids.PersonalDetailsId, mapper: tables.PersonalDetails => tables.profile.api.Rep[X], sl: X): Future[Int] = {
```
[server] $ compile
[info] Compiling 1 Scala source to ... target\scala-2.12\classes...
[error] ...schema\DbProxy.scala:688: No matching Shape found.
[error] Slick does not know how to map the given types.
[error] Possible causes: T in Table[T] does not match your * projection,
[error] you use an unsupported type in a Query (e.g. scala List),
[error] or you forgot to import a driver api into scope.
[error] Required level: slick.lifted.FlatShapeLevel
[error] Source type: slick.lifted.Rep[X]
[error] Unpacked type: T
[error] Packed type: G
[error] val q2: Query[tables.profile.api.Rep[X], X, Seq] = q1.map(mapper)
[error] ^
[error] one error found
[error] (server/compile:compileIncremental) Compilation failed
[error] Total time: 4 s, completed 23-Mar-2017 11:15:47
```
完整代码位于https://gist.github.com/aholland/0845bf29d836d672d006ab58f5f1c73c https://gist.github.com/aholland/0845bf29d836d672d006ab58f5f1c73c