See Domain Modelling and Assets, Entities and Inventories.
These classes were defined:
expect:: (TestSimpleClass is class
)
expect:: (TestContainer is class
)
expect:: (TestEmptyBody is class
)
expect:: (TestAnnotated is class
)
expect:: (TestClass1 is class
)
expect:: (TestWithParms is class
)
val twp1:JSON[TestSubtypeClass]={}
expect:: ( (twp1 xNot TestWithParms)
)
expect:: (twp1 is TestSubtypeClass
)
expect:: (twp1 is TestClass1
)
send::
msg diesel.db.memshared.log
send::
msg diesel.db.memshared.clear
We can use the class annotation or register an inventory separately:
send::
msg diesel.inv.register (inventory="diesel.db.memshared"
, classNames ="DTInventory, DTProductUnit,DTP"
...)
Each approach has pros and cons:
When these objects are created, they are automatically sync'd to the inventory:
send:: msg (inventory
={products:[]}
, blog
={key:"blog1.munchies",content:"munchies are cool"}
, productSpec
={key:"munchies",sku:"munchieseh",descriptionRef:"blog1.munchies"}
)
We created an inventory, a blog and a product specification. Now let's add units to the inventory:
send:: msg (inventory[="products"]
=(inventory[="products"] + {key:"a-prod",qty:3,spec:"munchies"})
)
Let's Store them in the inventory:
send::
msg diesel.inv.upsert (entity)
send::
msg diesel.inv.upsert (entity)
send::
msg diesel.inv.upsert (entity)
Note: this would not work - when inserting multiple types of objects into an array, the array looses the typing information - it's just a quirk of them:
$ (x = [inventory, blog, productSpec] foreach entity => diesel.inv.upsert(entity))
We'll register the ordering demo classes to persisted inventory:
send::
msg diesel.inv.register (inventory="diesel.db.memshared"
, classNames ="DTCart,DTItem,DTOrder,DTCustom"
...)
Create a customer and put something in the cart:
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}]}
)
Create them in the inventory:
send::
msg diesel.inv.upsert (entity)
send::
msg diesel.inv.upsert (entity)
You can query objects directly in the inventory:
send::
msg diesel.inv.query (className="DTCart"
, query :JSON)
expect:: (payload[="data"][="0"=0][:String="key"] is "a-cart"
)
Or nicer, with the XP syntax:
val allCarts=DTCart
val foundCarts=DTCart[key == 'a-cart']
expect:: ( (sizeOf(allCarts) > 0)
)
expect:: ( (sizeOf(foundCarts) > 0)
)
expect:: (foundCarts[="0"=0][:String="key"] is "a-cart"
)
val foundCartKeys=(DTCart[key == 'a-cart'] map x=>x="key")
expect:: ( (sizeOf(foundCartKeys) > 0)
)
expect:: (foundCartKeys[="0"=0] is "a-cart"
)
// But here's a :
// $val cust = xp:DTCart[key == 'a-cart']/DTCustomer
You need to log in to post a comment!