              (throw err#))))))
 
 
-(defn query [& {:keys [kind ancestor filter sort keys-only?
-                       count-only? in-transaction?
-                       limit offset
-                       start-cursor end-cursor ; TODO: Implement this.
-                       prefetch-size chunk-size]
-                :or {keys-only? false, filter [[]], sort [[]],
-                     count-only? false, in-transaction? false}}]
-  (let [query-object (make-query-object kind ancestor filter sort keys-only?)
+(defn query* [kind ancestor filters sorts keys-only?
+              count-only? in-transaction?
+              limit offset
+              start-cursor end-cursor
+              prefetch-size chunk-size]
+  (let [query-object (make-query-object kind ancestor filters sorts keys-only?)
         fetch-options-object (make-fetch-options-object limit offset prefetch-size chunk-size)
         prepared-query (if (and in-transaction? *current-transaction*)
                            (.prepare (get-datastore-service) *current-transaction*

(defonce *datastore-implicit-transaction-policy-map*
  {:auto ImplicitTransactionManagementPolicy/AUTO
   :none ImplicitTransactionManagementPolicy/NONE})


(defonce *filter-operator-map*
  {:eq Query$FilterOperator/EQUAL
   :gt Query$FilterOperator/GREATER_THAN
   :ge Query$FilterOperator/GREATER_THAN_OR_EQUAL
   :in Query$FilterOperator/IN
   :lt Query$FilterOperator/LESS_THAN
   :le Query$FilterOperator/LESS_THAN_OR_EQUAL
   :ne Query$FilterOperator/NOT_EQUAL})


(defonce *sort-direction-map*
  {:ascending Query$SortDirection/ASCENDING
   :asc Query$SortDirection/ASCENDING
   :descending Query$SortDirection/DESCENDING
   :dsc Query$SortDirection/DESCENDING
   :desc Query$SortDirection/DESCENDING})




    (if count-only?
        (.countEntities prepared-query)
        (seq (.asIterable prepared-query fetch-options-object)))))


(defmacro query [& {:keys [kind ancestor filter sort keys-only?
                           count-only? in-transaction?
                           limit offset
                           start-cursor end-cursor ; TODO: Implement this.
                           prefetch-size chunk-size]
                    :or {keys-only? false, filter [], sort [],
                         count-only? false, in-transaction? false}}]
  ;; Normalize :filter and :sort keywords (into lists, even if only one is gen),
  ;; then turn them into QueryFilter and QuerySort objects.
  (let [filter (if (every? sequential? filter) filter (vector filter))
        filter `(list ~@(map (fn [[op k v]] `(list (keyword '~op) ~k ~v)) filter))
        sort (if (sequential? sort) sort (vector sort))]
    `(let [filter# (map (fn [[sym# prop-kw# prop-val#]]
                          (QueryFilter. (condp = sym#
                                            := Query$FilterOperator/EQUAL
                                            :> Query$FilterOperator/GREATER_THAN
                                            :>= Query$FilterOperator/GREATER_THAN_OR_EQUAL
                                            :in Query$FilterOperator/IN
                                            :< Query$FilterOperator/LESS_THAN
                                            :<= Query$FilterOperator/LESS_THAN_OR_EQUAL
                                            :! Query$FilterOperator/NOT_EQUAL
                                            :!= Query$FilterOperator/NOT_EQUAL
                                            :<> Query$FilterOperator/NOT_EQUAL)
                                        prop-kw# prop-val#))
                        ~filter)
           sort# (map (fn [sort-spec#]
                        (if (sequential? sort-spec#)
                            (let [[sort-property# sort-dir-spec#] sort-spec#
                                  sort-dir# (condp = sort-dir-spec#
                                                :asc Query$SortDirection/ASCENDING
                                                :ascending Query$SortDirection/ASCENDING
                                                :dsc Query$SortDirection/DESCENDING
                                                :desc Query$SortDirection/DESCENDING
                                                :descending Query$SortDirection/DESCENDING)]
                              (QuerySort. sort-property# sort-dir#))
                            (QuerySort. sort-spec# Query$SortDirection/ASCENDING)))
                      ~sort)]
       (query* ~kind ~ancestor filter# sort# ~keys-only?
               ~count-only? ~in-transaction?
               ~limit ~offset
               ~start-cursor ~end-cursor
               ~prefetch-size ~chunk-size))))
