I'm implementing a Users table in Slick with a User class that extends SecureSocial's Identity trait. I'm having trouble converting from an optional not-storable-in-database type object to an optional primitive database type.
To refer to: Slick docs, SecureSocial docs (To generate API documentation for SecureSocial, pull from their Github, go into their "module-code" directory, and then run play doc
. Then look in the module-code/target/api folder and open up index.html)
What I have
Take this parameter in a User
case class:
oAuth1Info: Option[securesocial.core.OAuth1Info]
Where OAuth1Info's new instance constructor in the Scaladoc looks like so:
new OAuth1Info(token: String, secret: String)
Now in my *
method (as explained here) :
def * = stuffs ~ oAuth1InfoToken ~ oAuth1InfoToken ~ moreStuff <>
( // the following is the apply method
{ t => User(stuffs,
Some(OAuth1Info( (t._9).getOrElse(""), (t._10).getOrElse("")) ),
moreStuffs)
}, // the following is the unapply method
{
(r: User) => Some( (r.stuffs,
(r.oAuth1Info).getOrElse(None).token , // ERROR
(r.oAuth1Info).getOrElse(None).secret , // ERROR
r.moreStuffs) )
}
What I'm trying to do
Insert in None
to the database if oAuth1Info
wasn't provided and
Option[securesocial.core.OAuth1Info] = None
Otherwise, take the OAuth1Info
object and get the token and secret and store it to their respective columns in my database.
On top of this mapped projection being a 500+ character line, do I need to do some sort of
oAuth1Info match {
case None: None
case _: oAuth1Info.token
}
? Can a single-line pattern-matcher be possible? I am so lost in my code at this point...
Thanks for any help
If you'd like to see my full implementation so far...
Scala + Slick + SecureSocial = sadly tl;dr code
I know this code is a wall of text. Multiline Scala code would be awesome here if it exists? Pastebin