# How to define embedded properties inside collection?
First define the embedded object inside the collection using the keyword
embedded& then define the embedded as aproperty. For example:collection Employee { embedded Address { property line1:String property line2:String? property city:String property state:String } property name:String property designation:String property address:Address }enter sbt shell, run command
compile
# Sample Usage:
//Create
def addEmployee(): Unit = {
val address = AddressEmbedded( line1 = "No 123, 4th Street",
city = "Bangalore", state = "Karnataka")
val empRow = EmployeeRow(
name = "Vivitsa", designation = "HR",
address = address)
EmployeeWriter().insert(empRow)
}
//Read
def getResidentCity(employeeId:Id):String = {
val empRow = EmployeeQuery.findById(employeeId).get
empRow.address.city
}
//Query
def getAllEmployeesInCity(city: String): List[EmployeeRow] = {
val embeddedQry = AddressQuery().city.is(city)
val employeesInCity = EmployeeQuery().address.matches(embeddedQry).find
employeesInCity
}
//Update
def updateEmployeeCity(): Unit = {
val embeddedQry = AddressQuery().city.is("Bangalore")
val embeddedUpd = AddressUpdate().city.set("Bengaluru")
val q = EmployeeQuery().address.matches(embeddedQry)
val u = EmployeeUpdate().address.update(embeddedUpd)
EmployeeWriter().updateMulti(q, u)
}
REFERENCES