p
molecule
package molecule
Type Members
-
abstract
class
DomainStructure extends AnyRef
Domain structure definition
Domain structure definition
Define a Domain structure to be handled by Molecule in an object that extends this
Domainclass.A domain structure consists of traits describing real world entities. Each entity/trait is given a name and defines a list of attributes that are the relevant properties of the entity.
A
maxAritynumber is applied toDomainto tell Molecule how many Attributes it should create boilerplate code for, or how many attribute values are expected at most to be returned from molecule queries. This is to generate a minimum of boilerplate code.package path.to.your.project import molecule.Domain object Community extends Domain(8) { // "Community" domain trait Person { // "Person" entity val name = oneString // Person "name" String attribute definition val age = oneInt // Person "age" Int attribute definition } // Additional entities... }
For larger projects, it is recommended to organize the domain structure in segments of related entity traits within objects:
object Seattle extends Domain(15) { object customer { // "customer" segment trait Person { val name = oneString val age = oneInt val address = one[Address] // Cardinality-one relationship to Address val bought = many[products.Item] // Cardinality-many relationship to products.Item } trait Address { val street = oneString.fulltext val city = oneInt } // ..more entities in the `customer` segment } object products { // "products" segment trait Item { val title = oneString val inStock = oneInt } // ..more entities in the `products` segment } // Additional segments... }