   :resource-exists?       (constantly true)
   :content-types-provided (constantly {resource-list-c-t resource-list-as-json}))
 
-
-
-
-
-
-
-;;;; The SQL query compiler implementation.
+;; ## SQL query compiler
 (defmethod compile-query->sql "="
+  "Compile an '=' predicate, the basic atom of a resource query. This will
+produce a query that selects a set of hashes matching the predicate, which
+can then be combined with connectives to build complex queries."
   [db [op path value :as term]]
   (let [count (count term)]
     (if (not (= 3 count))

(ns com.puppetlabs.cmdb.query.resource
  (:require [com.puppetlabs.utils :as utils]
            [clojure.contrib.logging :as log]

      (apply vector (format "(%s)" sql) params)))

(defn- alias-subqueries
  "Produce distinct aliases for a list of queries, suitable for a join
operation."
  [queries]
  (let [ids (range (count queries))]
    (map #(format "%s resources_%d" %1 %2) queries ids)))

(defmethod compile-query->sql "and"
  "Join a set of predicates together with an 'and' relationship, performing an
intersection (via natural join)."
  [db [op & terms]]
  {:pre [(every? vector? terms)]
   :post [(string? (first %))
