domain-story Pub Share

Diesel inventory

See Domain Modelling and Assets, Entities and Inventories.

Simple Classes

These classes were defined:

send::  msg diesel.nothing 

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)

Cleanup after testing

send::  msg diesel.db.memshared.log 

send::  msg diesel.db.col.log 

send::  msg diesel.db.memshared.clear 

Inventory and ordering example - creating and using objects

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:

  • registration is dynamic (you can change inventory based on variables), but it requires that command to be executed before the classes actually function as expected. You can do that in EnvironmentSettings
  • annotation is static, but it doesn't require anything else. It is also clear at all times where things go

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))

Ordering demo

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)

Finding objects

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")

XP syntax to navigate the data:

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


Was this useful?    

By: Razie | 2020-10-16 .. 2024-10-10 | Tags: story , dsl , sanity


Viewed 805 times ( | History | Print ) this page.

You need to log in to post a comment!

© Copyright DieselApps, 2012-2024, all rights reserved.