   ...]`, in which case it will be transformed into `key = value1 OR
   key = value2 ...`. Nested vectors is supported."
   [k v]
-  (let [k (name k)]
+  (let [qk (qualified-name k)]
     (condp #(= % (type %2)) v
       PersistentVector (let [[op & values] v]
                          (->> values
                               (map (partial keyval-to-sql k))
                               (interpose (str " " (name op) " "))
                               string/join))
-      String (format "(%s = '%s')" k v)
-      Boolean (format "(%s = %s)" k (if v 1 0))
-      nil (format "(%s is NULL)" k)
-      (format "(%s = %s)" k v))))
+      String (format "(%s = '%s')" qk v)
+      Boolean (format "(%s = %s)" qk (if v 1 0))
+      Keyword (format "(%s = %s)" qk (qualified-name v))
+      nil (format "(%s is NULL)" qk)
+      (format "(%s = %s)" qk v))))
 
 ;; ### SQL operations
 

         (interpose " AND ")
         string/join)))

(defn query
  "Executes SELECT statement against the database and returns a Cursor
  object with the results. `where` argument should be a map of column
  keywords to values."
  [^TaggedDatabase tagged-db table-name where]
  (let [columns (->> (get-in (.schema tagged-db) [:tables table-name :columns])
                     keys
                     (map name)
                     into-array)]
    (.query (.db tagged-db) (name table-name) columns
            (where-clause where) nil nil nil nil)))
(def db-query query)

(defn seq-cursor
  "Turns data from Cursor object into a lazy sequence. Takes database
  argument in order to get schema from it."
  [^TaggedDatabase tagged-db, table-name, ^Cursor cursor]
  (.moveToFirst cursor)
  (let [columns (get-in (.schema tagged-db) [:tables table-name :columns])
        seq-fn (fn seq-fn []
                 (lazy-seq
                  (if (.isAfterLast cursor)
                    (.close cursor)
                    (let [v (reduce-kv
                             (fn [data i [column-name {type :type}]]
                               (assoc data column-name
                                      (get-value-from-cursor cursor i type)))
                             {} (vec columns))]
                      (.moveToNext cursor)
                      (cons v (seq-fn))))))]
    (seq-fn)))

(defn query-seq
  "Executes a SELECT statement against the database and returns the
  result in a sequence. Same as calling `seq-cursor` on `query` output."
  [^TaggedDatabase tagged-db table-name where]
  (seq-cursor tagged-db table-name (db-query tagged-db table-name where)))
(def db-query-seq query-seq)

(defn query-scalar

                      (name table-name)
                      (if (seq where-cl)
                        (str "where " where-cl) ""))]
    (with-open [^Cursor cursor (.rawQuery (.db tagged-db) query nil)]
      (try (.moveToFirst cursor)
           (get-value-from-cursor cursor 0 type)
           (catch CursorIndexOutOfBoundsException e nil)))))
