Created
February 11, 2017 23:17
-
-
Save d6y/054ae67a3169499b30a24ae60f02f38d to your computer and use it in GitHub Desktop.
Enum example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import slick.driver.H2Driver.api._ | |
import java.sql.Timestamp | |
import java.util.Date | |
object Gender extends Enumeration { | |
type Gender = Value | |
val MALE = Value("MALE") | |
val FEMALE = Value("FEMALE") | |
} | |
import Gender._ | |
object CustomColumnTypes { | |
implicit val utilDateTimeType = | |
MappedColumnType.base[Date, Timestamp]( | |
d => new Timestamp(d.getTime), | |
ts => new Date(ts.getTime) | |
) | |
implicit val genderType = | |
MappedColumnType.base[Gender, String](_.toString, Gender.withName(_)) | |
} | |
final case class Contact(name: String, dob: Date, gender: Gender) | |
final class ContactTable(tag: Tag) extends Table[Contact](tag, "contacts") { | |
import CustomColumnTypes._ | |
def name = column[String]("name", O.PrimaryKey) | |
def dob = column[Date]("dob") | |
def gender = column[Gender]("gender") | |
def * = (name, dob, gender) <> (Contact.tupled, Contact.unapply) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment