Class: Diametric::Persistence::Function

Inherits:
Object
  • Object
show all
Defined in:
lib/diametric/persistence/function.rb

Class Method Summary collapse

Class Method Details

.create(function_map, conn) ⇒ Object

Defines and saves a transaction or database function from given hash.

The hash should have keys of :name, :lang, :params and :code.
The hash can have optional keys of :doc, :requires and :imports.
The second argument is a connection to datomic. (optional)

Examples:

Defines and saves a database function in datomic.

Function.create({
  name: :inc_fn
  lang: :clojure,
  params: [:db, :id, :attr, :amount],
  code: %{(let [e (datomic.api/entity db id) orig (attr e 0)]
         [[:db/add id attr (+ orig amount) ]])},
  connection)

19
20
21
22
23
24
25
26
27
# File 'lib/diametric/persistence/function.rb', line 19

def self.create(function_map, conn)
  if conn && conn.is_a?(Diametric::Persistence::Connection)
    self.extend(Diametric::Persistence::PeerFunction)
  else
    conn = Diametric::Persistence::REST.connection
    self.extend(Diametric::Persistence::RestFunction)
  end
  self.create_function(function_map, conn)
end