diesel-inv-story Pub

Diesel inventory

See Domain Modelling and Assets, Entities and Inventories.

diesel.db.col

Register and connect

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

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

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

expect::  (payload contains "ok")

CRUD

Some objects...

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

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

send::  msg a.b 

send::  msg ctx.echo  (x=x)

Upsert - creating entities in the inventory

Specify class, untyped object send::  msg diesel.inv.upsert  (className="TestClassInv1"="TestClassInv1", entity:JSON={key:"akey",x:"xvalue"})

expect::  (payload contains "akey")

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

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

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

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

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

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

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

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

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

send::  msg ctx.echo  (x=payload[="data"][="0"=0])

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

expect::  (payload is Json)

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

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

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

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

send::  msg diesel.inv.query  (className="TestClassInv1"="TestClassInv1", query:JSON={key:tc11[="key"]})

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

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

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

expect::  (payload is undefined)

in mem

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

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

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

expect::  (payload contains "ok")

CRUD

Some objects...

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

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

send::  msg a.b 

send::  msg ctx.echo  (x=x)

Upsert - creating entities in the inventory

Specify class, untyped object send::  msg diesel.inv.upsert  (className="TestClassInv1"="TestClassInv1", entity:JSON={key:"akey",x:"xvalue"})

expect::  (payload contains "akey")

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

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

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

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

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

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

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

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

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

expect::  (payload is Json)

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

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

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

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

send::  msg diesel.inv.query  (className="TestClassInv1"="TestClassInv1", query:JSON={key:tc11[="key"]})

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

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

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

expect::  (payload is undefined)

------ memshared

in mem

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

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

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

expect::  (payload contains "ok")

CRUD

Some objects...

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

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

send::  msg a.b 

send::  msg ctx.echo  (x=x)

Upsert - creating entities in the inventory

Specify class, untyped object send::  msg diesel.inv.upsert  (className="TestClassInv1"="TestClassInv1", entity:JSON={key:"akey",x:"xvalue"})

expect::  (payload contains "akey")

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

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

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

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

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

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

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

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

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

expect::  (payload is Json)

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

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

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

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

send::  msg diesel.inv.query  (className="TestClassInv1"="TestClassInv1", query:JSON={key:tc11[="key"]})

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

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

send::  msg diesel.inv.find  (className="TestClassInv1"="TestClassInv1", key=tc100[="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 79 times ( | Print ) this page.

You need to log in to post a comment!

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