Two forms:
[db relation-name tuple] adds tuple to the named relation. Returns
the new database.
[rel tuple] adds to the relation object. Returns the new relation.
(defn add-tuple
"Two forms:
[db relation-name tuple] adds tuple to the named relation. Returns
the new database.
[rel tuple] adds to the relation object. Returns the new relation."
([db rel-name tuple]
(assert (= (-> tuple keys set) (-> rel-name db :schema)))
(assoc db rel-name (add-tuple (db rel-name) tuple)))
([rel tuple]
(let [data (:data rel)
new-data (conj data tuple)]
(if (identical? data new-data) ; optimization hack!
rel
(let [idxs (add-to-indexes (:indexes rel) tuple)]
(assoc rel :data new-data :indexes idxs))))))
Comments top
No comments for add-tuple. Log in to add a comment.