<commit_before>(ns poky.kv.jdbc
  (:require [poky.kv.core :refer :all]
            [poky.kv.jdbc.util :refer :all]
            [clojure.tools.logging :refer [warnf]]
            [clojure.java.jdbc :as sql]
            [clojure.string :as string])
  (:import [poky.kv.core.KeyValue]
           [poky.kv.core.Connection]))

(declare get-connection)

(defrecord JdbcKeyValue [conn]
  KeyValue
  Connection
  (get* [this b k params]
    (get* this b k))
  (get* [this b k]
    (when-let [row (jdbc-get @conn b k)]
      {(:key row) (:data row) :modified_at (:modified_at row)}))
  (mget* [this b ks params]
    (mget* this b ks))
  (mget* [this b ks]
    (into {} (map (juxt :key :data) (jdbc-mget @conn b ks))))
  (set* [this b k value]
    (when-let [ret (jdbc-set @conn b k value)]
      (cond
        (and (seq? ret) (compare-seq-first ret 1)) :updated
        (and (seq? ret) (compare-seq-first ret 0)) :rejected
        (map? ret) :inserted
        :else false)))
  (set* [this b k value params]
    (set* this b k value))
  (delete* [this b k]
    (compare-seq-first (jdbc-delete @conn b k) 1))

  (connection [this]
    (get-connection this))
  (close [this]
    (close-connection (connection this))))

(defn get-connection
  "Get the connection from a JdbcKeyValue object."
  [jdbc-keyvalue-object]
  @(:conn jdbc-keyvalue-object))

(defn create
  [dsn]
  (->JdbcKeyValue (create-connection dsn)))<commit_msg>Moving the Connection in JdbcKeyValue.<commit_after>(ns poky.kv.jdbc
  (:require [poky.kv.core :refer :all]
            [poky.kv.jdbc.util :refer :all]
            [clojure.tools.logging :refer [warnf]]
            [clojure.java.jdbc :as sql]
            [clojure.string :as string])
  (:import [poky.kv.core.KeyValue]
           [poky.kv.core.Connection]))

(declare get-connection)

(defrecord JdbcKeyValue [conn]
  KeyValue
  (get* [this b k params]
    (get* this b k))
  (get* [this b k]
    (when-let [row (jdbc-get @conn b k)]
      {(:key row) (:data row) :modified_at (:modified_at row)}))
  (mget* [this b ks params]
    (mget* this b ks))
  (mget* [this b ks]
    (into {} (map (juxt :key :data) (jdbc-mget @conn b ks))))
  (set* [this b k value]
    (when-let [ret (jdbc-set @conn b k value)]
      (cond
        (and (seq? ret) (compare-seq-first ret 1)) :updated
        (and (seq? ret) (compare-seq-first ret 0)) :rejected
        (map? ret) :inserted
        :else false)))
  (set* [this b k value params]
    (set* this b k value))
  (delete* [this b k]
    (compare-seq-first (jdbc-delete @conn b k) 1))

  Connection
  (connection [this]
    (get-connection this))
  (close [this]
    (close-connection (connection this))))

(defn get-connection
  "Get the connection from a JdbcKeyValue object."
  [jdbc-keyvalue-object]
  @(:conn jdbc-keyvalue-object))

(defn create
  [dsn]
  (->JdbcKeyValue (create-connection dsn)))
{'fraction_non_alphanumeric': 0.15807921486154924, 'fraction_numerical': 0.002103049421661409, 'mean_word_length': 2.7552631578947366, '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': '6471205', 'n_tokens_mistral': 1089, 'n_tokens_neox': 1051, 'n_words': 315}