README.md 1.77 KB
Newer Older
Ivar Refsdal's avatar
Ivar Refsdal committed
1
2
# vase-transact-fn

Ivar Refsdal's avatar
Ivar Refsdal committed
3
Sample project for executing a Datomic DB function on JSON payload.
Ivar Refsdal's avatar
Ivar Refsdal committed
4

Ivar Refsdal's avatar
Ivar Refsdal committed
5
## Usage
Ivar Refsdal's avatar
Ivar Refsdal committed
6
7
8
9
10
11
12
13
14
15
16

Start the server

    lein repl
    (def srv (run-dev))

In another terminal
    
    curl -H "Content-Type: application/json" -X POST -d '{"payload": [{"item/name": "milk_bottle"}]}' http://localhost:8080/api/accounts/v1/hello
    

Ivar Refsdal's avatar
Ivar Refsdal committed
17
In the console you should then see 
Ivar Refsdal's avatar
Ivar Refsdal committed
18

Ivar Refsdal's avatar
Ivar Refsdal committed
19
20
21
22
    hello from DB land:: ==>> {:item/name milk_bottle}
    

The function that emits this line is both specified and used in [vase-transact-fn_service.edn](resources/vase-transact-fn_service.edn):
Ivar Refsdal's avatar
Ivar Refsdal committed
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

```
{:activated-apis
 [:accounts/v1]
 :datomic-uri
 "datomic:mem://bergen"
 :descriptor
 {:vase/norms
  {:accounts/item
   {:vase.norm/txes [[{:db/id    #db/id [:db.part/user]
                       :db/ident :my-great-fn
                       :db/fn    #db/fn
                                     {:lang   :clojure
                                      :params [db m]
                                      :code   (do
                                                (println "hello from DB land:: ==>>" m)
                                                [m])}}
                      {:db/id          #db/id[:db.part/db]
                       :db/ident       :item/name
                       :db/valueType   :db.type/string
                       :db/unique      :db.unique/identity
                       :db/cardinality :db.cardinality/one
                       :db/doc         "The name of an item"}]]}}
  :vase/specs
  {}
  :vase/apis
  {:accounts/v1
   {:vase.api/routes {"/hello" {:post [#nsd/transact-fn {:name       :accounts.v1/item-create-with-function
                                                         :db-fn      :my-great-fn
                                                         :properties [:item/name]}]}}}}}}
```