diesel-inv-spec Pub

Inventory examples

Upsert by default uses the payload and assumes it has an assetRef or a key:

Diesel interfaces:

msg diesel.inv.register  (inventory, classNames)

msg diesel.inv.connect  (inventory, connection?)

msg diesel.inv.testConnection  (inventory, connection?)

msg diesel.inv.upsert  (inventory?, connection?, className?, entity?, key?)

msg diesel.inv.find  (inventory?, connection?, className, key)

msg diesel.inv.remove  (inventory?, connection?, className, key)

msg diesel.inv.query  (inventory?, connection?, ref, attrs, from?, size?, countOnly?)

msg diesel.inv.listAll  (inventory?, connection?, ref, from?, size?)

Implementation signatures:

msg diesel.inv.impl.testConnection  (inventory, connection, env)

msg diesel.inv.impl.connect  (inventory, connection, env)

msg diesel.inv.impl.upsert  (inventory?, connection?, className, table, entity, assetRef, key)

msg diesel.inv.impl.listAll  (inventory?, connection?, className, table, ref, from?, size?, countOnly?)

msg diesel.inv.impl.remove  (inventory?, connection?, className, table, ref)

msg diesel.inv.impl.findByQuery  (inventory?, connection?, className, table, from?, size?, countOnly?, sort?)

msg diesel.inv.impl.findByRef  (inventory?, connection?, className, table, ref)

##-------- diesel.db.col Connecting

$when:: diesel.inv.impl.testConnection (inventory is "diesel.db.col", connection)
   . (payload="haha, ok")

$when:: diesel.inv.impl.connect (inventory == "diesel.db.col", connection, env)
   . (payload="connected, ok")

diesel.db.col CRUD - creating and managing entities

Create is special - needs to add the "assetRef" to the entity

$when:: diesel.inv.impl.upsert (inventory == "diesel.db.col", className, table, key, assetRef, entity)
   . (k=(key || assetRef[="key"]))
   . (e=(entity + {assetRef:assetRef}))
   diesel.db.col.upsert (collection=table, id=k, document=e)
   . (payload=entity)

$when:: diesel.inv.impl.listAll (inventory == "diesel.db.col", className, table)
   diesel.db.col.query (collection=table)

$when:: diesel.inv.impl.findByRef (inventory == "diesel.db.col", className, table, ref)
   diesel.db.col.get (collection=table, id=ref[="key"...)

$when:: diesel.inv.impl.remove (inventory == "diesel.db.col", className, table, ref)
   diesel.db.col.remove (collection=table, id=ref[="key"...)

$when:: diesel.inv.impl.findByQuery (inventory == "diesel.db.col", connection, className, table, query)
   ctx.echo (q=query)
   diesel.db.col.query (collection=table, query.asAttrs)

##-------------- diesel.db.inmem

$when:: diesel.inv.impl.testConnection (inventory is "diesel.db.inmem", connection)
   . (payload="haha, ok")

$when:: diesel.inv.impl.connect (inventory == "diesel.db.inmem", connection, env)
   . (payload="connected, ok")

diesel.db.inmem CRUD - creating and managing entities

Create is special - needs to add the "assetRef" to the entity

$when:: diesel.inv.impl.upsert (inventory == "diesel.db.inmem", className, table, key, assetRef, entity)
   . (k=(key || assetRef[="key"]))
   . (entity=(entity + {assetRef:assetRef}))
   diesel.db.inmem.upsert (collection=table, id=k, document=entity)
   . (payload=entity)

$when:: diesel.inv.impl.listAll (inventory == "diesel.db.inmem", className, table)
   diesel.db.inmem.query (collection=table)

$when:: diesel.inv.impl.findByRef (inventory == "diesel.db.inmem", className, table, ref)
   diesel.db.inmem.get (collection=table, id=ref[="key"...)

$when:: diesel.inv.impl.remove (inventory == "diesel.db.inmem", className, table, ref)
   diesel.db.inmem.remove (collection=table, id=ref[="key"...)

$when:: diesel.inv.impl.findByQuery (inventory == "diesel.db.inmem", connection, className, table, query)
   ctx.echo (q=query)
   diesel.db.inmem.query (collection=table, query.asAttrs)

-------- diesel.db.memshared

$when:: diesel.inv.impl.testConnection (inventory is "diesel.db.memshared", connection)
   . (payload="haha, ok")

$when:: diesel.inv.impl.connect (inventory == "diesel.db.memshared", connection, env)
   . (payload="connected, ok")

diesel.db.memshared CRUD - creating and managing entities

Create is special - needs to add the "assetRef" to the entity

$when:: diesel.inv.impl.upsert (inventory == "diesel.db.memshared", className, table, key, assetRef, entity)
   . (k=(key || assetRef[="key"]))
   . (entity=(entity + {assetRef:assetRef}))
   diesel.db.memshared.upsert (collection=table, id=k, document=entity)
   . (payload=entity)

$when:: diesel.inv.impl.listAll (inventory == "diesel.db.memshared", className, table)
   diesel.db.memshared.query (collection=table, from, size)

$when:: diesel.inv.impl.findByRef (inventory == "diesel.db.memshared", className, table, ref)
   diesel.db.memshared.get (collection=table, id=ref[="key"...)

$when:: diesel.inv.impl.remove (inventory == "diesel.db.memshared", className, table, ref)
   diesel.db.memshared.remove (collection=table, id=ref[="key"...)

$when:: diesel.inv.impl.findByQuery (inventory == "diesel.db.memshared", connection, className, table, query)
   ctx.echo (q=query)
   diesel.db.memshared.query (collection=table, from, size, query.asAttrs)

##------------------- Postgres Inventory

Note for postgres, you'll need to create a new connection before the rules below work:

// $send diesel.db.postgres.new ( // connection = "default", // url = POSTGRES_URL // )

$when:: diesel.inv.impl.testConnection (inventory is "diesel.db.postgres", connection)
   . (payload="haha, ok")

TODO when connecting, grab the connection somehow?

$when:: diesel.inv.impl.connect (inventory == "diesel.db.postgres", connection, env)
   . (payload="connected, ok")

CRUD - creating and managing entities

Create is special - needs to add the "assetRef" to the entity

$when:: diesel.inv.impl.upsert (inventory == "diesel.db.postgres", className, table, key, assetRef, entity)
   . (k=(key || assetRef[="key"]))
   . (entity=(entity + {assetRef:assetRef}))
   ctx.echo (entity)
   . (e=(entity + {assetRef:assetRef}))
   diesel.db.postgres.upsert (collection=table, id=k, document=e)
   . (payload=entity)

$when:: diesel.inv.impl.listAll (inventory == "diesel.db.postgres", className, table)
   diesel.db.postgres.query (collection=table)

$when:: diesel.inv.impl.findByRef (inventory == "diesel.db.postgres", className, table, ref)
   diesel.db.postgres.get (collection=table, id=ref[="key"...)

$when:: diesel.inv.impl.remove (inventory == "diesel.db.postgres", className, table, ref)
   diesel.db.postgres.remove (collection=table, id=ref[="key"...)

$when:: diesel.inv.impl.findByQuery (inventory == "diesel.db.postgres", connection, className, table, query)
   ctx.echo (q=query)
   diesel.db.postgres.query (collection=table, query.asAttrs)

------- Default fallback rules

These kick in if no inventory rules were defined

fallback:: diesel.inv.impl.upsert (className)
   diesel.throw (msg="No invent...)

fallback:: diesel.inv.impl.findByRef (className)
   diesel.throw (msg="No invent...)

fallback:: diesel.inv.impl.findByQuery (className)
   diesel.throw (msg="No invent...)

fallback:: diesel.inv.impl.update (className)
   diesel.throw (msg="No invent...)

fallback:: diesel.inv.impl.delete (className)
   diesel.throw (msg="No invent...)


Was this useful?    

By: Razie | 2021-01-16 .. 2022-05-03 | Tags: spec , dsl , DslDomain , database , inventory


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

You need to log in to post a comment!

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