Skip to content

Commit

Permalink
remove stray docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dwwoelfel committed Nov 26, 2024
1 parent 7f15399 commit 041c79f
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 37 deletions.
17 changes: 0 additions & 17 deletions client/www/pages/docs/instaql.md
Original file line number Diff line number Diff line change
Expand Up @@ -659,23 +659,6 @@ console.log(data)
}
```
### Comparison operators
The `where` clause supports comparison operators on fields that are indexed and have checked types.
{% callout %}
Add indexes and checked types to your attributes from the [Explorer on the the Instant dashboard](/dash?t=explorer) or from the [cli with Schema-as-code](/docs/schema).
{% /callout %}
| Operator | Description | JS equivalent |
| :------: | :----------------------: | :-----------: |
| `$gt` | greater than | `>` |
| `$lt` | less than | `<` |
| `$gte` | greater than or equal to | `>=` |
| `$lte` | less than or equal to | `<=` |
### $not
The `where` clause supports `$not` queries that will return entities that don't
Expand Down
10 changes: 7 additions & 3 deletions server/src/instant/db/datalog.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1053,13 +1053,16 @@
after]
:as _page-info}
ctes]
(tool/def-locals)
(let [[but-last [table query & opts]] (coll/split-last-vec ctes)
entity-id-col (kw table :-entity-id)
sym-component-type (component-type-of-sym named-pattern order-sym)
sym-triple-idx (get (set/map-invert idx->component-type)
sym-component-type)
order-col-name (->> sym-component-type
component-type->col-name)
;; XXX: This isn't right
order-col-name (or (->> sym-component-type
component-type->col-name)
:value-blob)

;; If they want the last N items, we need to switch the direction so that
;; we get the items from the end of the list.
Expand Down Expand Up @@ -1795,6 +1798,7 @@
```"
[{:keys [app-id missing-attr? db datalog-loader] :as ctx}
patterns]
(tool/def-locals)
(if (map? patterns)
(query-nested ctx patterns)
(let [named-patterns (->named-patterns patterns)]
Expand All @@ -1807,7 +1811,7 @@
;; Fall back to regular query if we don't have a loader
(apply send-query-single ctx (:conn-pool db) args)

(let [;; The promise that returns the result for our args
(let [ ;; The promise that returns the result for our args
this-result (promise)]
(when (add-pending! datalog-loader
(:conn-pool db)
Expand Down
82 changes: 65 additions & 17 deletions server/src/instant/db/instaql.clj
Original file line number Diff line number Diff line change
Expand Up @@ -721,43 +721,83 @@
(when (or limit first last offset before after order)
(let [{:keys [k direction]} (or order default-order)
etype-sym (attr-pat/default-level-sym etype level)
order-sym (symbol (str "?t-" level))]
order-sym (if (= "serverCreatedAt" k)
(symbol (str "?t-" level))
;; XXX: Will this work??
(attr-pat/default-level-sym k level))]

;; Only supports serverCreatedAt for the initial release
(when (and (not (:table-info ctx)) ;; byop will do its own check for ordering
(not= k "serverCreatedAt"))
(ex/throw-validation-err!
:query
(:root state)
[{:expected 'valid-order?
:in (apply conj (:in state) [:$ :order k])
:message (format "We currently only support \"serverCreatedAt\" as the sort key in the `order` clause. Got %s."
(->json k))}]))
#_(when (and (not (:table-info ctx)) ;; byop will do its own check for ordering
(not= k "serverCreatedAt"))
(ex/throw-validation-err!
:query
(:root state)
[{:expected 'valid-order?
:in (apply conj (:in state) [:$ :order k])
:message (format "We currently only support \"serverCreatedAt\" as the sort key in the `order` clause. Got %s."
(->json k))}]))

;; When we support ordering on attributes, this will be where
;; we validate that the user has indexed the attribute
(let [{attr-id :id} (attr-model/seek-by-fwd-ident-name [etype "id"] (:attrs ctx))]
(when-not attr-id
(let [{id-attr-id :id} (attr-model/seek-by-fwd-ident-name [etype "id"] (:attrs ctx))

Check warning on line 742 in server/src/instant/db/instaql.clj

View workflow job for this annotation

GitHub Actions / lint

Redundant let expression.

Check warning on line 742 in server/src/instant/db/instaql.clj

View workflow job for this annotation

GitHub Actions / lint

Redundant let expression.
order-attr (when (not= "serverCreatedAt" k)
(attr-model/seek-by-fwd-ident-name [etype k] (:attrs ctx)))]

(when (not= "serverCreatedAt" k)
(when (not order-attr)
(ex/throw-validation-err!
:query
(:root state)
[{:expected 'supported-order?
:in (apply conj (:in (:state ctx)) [:$ :order])
:message (format "There is no `%s` attribute for %s."
k etype)}])))

(when (not= "serverCreatedAt" k)
(let [errors (keep identity
[(when (:checking-data-type? order-attr)
(format "The `%s` attribute is still in the process of validating its type. It must finish before ordering by the attribute."
(attr-model/fwd-friendly-name order-attr)))
(when (:indexing? order-attr)
(format "The `%s` attribute is still in the process of indexing. It must finish before ordering by the attribute."
(attr-model/fwd-friendly-name order-attr)))
(when (not (:index? order-attr))
(format "The `%s` attribute is not indexed. Only indexed and type-checked attrs can be used to order by."
(attr-model/fwd-friendly-name order-attr)))
(when (not (:checked-data-type order-attr))
(format "The `%s` attribute is not type-checked. Only type-checked and indexed attrs can be used to order by."
(attr-model/fwd-friendly-name order-attr)))])]
(when (seq errors)
(ex/throw-validation-err!
:query
(:root state)
(map (fn [message]
[{:expected 'supported-order?
:in (apply conj (:in (:state ctx)) [:$ :order])
:message message}])
errors)))))

(when-not id-attr-id
(ex/throw-validation-err!
:query
(:root state)
[{:expected 'supported-order?
:in (apply conj (:in (:state ctx)) [:$ :order])
:message (format "There is no id attribute for %s."
etype)}]))
(when (and attr-id
(when (and id-attr-id
before
(not= attr-id (second before)))
(not= id-attr-id (second before)))
(ex/throw-validation-err!
:query
(:root state)
[{:expected 'valid-cursor?
:in (apply conj (:in (:state ctx)) [:$ :before])
:message "Invalid before cursor. The join row has the wrong attribute id."}]))

(when (and attr-id
(when (and id-attr-id
after
(not= attr-id (second after)))
(not= id-attr-id (second after)))
(ex/throw-validation-err!
:query
(:root state)
Expand All @@ -770,7 +810,13 @@
:offset offset
:direction direction
:order-sym order-sym
:pattern [:ea etype-sym attr-id '_ order-sym]
:pattern (if (= "serverCreatedAt" k)
[:ea etype-sym id-attr-id '_ order-sym]
[{:idx-key :ave
:data-type (:checked-data-type order-attr)}
etype-sym
(:id order-attr)
order-sym])
:before before
:after after})))))

Expand Down Expand Up @@ -924,13 +970,15 @@
(defn query-normal
"Generates and runs a nested datalog query, then collects the results into nodes."
[base-ctx o]
(tool/def-locals)
(tracer/with-span! {:name "instaql/query-nested"
:attributes {:app-id (:app-id base-ctx)
:forms o}}
(let [ctx (merge {:datalog-query-fn #'d/query}
base-ctx)
{:keys [patterns forms]} (instaql-query->patterns ctx o)
datalog-result ((:datalog-query-fn ctx) ctx patterns)]
(tool/def-locals)
(collect-query-results (:data datalog-result) forms))))

;; BYOP InstaQL
Expand Down

0 comments on commit 041c79f

Please sign in to comment.