diesel-inv-story Pub Share

Diesel inventory, domain and assets

See Domain Modelling and Assets, Entities and Inventories.

diesel.db.col

Register and connect

send::  msg diesel.inv.register  (inventory="diesel.db.col", classNames ="TestClassInv1,TestClassInv2"...)

send::  msg diesel.inv.connect  (inventory="diesel.db.col", env, connection)

expect::  (payload contains "ok")
send::  msg diesel.inv.testConnection  (inventory="diesel.db.col", connection)

expect::  (payload contains "ok")

CRUD

Some objects...

val tc21:JSON[TestClassInv2]={ "someValue": "something 2", "key": "tc21" } val tc100:JSON[TestClassInv1]={ "someValue": "something", "ref2": "tc21", "key": "tc100" } val tc11:JSON[TestClassInv1]={ "someValue": "something", "ref2": "tc21", "key": "tc11" } val tc12:JSON[TestClassInv1]={ "assetRef": {"key": "tc12"}, "someValue": "something" }

0 $mock:: a.b
   . (x=[tc21,tc11,tc12])

send::  msg a.b 

send::  msg ctx.echo  (x)

Upsert - creating entities in the inventory

Specify class, untyped object send::  msg diesel.inv.upsert  (className="TestClassInv1", entity :JSON)

expect::  (payload[="key"] is "akey")

Typed version - by key, don't specify the class anymore (the entities have a field called key and they know their class, i.e. they are not generic objects):

send::  msg diesel.inv.upsert  (entity)

expect::  (payload contains "tc21")
send::  msg diesel.inv.upsert  (entity)

expect::  (payload contains "tc11")

Typed version - by ref - the entities have a field called assetRef - this is the default diesel asset reference.

send::  msg diesel.inv.upsert  (entity)

expect::  (payload contains "tc12")
send::  msg diesel.db.col.get  (collection="TestClassInv1", id="tc12")

expect::  ( ((payload as string) contains "tc12"))
// ### QUERY

send::  msg diesel.inv.listAll  (className="TestClassInv1")

expect::  (payload[="total"] is Number)
expect::  (payload[="data"] is Array)

TODO expect (payload.data[0] is TestClassInv1)

send::  msg ctx.echo  (x)

send::  msg diesel.inv.find  (className="TestClassInv1", key="tc11")

expect::  (payload is Json)

send:: msg  (tc11[="x"]="xattr")
send::  msg diesel.inv.upsert  (entity)

send::  msg diesel.inv.find  (className="TestClassInv1", key)

expect::  (payload[="x"] is "xattr")

send::  msg ctx.set  (payload :Array=[..])

send::  msg diesel.inv.query  (className="TestClassInv1", query :JSON)

expect::  (payload[="data"][="0"=0][:String="x"] is "xattr")

send::  msg diesel.inv.remove  (className="TestClassInv1", key="tc100")

send::  msg diesel.inv.find  (className="TestClassInv1", key)

expect::  (payload is undefined)

in mem

send::  msg diesel.inv.register  (inventory="diesel.db.inmem", classNames ="TestClassInv1,TestClassInv2"...)

send::  msg diesel.inv.connect  (inventory="diesel.db.inmem", env, connection)

expect::  (payload contains "ok")
send::  msg diesel.inv.testConnection  (inventory="diesel.db.inmem", connection)

expect::  (payload contains "ok")

CRUD

Some objects...

val tc21:JSON[TestClassInv2]={ "someValue": "something 2", "key": "tc21" } val tc100:JSON[TestClassInv1]={ "someValue": "something", "ref2": "tc21", "key": "tc100" } val tc11:JSON[TestClassInv1]={ "someValue": "something", "ref2": "tc21", "key": "tc11" } val tc12:JSON[TestClassInv1]={ "assetRef": {"key": "tc12"}, "someValue": "something" }

0 $mock:: a.b
   . (x=[tc21,tc11,tc12])

send::  msg a.b 

send::  msg ctx.echo  (x)

Upsert - creating entities in the inventory

Specify class, untyped object send::  msg diesel.inv.upsert  (className="TestClassInv1", entity :JSON)

expect::  (payload[="key"] is "akey")

Typed version - by key, don't specify the class anymore (the entities have a field called key):

send::  msg diesel.inv.upsert  (entity)

expect::  (payload[="key"] is "tc21")
send::  msg diesel.inv.upsert  (entity)

expect::  (payload[="key"] is "tc11")

Typed version - by ref - the entities have a field called assetRef - this is the default diesel asset reference.

send::  msg diesel.inv.upsert  (entity)

expect::  ( ((payload as string) contains "tc12"))
send::  msg diesel.ing.find  (collection="TestClassInv1", key="tc12")

expect::  ( ((payload as string) contains "tc12"))
// ### QUERY

send::  msg diesel.inv.listAll  (className="TestClassInv1")

expect::  (payload[="data"] is Array)
send::  msg ctx.echo  (x)

send::  msg diesel.inv.find  (className="TestClassInv1", key="tc11")

expect::  (payload is Json)

send:: msg  (tc11[="x"]="xattr")
send::  msg diesel.inv.upsert  (entity)

send::  msg diesel.inv.find  (className="TestClassInv1", key)

expect::  (payload[="x"] is "xattr")

send::  msg ctx.set  (payload :Array=[..])

send::  msg diesel.inv.query  (className="TestClassInv1", query :JSON)

expect::  (payload[="data"][="0"=0][:String="x"] is "xattr")

send::  msg diesel.inv.remove  (className="TestClassInv1", key="tc100")

send::  msg diesel.inv.find  (className="TestClassInv1", key)

expect::  (payload is undefined)

------ memshared

in mem

send::  msg diesel.inv.register  (inventory="diesel.db.memshared", classNames ="TestClassInv1,TestClassInv2"...)

send::  msg diesel.inv.connect  (inventory="diesel.db.memshared", env, connection)

expect::  (payload contains "ok")
send::  msg diesel.inv.testConnection  (inventory="diesel.db.memshared", connection)

expect::  (payload contains "ok")

CRUD

Some objects...

val tc21:JSON[TestClassInv2]={ "someValue": "something 2", "key": "tc21" } val tc100:JSON[TestClassInv1]={ "someValue": "something", "ref2": "tc21", "key": "tc100" } val tc11:JSON[TestClassInv1]={ "someValue": "something", "ref2": "tc21", "key": "tc11" } val tc12:JSON[TestClassInv1]={ "assetRef": {"key": "tc12"}, "someValue": "something" }

0 $mock:: a.b
   . (x=[tc21,tc11,tc12])

send::  msg a.b 

send::  msg ctx.echo  (x)

Upsert - creating entities in the inventory

Specify class, untyped object send::  msg diesel.inv.upsert  (className="TestClassInv1", entity :JSON)

expect::  (payload[="key"] is "akey")

Typed version - by key, don't specify the class anymore (the entities have a field called key):

send::  msg diesel.inv.upsert  (entity)

expect::  ( ((payload as string) contains "tc21"))
send::  msg diesel.inv.upsert  (entity)

expect::  ( ((payload as string) contains "tc11"))

Typed version - by ref - the entities have a field called assetRef - this is the default diesel asset reference.

send::  msg diesel.inv.upsert  (entity)

expect::  ( ((payload as string) contains "tc12"))
send::  msg diesel.db.memshared.get  (collection="TestClassInv1", id="tc12")

expect::  ( ((payload as string) contains "tc12"))
// ### QUERY

send::  msg diesel.inv.listAll  (className="TestClassInv1")

expect::  (payload[="data"] is Array)
send::  msg ctx.echo  (x)

send::  msg diesel.inv.find  (className="TestClassInv1", key="tc11")

expect::  (payload is Json)

send:: msg  (tc11[="x"]="xattr")
send::  msg diesel.inv.upsert  (entity)

send::  msg diesel.inv.find  (className="TestClassInv1", key)

expect::  (payload[="x"] is "xattr")

send::  msg ctx.set  (payload :Array=[..])

send::  msg diesel.inv.query  (className="TestClassInv1", query :JSON)

expect::  (payload[="data"][="0"=0][:String="x"] is "xattr")

send::  msg diesel.inv.remove  (className="TestClassInv1", key="tc100")

send::  msg diesel.inv.find  (className="TestClassInv1", key)

expect::  (payload is undefined)

Pagination

TODO add tests for from, size, sort and q: asc or desc.


Was this useful?    

By: Razie | 2021-01-16 .. 2021-01-26 | Tags: story , dsl


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

You need to log in to post a comment!

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