Add create/drop extension #293

This commit is contained in:
Sean Corfield 2021-02-13 22:06:43 -08:00
parent 22384b9daa
commit e23502eba8
3 changed files with 20 additions and 19 deletions

View file

@ -40,6 +40,7 @@
:alter-table :add-column :drop-column :modify-column :rename-column :alter-table :add-column :drop-column :modify-column :rename-column
:add-index :drop-index :rename-table :add-index :drop-index :rename-table
:create-table :with-columns :create-view :drop-table :create-table :with-columns :create-view :drop-table
:create-extension :drop-extension
;; then SQL clauses in priority order: ;; then SQL clauses in priority order:
:nest :with :with-recursive :intersect :union :union-all :except :except-all :nest :with :with-recursive :intersect :union :union-all :except :except-all
:select :select-distinct :select-distinct-on :select :select-distinct :select-distinct-on
@ -609,9 +610,11 @@
:drop-index #'format-selector :drop-index #'format-selector
:rename-table (fn [_ x] (format-selector :rename-to x)) :rename-table (fn [_ x] (format-selector :rename-to x))
:create-table #'format-create-table :create-table #'format-create-table
:create-extension #'format-create-table
:with-columns #'format-table-columns :with-columns #'format-table-columns
:create-view #'format-create-view :create-view #'format-create-view
:drop-table #'format-drop-table :drop-table #'format-drop-table
:drop-extension #'format-drop-table
:nest (fn [_ x] (format-expr x)) :nest (fn [_ x] (format-expr x))
:with #'format-with :with #'format-with
:with-recursive #'format-with :with-recursive #'format-with

View file

@ -52,6 +52,7 @@
(defn drop-index [& args] (generic-1 :drop-index args)) (defn drop-index [& args] (generic-1 :drop-index args))
(defn rename-table [& args] (generic-1 :rename-table args)) (defn rename-table [& args] (generic-1 :rename-table args))
(defn create-table [& args] (generic :create-table args)) (defn create-table [& args] (generic :create-table args))
(defn create-extension [& args] (generic :create-extension args))
(defn with-columns [& 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])
@ -63,6 +64,7 @@
(generic :with-columns args))) (generic :with-columns args)))
(defn create-view [& args] (generic-1 :create-view args)) (defn create-view [& args] (generic-1 :create-view args))
(defn drop-table [& args] (generic :drop-table args)) (defn drop-table [& args] (generic :drop-table args))
(defn drop-extension [& args] (generic :drop-extension args))
(defn nest [& args] (generic :nest args)) (defn nest [& args] (generic :nest args))
(defn with [& args] (generic :with args)) (defn with [& args] (generic :with args))
(defn with-recursive [& args] (generic :with-recursive args)) (defn with-recursive [& args] (generic :with-recursive args))

View file

@ -24,8 +24,7 @@
#_insert-into-as #_insert-into-as
create-table rename-table drop-table create-table rename-table drop-table
window create-view over with-columns window create-view over with-columns
;; temporarily disable until these are also implemented: create-extension drop-extension
#_#_create-extension drop-extension
select-distinct-on select-distinct-on
;; already part of HoneySQL ;; already part of HoneySQL
insert-into values where select insert-into values where select
@ -314,21 +313,18 @@
(modifiers :distinct-on :a :b) (modifiers :distinct-on :a :b)
(sql/format :quoting :ansi)))))) (sql/format :quoting :ansi))))))
#_(deftest create-extension-test (deftest create-extension-test
(testing "create extension" (testing "create extension"
(is (= ["CREATE EXTENSION \"uuid-ossp\""] (is (= ["CREATE EXTENSION \"uuid-ossp\""]
(-> (create-extension :uuid-ossp) (-> (create-extension :uuid-ossp)
(sql/format :allow-dashed-names? true (sql/format {:quoted true})))))
:quoting :ansi))))) (testing "create extension if not exists"
(testing "create extension if not exists" (is (= ["CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\""]
(is (= ["CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\""] (-> (create-extension :uuid-ossp :if-not-exists? true)
(-> (create-extension :uuid-ossp :if-not-exists? true) (sql/format {:quoted true}))))))
(sql/format :allow-dashed-names? true
:quoting :ansi))))))
#_(deftest drop-extension-test (deftest drop-extension-test
(testing "create extension" (testing "create extension"
(is (= ["DROP EXTENSION \"uuid-ossp\""] (is (= ["DROP EXTENSION \"uuid-ossp\""]
(-> (drop-extension :uuid-ossp) (-> (drop-extension :uuid-ossp)
(sql/format :allow-dashed-names? true (sql/format {:quoted true}))))))
:quoting :ansi))))))