Upsert by default uses the payload and assumes it has an assetRef
or a key
:
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?)
Obsoleted (same as find and query) - but I like these names better, more precise:
msg diesel.inv.findByRef (inventory?, connection?, className, key)
msg diesel.inv.findByQuery (inventory?, connection?, ref, attrs, from?, size?, countOnly?)
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)
If the inventory or connection are not passed in, they are not known and assumed to be the default for the className
.
For the return signatures and examples, see the implementations for DieselMonkey++ below.
$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"
)
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)
Create is special - needs to add the "assetRef" to the entity
$when::
diesel.inv.impl.upsert (inventory == "diesel.inv.default"
, 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.inv.default"
, className, table)
diesel.db.col.query (collection=table)
$when::
diesel.inv.impl.findByRef (inventory == "diesel.inv.default"
, className, table, ref)
diesel.db.col.get (collection=table, id=ref[="key"...)
$when::
diesel.inv.impl.remove (inventory == "diesel.inv.default"
, className, table, ref)
diesel.db.col.remove (collection=table, id=ref[="key"...)
$when::
diesel.inv.impl.findByQuery (inventory == "diesel.inv.default"
, connection, className, table, query)
ctx.echo (q=query)
diesel.db.col.query (collection=table, query.asAttrs)
$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"
)
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)
$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"
)
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)
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"
)
"diesel.db.postgres"
, connection, env) payload
="connected, ok"
) 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)
$when::
diesel.inv.impl.testConnection (inventory is "diesel.monkeys"
, connection)
step return is optional, throw exception if any problems
$when::
diesel.inv.impl.connect (inventory is "diesel.monkeys"
, connection, env)
step return is optional, throw exception if any problems
Create is special - needs to add the "assetRef" to the entity
$when::
diesel.inv.impl.upsert (inventory is "diesel.monkeys"
, className, table, key, assetRef, entity)
step return the entity as created
. (payload
=entity
)
$when::
diesel.inv.impl.listAll (inventory is "diesel.monkeys"
, className, table)
step return total
count and paginated data
. (payload
={total:1,data:[{name:"monkeyboss"}]}
)
$when::
diesel.inv.impl.findByQuery (inventory is "diesel.monkeys"
, connection, className, table, query)
step return total
count and paginated data
. (payload
={total:1,data:[{name:"monkeyboss"}]}
)
$when::
diesel.inv.impl.findByRef (inventory is "diesel.monkeys"
, className, table, ref)
step return total
count and paginated data
OR the entity you found / null for nothing
. (payload
={total:1,data:[{name:"monkeyboss"}]}
)
$when::
diesel.inv.impl.remove (inventory is "diesel.monkeys"
, className, table, ref)
step nothing to return
These kick in if no inventory rules were defined
fallback::
diesel.inv.impl.upsert (className)
diesel.throw (msg ="impl.upsert missing OR no inve"
...="impl.upse...)
fallback::
diesel.inv.impl.findByRef (className)
diesel.throw (msg ="impl.findByRef missing OR no i"
...="impl.find...)
fallback::
diesel.inv.impl.findByQuery (className)
diesel.throw (msg ="impl.findByQuery missing OR no"
...="impl.find...)
fallback::
diesel.inv.impl.update (className)
diesel.throw (msg ="impl.update missing OR no inve"
...="impl.upda...)
fallback::
diesel.inv.impl.delete (className)
diesel.throw (msg ="impl.delete missing OR no inve"
...="impl.dele...)
You need to log in to post a comment!