I'm beginning with Slick (and Scala) on playframework. My project is structured with .scala files who contains all classes and objects for a domain concept.
package models
class Folder(val id: Option[Long], var name: String, val childrens:Set)
object Folder{
val folders = new db.Folders
def get(id: Long)(implicit s: Session): Option[Folder] = {
Query(users).where(_.id === id).firstOption.map { r: db.Row =>
new Folder(r.id, r.name, Set.empty]) // TODO load childrens for folder
}
}
}
// Attempt to segregate and maybe restrict the persistence code
package db {
case class Row(id: Option[Long], name: String)
class Folders extends Table[Row]("folders") {
def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
def name = column[String]("name", O.NotNull)
def * = id.? ~ name <> (map _, unmap _)
// ...
}
}
Is there some Scala constructs who can restrict the inner package visibility to the Folder
object only ?
Thanks
Some options:
object
inside of the Folder companion object, trait
, make the members protected and mix that into the Folder companion objectprivate[folder-package]
).