<commit_before>(ns wombats.components.datomic
  (:require [com.stuartsierra.component :as component]
            [datomic.api :as d]
            [io.pedestal.log :as log]))

;; Private helper functions

(defn- create-db-connection
  [config]
  (let [datomic-uri (get-in config [:settings :datomic :uri] nil)
        ;; _ (d/delete-database datomic-uri)
        _ (d/create-database datomic-uri)
        conn (d/connect datomic-uri)]
    (d/transact conn (load-file "resources/datomic/schema.edn"))
    {:conn conn}))

;; Component

(defrecord Datomic [config database]
  component/Lifecycle
  (start [component]
    (if database
      component
      (assoc component :database (create-db-connection config))))
  (stop [component]
    (if-not database
      component
      (do
        (d/release (:conn database))
        (assoc component :database nil)))))

;; Public component methods

(defn new-database
  "Datomic component. Creates database connection to Datomic.

  Note: This component is dependent on the Configuration component."
  []
  (map->Datomic {}))
<commit_msg>remove reset db work around<commit_after>(ns wombats.components.datomic
  (:require [com.stuartsierra.component :as component]
            [datomic.api :as d]
            [io.pedestal.log :as log]))

;; Private helper functions

(defn- create-db-connection
  [config]
  (let [datomic-uri (get-in config [:settings :datomic :uri] nil)
        _ (d/create-database datomic-uri)
        conn (d/connect datomic-uri)]
    (d/transact conn (load-file "resources/datomic/schema.edn"))
    {:conn conn}))

;; Component

(defrecord Datomic [config database]
  component/Lifecycle
  (start [component]
    (if database
      component
      (assoc component :database (create-db-connection config))))
  (stop [component]
    (if-not database
      component
      (do
        (d/release (:conn database))
        (assoc component :database nil)))))

;; Public component methods

(defn new-database
  "Datomic component. Creates database connection to Datomic.

  Note: This component is dependent on the Configuration component."
  []
  (map->Datomic {}))

{'fraction_non_alphanumeric': 0.12188235294117647, 'fraction_numerical': 0.0, 'mean_word_length': 3.1042471042471043, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4919611', 'n_tokens_mistral': 647, 'n_tokens_neox': 637, 'n_words': 182}