diesel-inv-spec Pub

Inventory examples

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

Diesel interfaces:

These are the signatures you should use in your code.

Before you do anything with a class, it needs registered to a specific inventory implementation. classNames are comma-separated and you can use "*" to default a single inventory type to all classes in a project.

See below these sections, for the supported inventories.

Note: try to avoid using diesel.inv.register unless you need dynamic inventory mapping OR for the "*" mapping of all classes - otherwise use the annotation per class ($anno(inventory="my.preferred.inventory"))

msg diesel.inv.register  (inventory, classNames)

And then you have to connect that inventory to an instance (use default for the connection if you only intend to support one and it's default):

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

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

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

Implementation signatures:

These are used internally, to implement the interface messages above. You should not call these in your code!

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 inventory defined for ${cla"...="No invent...)

fallback:: diesel.inv.impl.findByRef (className)
   diesel.throw (msg ="No inventory defined for ${cla"...="No invent...)

fallback:: diesel.inv.impl.findByQuery (className)
   diesel.throw (msg ="No inventory defined for ${cla"...="No invent...)

fallback:: diesel.inv.impl.update (className)
   diesel.throw (msg ="No inventory defined for ${cla"...="No invent...)

fallback:: diesel.inv.impl.delete (className)
   diesel.throw (msg ="No inventory defined for ${cla"...="No invent...)


Was this useful?    

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


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

You need to log in to post a comment!

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