                                                    (name< f1 f2)))
               ((clause-pos< f1 f2)))))))))
 
-(defn- fk-info-added° [field]
-  )
+(defn- resolve+order-cols [{:keys [result-keys], :as query}]
+  (when (seq result-keys)
+    (first (let [fields       (vec (lvars (count result-keys)))
+                 known-field° (field° query)]
+             (run 1 [q]
+               (everyg (fn [[result-key field]]
+                         (conda
+                           ((known-field°   result-key field))
+                           ((unknown-field° result-key field))))
+                       (zipmap result-keys fields))
+               (sorted-permutation° (fields-sorted° query) fields q))))))
+
+
+;;; # ---------------------------------------- COLUMN DETAILS  ----------------------------------------
+
+;; Format the results in the way the front-end expects.
+
+(defn- format-col [col]
+  (merge {:description nil
+          :id          nil
+          :table_id    nil}
+         (-> col
+             (set/rename-keys  {:base-type    :base_type
+                                :field-id     :id
+                                :field-name   :name
+                                :special-type :special_type
+                                :table-id     :table_id})
+             (dissoc :position))))
 
 (defn- add-fields-extra-info
   "Add `:extra_info` about `ForeignKeys` to `Fields` whose `special_type` is `:fk`."

                    :target     dest-field
                    :extra_info (if-not dest-field {}
                                        {:target_table_id (:table_id dest-field)})))))))

(defn- resolve+order-cols [{:keys [result-keys], :as query}]
  (when (seq result-keys)
    (first (let [fields       (vec (lvars (count result-keys)))
                 known-field° (field° query)]
             (run 1 [q]
               (everyg (fn [[result-key field]]
                         (conda
                           ((known-field°   result-key field))
                           ((unknown-field° result-key field))))
                       (zipmap result-keys fields))
               (sorted-permutation° (fields-sorted° query) fields q))))))


;;; # ---------------------------------------- COLUMN DETAILS  ----------------------------------------

;; Format the results in the way the front-end expects.

(defn- format-col [col]
  (merge {:description nil
          :id          nil
          :table_id    nil}
         (-> col
             (set/rename-keys  {:base-type    :base_type
                                :field-id     :id
                                :field-name   :name
                                :special-type :special_type
                                :table-id     :table_id})
             (dissoc :position))))

(defn post-annotate [qp]
  (fn [query]

        (trace-lvars "*" out)
        (== out ag-field)))))

(defn- unknown-field° [field-name out]
  (all
   (== out {:base-type    :UnknownField
