-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
65 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
(ns route-craft.query-strings) | ||
|
||
;; Goal: Support JSON | ||
;; Query string encodable | ||
;; Secure | ||
|
||
#_{:where {:fk_table_id {:eq fk_table_id}} | ||
:joins {:user_id "left"} | ||
:limit limit | ||
:offset offset | ||
:columns ["id" ...] | ||
:order [{:id "asc"}]} | ||
|
||
;; OPS | ||
;; eq | ||
;; ilike | ||
;; gt | ||
;; gte | ||
;; lt | ||
;; lte | ||
;; in | ||
|
||
;; TODO: logical ops, or, and? | ||
|
||
;; table key | ||
;; db-xray | ||
;; refers-to permitted in joins | ||
;; columns only permitted OR join columns only permitted | ||
;; column checks on: | ||
;; - where | ||
;; - joins | ||
;; - columns | ||
;; - order keys | ||
;; validate order vals as asc or desc | ||
;; validate limit and offset as int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
(ns route-craft.xray-ext | ||
"Extended data given db-xray output") | ||
|
||
(defn column-names | ||
[tables table-prefix columns expand-references?] | ||
(reduce-kv | ||
(fn [acc k {:keys [refers-to]}] | ||
(let [column-key (if table-prefix | ||
(keyword (str (name table-prefix) "." (name k))) | ||
k)] | ||
(if (and expand-references? refers-to) | ||
(let [refers-to-table (first refers-to)] | ||
(apply conj acc column-key (column-names tables refers-to-table (get-in tables [refers-to-table :columns]) false))) | ||
(conj acc column-key)))) | ||
#{} | ||
columns)) | ||
|
||
(defn extend-db-xray | ||
[db-xray] | ||
(update db-xray :tables | ||
(fn [tables] | ||
(reduce-kv | ||
(fn [acc table-kw {:keys [columns] :as table}] | ||
(assoc acc table-kw | ||
(assoc table :rc/permitted-columns (column-names tables nil columns true)))) | ||
{} | ||
tables)))) |