   (mon/update! :namespaces {:name (:name ns-map)} ns-map))
 
 
-(let [nss ["clojure.core"
+#_(let [nss ["clojure.core"
            "clojure.data"
            "clojure.edn"
            "clojure.inspector"

(defn all-notes []
  (j/query mysql-db ["SELECT * FROM comments"]))

(defn lookup-user [user-id]
  (select-keys (first (j/query mysql-db ["SELECT * FROM users WHERE id=?" user-id])) [:email :login]))

(defn lookup-ns [nsid]
  {:ns (->> (j/query mysql-db ["SELECT * FROM namespaces WHERE id=?" nsid])

  (mon/update! :examples (select-keys e [:library-url :ns :name :body]) e))

;; examples

(do
  (mon/drop-coll! :examples)
  (mon/drop-coll! :example-histories)
  (time
    (let [examples (->> (core-nss)
                        (map (fn [{:keys [library_id name id]}]
                               {:library-id library_id
                                :namespace-id id
                                :namespace name}))
                        (mapcat (fn [{:keys [namespace namespace-id]}]
                                  (let [res (j/query mysql-db ["SELECT * FROM functions WHERE namespace_id=?" namespace-id])]
                                    (->> res
                                         (map (fn [{:keys [name id]}]
                                                {:ns namespace
                                                 :name name
                                                 :function-id id}))))))
                        (mapcat (fn [m]
                                  (let [res (j/query mysql-db ["SELECT * FROM examples WHERE function_id=?" (:function-id m)])]
                                    (->> res
                                         (map (fn [{:keys [body user_id id created_at updated_at]}]
                                                (assoc m
                                                  :body body
                                                  :user-id user_id
                                                  :example-id id
                                                  :created-at created_at
                                                  :updated-at updated_at)))))))
                        (map (fn [{:keys [user-id example-id] :as m}]
                               (let [user (lookup-user user-id)]
                                 (assoc m
                                   :author user
                                   :history (history-for example-id)))))
                        (map #(assoc % :library-url "https://github.com/clojure/clojure"))
                        (map (fn [{:keys [author ns name body library-url created-at updated-at history]}]
                               {:_id (org.bson.types.ObjectId.)
                                :var {:ns ns
                                      :name name
                                      :library-url library-url}
                                :history history
                                :author author
                                :editors (map :editor history)
                                :body body
                                :created-at (.getTime created-at)
                                :updated-at (.getTime updated-at)})))]
      (doseq [{:keys [_id history] :as e} examples]
        (mon/insert! :examples
          (select-keys e [:_id :var :author :editors :body :created-at :updated-at]))
        (doseq [h history]
          (mon/insert!
            :example-histories
            (merge
              h
              {:_id (org.bson.types.ObjectId.)
               :example-id _id}))))
      (println "examples" (mon/fetch-count :examples))
      (println "example history entries" (mon/fetch-count :example-histories)))))

(def special-forms
  [{:name 'def
