| key, |
| sku, |
| descriptionRef:<>DTBlogPost, |
| key, |
| sku, |
| descriptionRef:<>DTBlogPost |
send::
msg diesel.inv.register (inventory="diesel.db.inmem", classNames ="DTInventory, DTProductUnit,DTP"...)
send:: msg (inventory={products:[]}, blog={key:"blog1.munchies",content:"munchies are cool"}, productSpec={key:"munchies",sku:"munchieseh",descriptionRef:"blog1.munchies"})
send:: msg (inventory[="products"]=(inventory[="products"] + {key:"a-prod",qty:3,spec:"munchies"}))
send:: msg (x=([inventory,blog,productSpec] foreach entity=>diesel.inv.upsert(entity)()))
| key, |
| customerRef:<>DTCustomer, |
| items:Array[DTItem], |
| key, |
| customerRef:<>DTCustomer, |
| items:Array[DTItem] |
| key, |
| customerRef:<>DTCustomer, |
| items:Array[DTItem], |
| key, |
| customerRef:<>DTCustomer, |
| items:Array[DTItem] |
send::
msg diesel.inv.register (inventory="diesel.db.mongo", classNames ="DTCart,DTItem,DTOrder,DTCustom"...)
send:: msg (customer={key:"123",name:"Jane Doe",address:"123 Phantom Town"}, cart={key:"a-cart",customerRef:"123",items:[{key:"123",productRef:"munchies",qty:2}]})
send:: msg (x=([customer,cart] foreach entity=>diesel.inv.upsert(entity)()))
// ## Inventory test
// ### Domain
// Make sure your classes include a key attribute, unique. Otherwise, one random key is assigned for you and all sorts of funny and entertaining side effects may occur...
// NOTE that these classes below won't work with persistence until you run this story - which will register and connect the postgress.
// First class is annotated for persistance, although annotations are static and we prefer the registration, see below:
// $class TestStudent(
// key,
// age,
// courseRef:<>TestCourse,
// grades:TestGrade*
// )
// This classes are registered, see the register message below - this is the preferred approach, as it's more dynamic:
// $class TestCourse(
// key
// )
// $class TestGrade(
// courseRef:<>TestCourse,
// grade
// )
// $send diesel.inv.register(inventory="diesel.db.inmem", classNames="TestCourse,TestGrade")
// We need to establish the default connection for the inventory:
// $send diesel.inv.connect(inventory="diesel.db.postgres", env=diesel.env, connection="", super="diesel")
// Now we're setup. We can begin playing with these entities...
// $val cs = new TestCourse {key: "CS"}
// $val jay = new TestStudent {
// key: "Jay",
// age: 33,
// courseRef: "CS",
// grades: [new TestGrade{courseRef: "CS", grade:7}]
// }
// $val mary = new TestStudent {
// key: "Mary",
// age: 33,
// courseRef: "CS",
// grades: [new TestGrade {courseRef: "CS", grade: 6}]
// }
// $ diesel.inv.upsert (entity=cs)
// $ diesel.inv.upsert (entity=jay)
// $ diesel.inv.upsert (entity=mary)
// $ diesel.inv.listAll(className="TestCourse")
// $expect (payload.total is 1)
// $ diesel.inv.listAll(className="TestStudent")
// $expect (payload.total is 2)
// ## Test delete with query:
// Delete all students taking CS - who needs them anyhow
// $send diesel.db.postgres.remove (collection="TestStudent", courseRef="CS")
// $ diesel.inv.listAll(className="TestStudent")
// $expect (payload.total is 0)
You need to log in to post a comment!