में enum मूल्य लागू करने के लिए कैसे:मैं पालन enum है चालाक
object LoginStatus extends Enumeration() with BitmaskedEnumeration {
type LoginStatus = Value
val Active = Value("A")
val Inactive = Value("I")
}
मैं 'ए' enum का मूल्य लागू करने के लिए की जरूरत है, लेकिन जब एसक्यूएल उत्पन्न होता है परिणाम 0. यह है है टेबल मैपिंग:
object LoginTable extends Table[Login]("login") {
def idLogin = column[Int]("idlogin", O.PrimaryKey, O.AutoInc)
def cdLogin = column[String]("cdlogin", O.NotNull)
def cdPass = column[String]("cdPass", O.NotNull)
def stLogin = column[LoginStatus]("stlogin", O.NotNull, O.DBType("character(1)"))
}
एनम मूल्य को कैसे जारी रखें?
मैं
implicit val charMapper = MappedTypeMapper.base[Char, String](
b => b.toString(),
i => i.charAt(0))
implicit def enum2StringMapper(enum: Enumeration) = MappedTypeMapper.base[enum.Value, Char](
b => b.toString.charAt(0),
i => enum.withName(i.toString))
implicit val LoginStatusMapper = enum2StringMapper(LoginStatus)
लागू किया लेकिन परिणाम में:
implicit val LoginStatusTypeMapper = MappedTypeMapper.base[LoginStatus.Value, Int]( // conversion from LoginStatus to int { status => status.id }, // conversion back from int to enum { id => LoginStatus(id) } )
तो आप के रूप में अपने स्तंभ को संदर्भित करने की जरूरत है:
[error] c.Login - Invalid value for type int : A
यह कुछ हद तक संबंधित है http://stackoverflow.com/questions/19030875/how-can-i-create-a-custom-column-type-with-typesafe-slick-in-scala/19040124#19040124 – cvogt
यह स्लिम मेलिंग सूची https://groups.google.com/d/msg/scalaquery/Cd5iG-tJchM/fEIhq8IPVJQJ – cvogt
पर भी चर्चा की गई है http://stackoverflow.com/questions/18752929/how-to-use से संबंधित -enums-in-scala-slick – cvogt