<commit_before>(ns modern-cljs.repository.newsrepository
  (:require [compojure.core :refer :all]
            [clojure.java.jdbc :as sql]
            [modern-cljs.config.dbconfig :as dbconfig]))

(defrecord News [id, title, short-text, full-text, creation-date])

(defprotocol CrudRepository
  (find-all [x])
  (find-by-id [id]))

(defrecord NewsRepositoryComponent [dbconfig]
  CrudRepository
  (find-all [x]
    (let [news-list (sql/query dbconfig ["SELECT * FROM news"])]
      (for [news news-list]
        (->News (news :news_id) (news :title) (news :short_text) (news :full_text) (news :creation_date)))))
  (find-by-id [id]
    ("abc"))
  )

;instance of news repo
(def news-repo-component (NewsRepositoryComponent. dbconfig/mysql-db))

(defn news-repo-find-all-example []
  (let [news-list (find-all news-repo-component)]
    (for [news news-list]
      (println news))))

(defn load-all-news []
  (sql/query dbconfig/mysql-db ["SELECT * FROM news"]
             {:row-fn #(str (:short_text %) " was released in " (:creation_date %))}))

(defn load-news-by-id [id]
  (sql/query dbconfig/mysql-db
             ["select * from news where news_id = ?" id]
             {:row-fn :short_text}))

(defn get-news-by-id [id]
  (sql/query dbconfig/mysql-db
             ["select * from news where news_id = ?" id]))

(defn save-news [news]
  news)<commit_msg>find-by-id method is added to crud protocol<commit_after>(ns modern-cljs.repository.newsrepository
  (:require [compojure.core :refer :all]
            [clojure.java.jdbc :as sql]
            [modern-cljs.config.dbconfig :as dbconfig]))

(defrecord News [id, title, short-text, full-text, creation-date])

(defprotocol CrudRepository
  (find-all [this])
  (find-by-id [this id]))

(defrecord NewsRepositoryComponent [dbconfig]
  CrudRepository
  (find-by-id [this id]
    (let [news-items (sql/query dbconfig ["select * from news where news_id = ?" id])]
      (for [news news-items]
        (->News (news :news_id) (news :title) (news :short_text) (news :full_text) (news :creation_date)))))
  (find-all [this]
    (let [news-list (sql/query dbconfig ["SELECT * FROM news"])]
      (for [news news-list]
        (->News (news :news_id) (news :title) (news :short_text) (news :full_text) (news :creation_date))))))

;instance of news repo
(def news-repo-component (NewsRepositoryComponent. dbconfig/mysql-db))

(defn news-repo-find-all-example []
  (let [news-list (find-all news-repo-component)]
    (for [news news-list]
      (println news))))

(defn news-repo-find-by-id-example [id]
  (let [news (find-by-id news-repo-component id)]
    (println news)))

(defn load-all-news []
  (sql/query dbconfig/mysql-db ["SELECT * FROM news"]
             {:row-fn #(str (:short_text %) " was released in " (:creation_date %))}))

(defn load-news-by-id [id]
  (sql/query dbconfig/mysql-db
             ["select * from news where news_id = ?" id]
             {:row-fn :short_text}))

(defn get-news-by-id [id]
  (sql/query dbconfig/mysql-db
             ["select * from news where news_id = ?" id]))

(defn save-news [news]
  news)
{'fraction_non_alphanumeric': 0.1634771326629906, 'fraction_numerical': 0.0, 'mean_word_length': 3.2131147540983607, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '6534334', 'n_tokens_mistral': 1097, 'n_tokens_neox': 1073, 'n_words': 272}