将具有嵌套对象的对象映射到Slick(2.1.0
)时出现问题。编译器错误是:
[error] Subscriber.scala:42: value ~ is not a member of scala.slick.lifted.Column[String]
[error] identityId ~
[error] ^
[error] Subscriber.scala:55: not found: value <>
[error] <> (
这是我的代码,知道什么是错的?为什么编译器不喜欢我的lambda?
import scala.slick.driver.PostgresDriver.simple._
case class Subscriber(
val identityId: IdentityId,
val firstName: String,
val lastName: String,
val fullName: String,
val email: Option[String],
val avatarUrl: Option[String],
val authMethod: AuthenticationMethod,
val oAuth1Info: Option[OAuth1Info],
val oAuth2Info: Option[OAuth2Info],
val passwordInfo: Option[PasswordInfo]
) extends Identity
/* Table mapping
*/
class SubscribersTable(tag: Tag) extends Table[Subscriber](tag, "trial_subscribers") {
def identityId = column[String]("identity_id", O.PrimaryKey)
def firstName = column[String]("first_name", O.NotNull)
def lastName = column[String]("last_name", O.NotNull)
def fullName = column[String]("full_name", O.NotNull)
def email = column[String]("email")
def avatarUrl = column[String]("avatar_url")
def authMethod = column[String]("auth_method")
def oAuth1Token = column[String]("oauth_1_token")
def oAuth1Secret = column[String]("oauth_1_secret")
def oAuth2AccessToken= column[String]("oauth_2_access_token")
def oAuth2TokenType = column[String]("oauth_2_token_type")
def oAuth2ExpiresIn = column[String]("oauth_2_expires_in")
def oAuth2RefreshToken = column[String]("oauth_2_refresh_token")
def passwordHasher = column[String]("password_hasher")
def password = column[String]("password")
def passwordSalt = column[String]("password_salt")
def * =
identityId ~
firstName ~
lastName ~
fullName ~
avatarUrl ~
authMethod ~
oAuth1Token ~
oAuth1Secret ~
oAuth2TokenType ~
oAuth2ExpiresIn ~
oAuth2RefreshToken ~
passwordHasher ~
password ~
passwordSalt
<> (
/* from a row to an object */
(
identityId,
firstName,
lastName,
fullName,
avatarUrl,
authMethod,
oAuth1Token,
oAuth1Secret,
oAuth2TokenType,
oAuth2ExpiresIn,
oAuth2RefreshToken,
passwordHasher,
password,
passwordSalt
) =>
Subscriber(
IdentityId(identityId.split("-")(0), identityId.split("-")(1)),
firstName,
lastName,
fullName,
email,
avatarUrl,
authMethod,
OAuth1Info(oAuth1Secret, oAuth1Token),
OAuth2Info(oAuth2AccessToken, oAuth2TokenType, oAuth2ExpiresIn, oAuth2RefreshToken),
PasswordInfo(passwordHasher, password, passwordSalt)
),
/* map object to a row */
(o: Subscriber) => Some((
o.identityId.userId+"-"+o.identityId.providerId,
o.firstName,
o.lastName,
o.fullName,
o.email,
o.avatarUrl,
o.authMethod.method,
o.oAuth1Info.map(_.token),
o.oAuth1Info.map(_.secret),
o.oAuth2Info.map(_.accessToken),
o.oAuth2Info.map(_.tokenType),
o.oAuth2Info.map(_.expiresIn),
o.oAuth2Info.map(_.refreshToken),
o.passwordInfo.map(_.passwordHasher),
o.passwordInfo.map(_.password),
o.passwordInfo.map(_.passwordSalt)
))
)
}
感谢您的帮助!
答案 0 :(得分:1)
在Slick 1.x中使用了此~
运算符。现在,预测由元组完成。所以你必须这样做:
def * = (identityId, firstName, ???) //and here rest of the mapping
您可以在此处阅读更多内容:http://slick.typesafe.com/doc/2.1.0/upgrade.html#table-descriptions