Skip to content

Add ordered keys as meta-data to the result-seq #142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
language: clojure
lein: lein
script: lein test
jdk:
- openjdk7
- openjdk6
22 changes: 11 additions & 11 deletions src/clojureql/internal.clj
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@
(transient empty)
idxs))
(rows)))))]
(rows)))
(with-meta (rows) {:column-names keys})))


(defn with-results*
Expand Down Expand Up @@ -375,7 +375,7 @@
"When supported by the JDBC driver, returns the generated keys of the latest executed statement"
(when (supports-generated-keys? (.getConnection stmt))
(let [ks (.getGeneratedKeys stmt)]
{:last-index
{:last-index
(and
(.next ks)
(.getObject ks 1))})))
Expand Down Expand Up @@ -490,14 +490,14 @@
(or alias table-name))))

(defn joins-by-table-alias
"given a list of joins return a map of joins
"given a list of joins return a map of joins
keyed by the join table-alias or,
in the case of subselects, the subselect table alias"
[joins]
(reduce #(let [{[table-name-alias join-on] :data :as join} %2
k (join-table-alias table-name-alias)]
(assoc %1 k join))
{}
(assoc %1 k join))
{}
joins))

(defn join-column-names
Expand All @@ -518,7 +518,7 @@
(concat renamed-subselect-col-strs other-col-strs))
cols))

(defn to-tbl-name
(defn to-tbl-name
"given a join definition, return a table alias
that the join depends on"
[{[table-name-alias join-on] :data :as join}]
Expand All @@ -528,25 +528,25 @@
(filter #(not= % (join-table-alias table-name-alias)))
first))

(defn to-graph-el
(defn to-graph-el
"given a join definition return an edge in the table
alias dependency graph"
[m {[table-name-alias join-on] :data :as join}]
(let [required-table (to-tbl-name join)]
(assoc m (join-table-alias table-name-alias) required-table)))

(defn add-deps
(defn add-deps
"recursively add dependencies of tbl into a list"
[map-of-joins edges tbl]
(into [(map-of-joins tbl)] (map #(add-deps map-of-joins edges %)
(filter #(= tbl (edges %))
(into [(map-of-joins tbl)] (map #(add-deps map-of-joins edges %)
(filter #(= tbl (edges %))
(keys edges)))))

(defn flatten-deps
[map-of-joins edges set-of-root-nodes]
(filter #(not (nil? %)) (flatten (map #(add-deps map-of-joins edges %) set-of-root-nodes))))

(defn sort-joins
(defn sort-joins
"sort a list of joins into dependency order"
[joins]
(let [map-of-joins (joins-by-table-alias joins)
Expand Down