Reformatting to prepare for docstring addition
This commit is contained in:
parent
78fe59d98c
commit
f84726a48b
1 changed files with 234 additions and 60 deletions
|
|
@ -3,7 +3,9 @@
|
||||||
(ns honey.sql.helpers
|
(ns honey.sql.helpers
|
||||||
"Helper functions for the built-in clauses in honey.sql."
|
"Helper functions for the built-in clauses in honey.sql."
|
||||||
(:refer-clojure :exclude [update set group-by for partition-by])
|
(:refer-clojure :exclude [update set group-by for partition-by])
|
||||||
(:require [honey.sql :as h]))
|
(:require [honey.sql]))
|
||||||
|
|
||||||
|
;; implementation helpers:
|
||||||
|
|
||||||
(defn- default-merge [current args]
|
(defn- default-merge [current args]
|
||||||
(into (vec current) args))
|
(into (vec current) args))
|
||||||
|
|
@ -43,17 +45,50 @@
|
||||||
(assoc data k arg)
|
(assoc data k arg)
|
||||||
(assoc {} k data)))
|
(assoc {} k data)))
|
||||||
|
|
||||||
(defn alter-table [& args] (generic :alter-table args))
|
;; for every clause, there is a public helper
|
||||||
(defn add-column [& args] (generic :add-column args))
|
|
||||||
(defn drop-column [& args] (generic-1 :drop-column args))
|
(defn alter-table
|
||||||
(defn modify-column [& args] (generic :modify-column args))
|
[& args]
|
||||||
(defn rename-column [& args] (generic :rename-column args))
|
(generic :alter-table args))
|
||||||
(defn add-index [& args] (generic :add-index args))
|
|
||||||
(defn drop-index [& args] (generic-1 :drop-index args))
|
(defn add-column
|
||||||
(defn rename-table [& args] (generic-1 :rename-table args))
|
[& args]
|
||||||
(defn create-table [& args] (generic :create-table args))
|
(generic :add-column args))
|
||||||
(defn create-extension [& args] (generic :create-extension args))
|
|
||||||
(defn with-columns [& args]
|
(defn drop-column
|
||||||
|
[& args]
|
||||||
|
(generic-1 :drop-column args))
|
||||||
|
|
||||||
|
(defn modify-column
|
||||||
|
[& args]
|
||||||
|
(generic :modify-column args))
|
||||||
|
|
||||||
|
(defn rename-column
|
||||||
|
[& args]
|
||||||
|
(generic :rename-column args))
|
||||||
|
|
||||||
|
(defn add-index
|
||||||
|
[& args]
|
||||||
|
(generic :add-index args))
|
||||||
|
|
||||||
|
(defn drop-index
|
||||||
|
[& args]
|
||||||
|
(generic-1 :drop-index args))
|
||||||
|
|
||||||
|
(defn rename-table
|
||||||
|
[& args]
|
||||||
|
(generic-1 :rename-table args))
|
||||||
|
|
||||||
|
(defn create-table
|
||||||
|
[& args]
|
||||||
|
(generic :create-table args))
|
||||||
|
|
||||||
|
(defn create-extension
|
||||||
|
[& args]
|
||||||
|
(generic :create-extension args))
|
||||||
|
|
||||||
|
(defn with-columns
|
||||||
|
[& args]
|
||||||
;; special case so (with-columns [[:col-1 :definition] [:col-2 :definition]])
|
;; special case so (with-columns [[:col-1 :definition] [:col-2 :definition]])
|
||||||
;; also works in addition to (with-columns [:col-1 :definition] [:col-2 :definition])
|
;; also works in addition to (with-columns [:col-1 :definition] [:col-2 :definition])
|
||||||
(cond (and (= 1 (count args)) (sequential? (first args)) (sequential? (ffirst args)))
|
(cond (and (= 1 (count args)) (sequential? (first args)) (sequential? (ffirst args)))
|
||||||
|
|
@ -62,59 +97,198 @@
|
||||||
(generic-1 :with-columns args)
|
(generic-1 :with-columns args)
|
||||||
:else
|
:else
|
||||||
(generic :with-columns args)))
|
(generic :with-columns args)))
|
||||||
(defn create-view [& args] (generic-1 :create-view args))
|
|
||||||
(defn drop-table [& args] (generic :drop-table args))
|
(defn create-view
|
||||||
(defn drop-extension [& args] (generic :drop-extension args))
|
[& args]
|
||||||
(defn nest [& args] (generic :nest args))
|
(generic-1 :create-view args))
|
||||||
(defn with [& args] (generic :with args))
|
|
||||||
(defn with-recursive [& args] (generic :with-recursive args))
|
(defn drop-table
|
||||||
|
[& args]
|
||||||
|
(generic :drop-table args))
|
||||||
|
|
||||||
|
(defn drop-extension
|
||||||
|
[& args]
|
||||||
|
(generic :drop-extension args))
|
||||||
|
|
||||||
|
(defn nest
|
||||||
|
[& args]
|
||||||
|
(generic :nest args))
|
||||||
|
|
||||||
|
(defn with
|
||||||
|
[& args]
|
||||||
|
(generic :with args))
|
||||||
|
|
||||||
|
(defn with-recursive
|
||||||
|
[& args]
|
||||||
|
(generic :with-recursive args))
|
||||||
|
|
||||||
;; these five need to supply an empty hash map since they wrap
|
;; these five need to supply an empty hash map since they wrap
|
||||||
;; all of their arguments:
|
;; all of their arguments:
|
||||||
(defn intersect [& args] (generic :intersect (cons {} args)))
|
(defn intersect
|
||||||
(defn union [& args] (generic :union (cons {} args)))
|
[& args]
|
||||||
(defn union-all [& args] (generic :union-all (cons {} args)))
|
(generic :intersect (cons {} args)))
|
||||||
(defn except [& args] (generic :except (cons {} args)))
|
|
||||||
(defn except-all [& args] (generic :except-all (cons {} args)))
|
|
||||||
|
|
||||||
(defn select [& args] (generic :select args))
|
(defn union
|
||||||
(defn select-distinct [& args] (generic :select-distinct args))
|
[& args]
|
||||||
(defn select-distinct-on [& args] (generic :select-distinct-on args))
|
(generic :union (cons {} args)))
|
||||||
(defn insert-into [& args] (generic :insert-into args))
|
|
||||||
(defn update [& args] (generic :update args))
|
(defn union-all
|
||||||
(defn delete [& args] (generic-1 :delete args))
|
[& args]
|
||||||
(defn delete-from [& args] (generic :delete-from args))
|
(generic :union-all (cons {} args)))
|
||||||
(defn truncate [& args] (generic :truncate args))
|
|
||||||
(defn columns [& args] (generic :columns args))
|
(defn except
|
||||||
(defn set [& args] (generic-1 :set args))
|
[& args]
|
||||||
(defn from [& args] (generic :from args))
|
(generic :except (cons {} args)))
|
||||||
(defn using [& args] (generic :using args))
|
|
||||||
(defn join [& args] (generic :join args))
|
(defn except-all
|
||||||
(defn left-join [& args] (generic :left-join args))
|
[& args]
|
||||||
(defn right-join [& args] (generic :right-join args))
|
(generic :except-all (cons {} args)))
|
||||||
(defn inner-join [& args] (generic :inner-join args))
|
|
||||||
(defn outer-join [& args] (generic :outer-join args))
|
(defn select
|
||||||
(defn full-join [& args] (generic :full-join args))
|
[& args]
|
||||||
(defn cross-join [& args] (generic :cross-join args))
|
(generic :select args))
|
||||||
(defn where [& args] (generic :where args))
|
|
||||||
(defn group-by [& args] (generic :group-by args))
|
(defn select-distinct
|
||||||
(defn having [& args] (generic :having args))
|
[& args]
|
||||||
(defn window [& args] (generic :window args))
|
(generic :select-distinct args))
|
||||||
(defn partition-by [& args] (generic :partition-by args))
|
|
||||||
(defn order-by [& args] (generic :order-by args))
|
(defn select-distinct-on
|
||||||
(defn limit [& args] (generic-1 :limit args))
|
[& args]
|
||||||
(defn offset [& args] (generic-1 :offset args))
|
(generic :select-distinct-on args))
|
||||||
(defn for [& args] (generic-1 :for args))
|
|
||||||
(defn values [& args] (generic-1 :values args))
|
(defn insert-into
|
||||||
(defn on-conflict [& args] (generic-1 :on-conflict args))
|
[& args]
|
||||||
(defn on-constraint [& args] (generic :on-constraint args))
|
(generic :insert-into args))
|
||||||
(defn do-nothing [& args] (generic :do-nothing args))
|
|
||||||
(defn do-update-set [& args] (generic :do-update-set args))
|
(defn update
|
||||||
(defn returning [& args] (generic :returning args))
|
[& args]
|
||||||
|
(generic :update args))
|
||||||
|
|
||||||
|
(defn delete
|
||||||
|
[& args]
|
||||||
|
(generic-1 :delete args))
|
||||||
|
|
||||||
|
(defn delete-from
|
||||||
|
[& args]
|
||||||
|
(generic :delete-from args))
|
||||||
|
|
||||||
|
(defn truncate
|
||||||
|
[& args]
|
||||||
|
(generic :truncate args))
|
||||||
|
|
||||||
|
(defn columns
|
||||||
|
[& args]
|
||||||
|
(generic :columns args))
|
||||||
|
|
||||||
|
(defn set
|
||||||
|
[& args]
|
||||||
|
(generic-1 :set args))
|
||||||
|
|
||||||
|
(defn from
|
||||||
|
[& args]
|
||||||
|
(generic :from args))
|
||||||
|
|
||||||
|
(defn using
|
||||||
|
[& args]
|
||||||
|
(generic :using args))
|
||||||
|
|
||||||
|
(defn join
|
||||||
|
[& args]
|
||||||
|
(generic :join args))
|
||||||
|
|
||||||
|
(defn left-join
|
||||||
|
[& args]
|
||||||
|
(generic :left-join args))
|
||||||
|
|
||||||
|
(defn right-join
|
||||||
|
[& args]
|
||||||
|
(generic :right-join args))
|
||||||
|
|
||||||
|
(defn inner-join
|
||||||
|
[& args]
|
||||||
|
(generic :inner-join args))
|
||||||
|
|
||||||
|
(defn outer-join
|
||||||
|
[& args]
|
||||||
|
(generic :outer-join args))
|
||||||
|
|
||||||
|
(defn full-join
|
||||||
|
[& args]
|
||||||
|
(generic :full-join args))
|
||||||
|
|
||||||
|
(defn cross-join
|
||||||
|
[& args]
|
||||||
|
(generic :cross-join args))
|
||||||
|
|
||||||
|
(defn where
|
||||||
|
[& args]
|
||||||
|
(generic :where args))
|
||||||
|
|
||||||
|
(defn group-by
|
||||||
|
[& args]
|
||||||
|
(generic :group-by args))
|
||||||
|
|
||||||
|
(defn having
|
||||||
|
[& args]
|
||||||
|
(generic :having args))
|
||||||
|
|
||||||
|
(defn window
|
||||||
|
[& args]
|
||||||
|
(generic :window args))
|
||||||
|
|
||||||
|
(defn partition-by
|
||||||
|
[& args]
|
||||||
|
(generic :partition-by args))
|
||||||
|
|
||||||
|
(defn order-by
|
||||||
|
[& args]
|
||||||
|
(generic :order-by args))
|
||||||
|
|
||||||
|
(defn limit
|
||||||
|
[& args]
|
||||||
|
(generic-1 :limit args))
|
||||||
|
|
||||||
|
(defn offset
|
||||||
|
[& args]
|
||||||
|
(generic-1 :offset args))
|
||||||
|
|
||||||
|
(defn for
|
||||||
|
[& args]
|
||||||
|
(generic-1 :for args))
|
||||||
|
|
||||||
|
(defn values
|
||||||
|
[& args]
|
||||||
|
(generic-1 :values args))
|
||||||
|
|
||||||
|
(defn on-conflict
|
||||||
|
[& args]
|
||||||
|
(generic-1 :on-conflict args))
|
||||||
|
|
||||||
|
(defn on-constraint
|
||||||
|
[& args]
|
||||||
|
(generic :on-constraint args))
|
||||||
|
|
||||||
|
(defn do-nothing
|
||||||
|
[& args]
|
||||||
|
(generic :do-nothing args))
|
||||||
|
|
||||||
|
(defn do-update-set
|
||||||
|
[& args]
|
||||||
|
(generic :do-update-set args))
|
||||||
|
|
||||||
|
(defn returning
|
||||||
|
[& args]
|
||||||
|
(generic :returning args))
|
||||||
|
|
||||||
;; helpers that produce non-clause expressions -- must be listed below:
|
;; helpers that produce non-clause expressions -- must be listed below:
|
||||||
(defn composite [& args] (into [:composite] args))
|
(defn composite
|
||||||
|
[& args]
|
||||||
|
(into [:composite] args))
|
||||||
|
|
||||||
;; to make this easy to use in a select, wrap it so it becomes a function:
|
;; to make this easy to use in a select, wrap it so it becomes a function:
|
||||||
(defn over [& args] [(into [:over] args)])
|
(defn over
|
||||||
|
[& args]
|
||||||
|
[(into [:over] args)])
|
||||||
|
|
||||||
;; this helper is intended to ease the migration from nilenso:
|
;; this helper is intended to ease the migration from nilenso:
|
||||||
(defn upsert
|
(defn upsert
|
||||||
|
|
@ -133,6 +307,6 @@
|
||||||
do-update-set))))))
|
do-update-set))))))
|
||||||
|
|
||||||
#?(:clj
|
#?(:clj
|
||||||
(assert (= (clojure.core/set (conj @@#'h/base-clause-order
|
(assert (= (clojure.core/set (conj @@#'honey.sql/base-clause-order
|
||||||
:composite :over :upsert))
|
:composite :over :upsert))
|
||||||
(clojure.core/set (map keyword (keys (ns-publics *ns*)))))))
|
(clojure.core/set (map keyword (keys (ns-publics *ns*)))))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue