Option Authentication. , :
`email` varchar(255) NOT NULL,
`encrypted_password` varchar(255) NULL,
`user_id` int(11) NOT NULL,
`token` varchar(255) NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NULL
:
case class Authentication(email: String, password: Option[String], userId: Int, token: Option[String], createdAt: Date, updatedAt: Option[Date])
:
val authentication_parser = {
get[String]("email") ~
get[Option[String]]("encrypted_password") ~
get[String]("user_id") ~
get[Option[String]]("token") ~
get[Date]("created_at") ~
get[Option[Date]]("updated_at") map {
case email~encrypted_password~user_id~token~created_at~updated_at =>
Authentication(email, encrypted_password, user_id, token, created_at, updated_at)
}
}
- Option Authentication, getOrElse ( ):
case email~encrypted_password~user_id~token~created_at~updated_at =>
Authentication(email, encrypted_password.getOrElse(""), user_id, token.getOrElse(""), created_at, updated_at.getOrElse(new Date())
:
val authentication_parser = {
get[String]("email") ~
get[String]("user_id") ~
get[Option[String]]("token") ~
get[Date]("created_at") ~
get[Option[Date]]("updated_at") map {
case email~user_id~token~created_at~updated_at =>
Authentication(email, None, user_id, token, created_at, updated_at)
}
}
.as(). SQL("....").on(...).as(authentication_parser *) List[Authentication]. LIMIT 1 , authentication_parser.single ( Authentication) authentication_parser.singleOpt ( Option[Authentication]). singleOpt - , single , .
, - , Any. ( ) .