             {operation :op} entry]
         (cond
           (= operation "insert")
-           (let [{article-id :id file-id :file_id  file-url :url audio-format :format} entry]
-            (create-schema)
-            (insert-entry article-id file-id file-url (str audio-format))
-            (>! out entry))
+           (let [{id :id file-id :file_id file-url :url audio-format :format} entry]
+             (create-schema)
+             (insert-entry id file-id file-url (str audio-format) (int 0))
+             (>! out entry))
+           (= operation "update")
+           (let [{id :id} entry]
+             (update-article-state 1 id))
            (= operation "search")
-           (let [{article-id :id} entry]
-             (>! out (get-entry article-id)))
+           (let [{id :id} entry]
+             (>! out (get-entry id)))
            (= operation "all")
            (>! out (get-all))
           )))


(def cluster (alia/cluster {:contact-points ["127.0.0.1"]}))
(def session (alia/connect cluster))
(def insert-entry-query "INSERT INTO articles (article_id, file_id, file_url, audio_format) VALUES (?, ?, ?, ?)")
(def get-entry-by-id-query "SELECT * FROM articles WHERE article_id = ?")
(def insert-entry-prepared (delay (alia/prepare session insert-entry-query)))
(def get-entry-by-id-prepared (delay (alia/prepare session get-entry-by-id-query)))

(defn- create-schema []

                         WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 3};")
  (alia/execute session "USE talkpocket;")
  (alia/execute session "CREATE TABLE IF NOT EXISTS articles (
                                                id varchar,
                                                file_id varchar,
                                                file_url varchar,
                                                audio_format varchar,
                                                state int,
                                                PRIMARY KEY (id));"))
(defn- insert-entry
  [id file-id file_url audio-format state]
  (alia/execute session "USE talkpocket;")
  (alia/execute session @insert-entry-prepared {:values [id file-id file_url audio-format state]}))

(defn- update-article-state
  [id new-state]
  (alia/execute session "USE talkpocket;")
  (alia/execute session @update-entry-state-prepared {:values [id new-state]}))

(defn- get-entry
  [id]
  (alia/execute session "USE talkpocket;")
  (alia/execute session @get-entry-by-id-prepared {:values [id]}))

(defn- get-all []
  (alia/execute session "USE talkpocket;")
