Skip to content

Instantly share code, notes, and snippets.

@priyatam

priyatam/gist:9649695

Last active Aug 29, 2015
Embed
What would you like to do?
;; Schema
;; poem
[{:db/id #db/id[:db.part/db]
:db/ident :poem/short-url
:db/unique :db.unique/identity
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db.install/_attribute :db.part/db}
{:db/id #db/id[:db.part/db]
:db/ident :poem/title
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/fulltext true
:db.install/_attribute :db.part/db}
{:db/id #db/id[:db.part/db]
:db/ident :poem/country
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db.install/_attribute :db.part/db}
{:db/id #db/id[:db.part/db]
:db/ident :poem/year
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db.install/_attribute :db.part/db}
{:db/id #db/id[:db.part/db]
:db/ident :author
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db.install/_attribute :db.part/db}
{:db/id #db/id[:db.part/db]
:db/ident :poem/tags
:db/valueType :db.type/string
:db/cardinality :db.cardinality/many
:db.install/_attribute :db.part/db}]
;; annotations
[{:db/id #db/id[:db.part/db]
:db/ident :annotations/short-url
:db/unique :db.unique/identity
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db.install/_attribute :db.part/db}
{:db/id #db/id[:db.part/db]
:db/ident :poem
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/unique :db.unique/identity
:db.install/_attribute :db.part/db}
{:db/id #db/id[:db.part/db]
:db/ident :annotations/selections
:db/valueType :db.type/string
:db/cardinality :db.cardinality/many
:db.install/_attribute :db.part/db}
{ :db/id #db/id[:db.part/db]
:db/ident :annotations/type
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db.install/_attribute :db.part/db}
{:db/id #db/id[:db.part/db]
:db/ident :annotations/notes
:db/valueType :db.type/string
:db/cardinality :db.cardinality/many
:db/fulltext true
:db.install/_attribute :db.part/db}
{:db/id #db/id[:db.part/db]
:db/ident :annotations/highlight
:db/valueType :db.type/string
:db/cardinality :db.cardinality/many
:db/fulltext true
:db.install/_attribute :db.part/db}]
;; tx
(defn save-annotation [io-type annot-edn poem-short-url]
(let [annot-url (tweet-url)
data (first (:annotations (zen/read-edn io-type annot-edn)))
tx-annot [{:db/id (d/tempid :db.part/user)
:annotations/short-url annot-url
:annotations/type (:type data)
:poem [:poem/short-url poem-short-url]
:annotations/selections (prn-str (:selections data))
:annotations/notes (:notes data)}]]
[annot-url (d/transact *conn* tx-annot)]))
;; 'data'
{:selections [[1 1] [1 3]], :type "notes", :notes "Unusual opening line."}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.