Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/viesti/puihin
Trying out Datomic
https://github.com/viesti/puihin
Last synced: about 2 months ago
JSON representation
Trying out Datomic
- Host: GitHub
- URL: https://github.com/viesti/puihin
- Owner: viesti
- License: epl-1.0
- Created: 2015-01-18T19:29:34.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-01-25T21:08:25.000Z (almost 10 years ago)
- Last Synced: 2023-03-23T02:06:24.682Z (almost 2 years ago)
- Language: Clojure
- Size: 141 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# puihin
## Demo of Datomic as document like storage:
Let's have a tree/document -like structure with nodes having text
attribute and child nodes (imagine a table of contents).```clojure
(def schema
[{:db/id #db/id[:db.part/db]
:db/ident :node/text
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/fulltext true
:db/index true
:db.install/_attribute :db.part/db}
{:db/id #db/id[:db.part/db]
:db/ident :node/children
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many
:db/isComponent true
:db.install/_attribute :db.part/db}])
```Datomic allows to write a whole 'document' at once with [nested maps](http://docs.datomic.com/transactions.html#sec-3-4):
```clojure
(defn document-like-tree-data [root]
[{:db/id root
:node/text "root"
:node/children
[{:node/text "middle"
:node/children
[{:node/text "leaf1"}
{:node/text "leaf2"}]}]}])
```[Pull API](http://blog.datomic.com/2014/10/datomic-pull.html) allows
to get it back as a nested map.```clojure
(d/pull (d/db conn) '[*] root-entity-id)
{:db/id 17592186045418,
:node/text "root",
:node/children
[{:db/id 17592186045419,
:node/text "middle",
:node/children
[{:db/id 17592186045420, :node/text "leaf1"}
{:db/id 17592186045421, :node/text "leaf2"}]}]}
```Neat!
## License
Copyright © 2015 Kimmo Koskinen
Distributed under the Eclipse Public License either version 1.0 or (at
your option) any later version.