# How to define a composite data?
PREREQUISITE
Open the respective .kdata file.
For example to define Lottery data as a composite data type, open LotteryData.kdata file in eclipse.
Define the composite data using keyword
dataas follows:data Lottery( lotteryName:String, amount:Int, participantList:String*, // * denotes List data type i.e. List[String] in this case winner:String?, // ? denotes Option data type i.e. Option[String] in this case status:String )Note: Dont forget to save the file
enter sbt shell, run
compilecommand to access the data class (ex: Lottery.scala).
# Sample Usage:
val row = LotteryReadQuery().lotteryName.is("LOTTO-1").findOne.get
val lotteryData = new Lottery(
lotteryName = row.lotteryName,
amount = row.amount,
participantList = row.participantList.map(_.name),
status = if (row.open) "OPEN" else "CLOSED",
winner = row.winner
)