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

View file

@ -52,6 +52,7 @@
(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]])
;; also works in addition to (with-columns [:col-1 :definition] [:col-2 :definition])
@ -63,6 +64,7 @@
(generic :with-columns args)))
(defn create-view [& args] (generic-1 :create-view 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))

View file

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