   ([table-name] (check-table table-name "*"))
   ([table-name column-name]
    (try
-     (jdbc/with-connection
+     (jdbc/query
        @spec
-       (jdbc/with-query-results
-         rs
-         [(str "SELECT COUNT(" (name column-name) ") FROM " (name table-name))]
-         rs))
+       [(str "SELECT COUNT(" (name column-name) ") FROM " (name table-name))])
      (catch Exception e nil))))
-
-(defn create-index
-  [table-name columns]
-  (jdbc/do-commands
-    "CREATE ALIAS IF NOT EXISTS FT_INIT FOR \"org.h2.fulltext.FullText.init\";"
-    "CALL FT_INIT();"
-    (format "CALL FT_CREATE_INDEX('PUBLIC', '%s', '%s');"
-            table-name (clojure.string/join "," columns))))
 
 (defn create-generic-table
   [table-name]
-  (jdbc/create-table
+  (jdbc/create-table-ddl
     table-name
     [:id "BIGINT" "PRIMARY KEY AUTO_INCREMENT"]
     [:realuserhash "BINARY"]


(defn get-single-user-data
  [params]
  (let [user-hash (:userhash params)]
    (jdbc/with-connection
      @spec
      (jdbc/with-query-results
        rs
        ["SELECT * FROM user WHERE userhash = ?" user-hash]
        (if-let [user (first (prepare-results rs :user))]
          (dissoc user :time)
          {:userhash user-hash :type :user})))))

(defn get-single-post-data
  [params]
  (let [user-hash (:userhash params)
        create-time (:time params)]
    (jdbc/with-connection
      @spec
      (jdbc/with-query-results
        rs
        ["SELECT * FROM post WHERE userhash = ? AND time = ? AND status = 1"
         user-hash create-time]
        (if-let [post (first (prepare-results rs :post))]
          post
          {:userhash user-hash :time create-time :type :post})))))

(defn get-post-data
  [params]
  (let [user-hash (:userhash params)
        page (:page params)]
    (jdbc/with-connection
      @spec
      (jdbc/with-query-results
        rs
        [(paginate page
                   "SELECT * FROM post 
                   WHERE userhash = ? AND status = 1 ORDER BY time DESC")
         user-hash]
        (prepare-results rs :post)))))

(defn get-single-fav-data
  ([params] (get-single-fav-data params @c/my-hash-bytes))
  ([params my-user-hash]
   (let [ptr-hash (:userhash params)
         ptr-time (:time params)]
     (jdbc/with-connection
       @spec
       (jdbc/with-query-results
         rs
         ["SELECT * FROM fav WHERE userhash = ? AND ptrhash = ? AND ptrtime IS ?"
          my-user-hash ptr-hash ptr-time]
         (first (prepare-results rs :fav)))))))

(defn get-fav-data
  ([params] (get-fav-data params @c/my-hash-bytes))
  ([params my-user-hash]
   (let [ptr-hash (:ptrhash params)]
     (jdbc/with-connection
       @spec
       (jdbc/with-query-results
         rs
         ["SELECT * FROM fav WHERE ptrhash = ? 
          AND status = 1 
          AND (userhash IN 
          (SELECT ptrhash FROM fav WHERE userhash = ? AND status = 1) 
          OR userhash = ?)"
          ptr-hash my-user-hash my-user-hash]
         (prepare-results rs :fav))))))

(defn get-category-data
  [params]

                           LIMIT 1" tag]
                    nil)]
    (when statement
      (-> (jdbc/query @spec statement)
          (prepare-results :tag)
          first))))

(defn get-pic-data
  ([params]
   (let [user-hash (:userhash params)
         pic-hash (:pichash params)
         statement ["SELECT * FROM pic WHERE userhash = ? AND pichash = ?"
                    user-hash pic-hash]
         rs (jdbc/query @spec statement)]
     (prepare-results rs :pic)))
  ([params ptr-time paginate?]
   (let [user-hash (:userhash params)
         page (:page params)
         sql "SELECT * FROM pic WHERE userhash = ? AND ptrtime IS ?"
         statement [(if paginate? (paginate page sql) sql)
                    user-hash ptr-time]
         rs (jdbc/query @spec statement)]
     (prepare-results rs :pic))))

; insertion / removal

