From e23502eba8f5819807871de70dd4b37323601eaa Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Sat, 13 Feb 2021 22:06:43 -0800 Subject: [PATCH] Add create/drop extension #293 --- src/honey/sql.cljc | 3 +++ src/honey/sql/helpers.cljc | 2 ++ test/honey/sql/postgres_test.cljc | 34 ++++++++++++++----------------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/honey/sql.cljc b/src/honey/sql.cljc index 2c1db38..3c86e63 100644 --- a/src/honey/sql.cljc +++ b/src/honey/sql.cljc @@ -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 diff --git a/src/honey/sql/helpers.cljc b/src/honey/sql/helpers.cljc index c09177d..ada71c8 100644 --- a/src/honey/sql/helpers.cljc +++ b/src/honey/sql/helpers.cljc @@ -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)) diff --git a/test/honey/sql/postgres_test.cljc b/test/honey/sql/postgres_test.cljc index 2812fbc..3c2058b 100644 --- a/test/honey/sql/postgres_test.cljc +++ b/test/honey/sql/postgres_test.cljc @@ -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 - (testing "create extension" - (is (= ["CREATE EXTENSION \"uuid-ossp\""] - (-> (create-extension :uuid-ossp) - (sql/format :allow-dashed-names? true - :quoting :ansi))))) - (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)))))) +(deftest create-extension-test + (testing "create extension" + (is (= ["CREATE EXTENSION \"uuid-ossp\""] + (-> (create-extension :uuid-ossp) + (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 {:quoted true})))))) -#_(deftest drop-extension-test - (testing "create extension" - (is (= ["DROP EXTENSION \"uuid-ossp\""] - (-> (drop-extension :uuid-ossp) - (sql/format :allow-dashed-names? true - :quoting :ansi)))))) +(deftest drop-extension-test + (testing "create extension" + (is (= ["DROP EXTENSION \"uuid-ossp\""] + (-> (drop-extension :uuid-ossp) + (sql/format {:quoted true}))))))