Skip to content

Commit

Permalink
Add tests for new cases in pg/create-table
Browse files Browse the repository at this point in the history
  • Loading branch information
Yngwarr committed Aug 2, 2023
1 parent efbdfbc commit 1bf1e49
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 25 deletions.
3 changes: 2 additions & 1 deletion deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
nrepl/nrepl {:mvn/version "1.0.0"}
refactor-nrepl/refactor-nrepl {:mvn/version "3.6.0"}

honeysql/honeysql {:mvn/version "1.0.461"}}
honeysql/honeysql {:mvn/version "1.0.461"}
lambdaisland/kaocha {:mvn/version "1.72.1136"}}

:jvm-opts ^:replace ["-XX:-OmitStackTraceInFastThrow"]}

Expand Down
22 changes: 0 additions & 22 deletions src/dsql/pg.clj
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,6 @@
(ql/to-sql opts node)
(conj "as" (ql/escape-ident opts k))))))))


(def index-keys
[[:unique acc-identity]
[:index identifier]
Expand Down Expand Up @@ -1117,13 +1116,6 @@
[])
(join-vec ",")))

(comment
(mk-columns {:a {:type "text"}
:b {:type "int" :not-null true}
:c {:type "int" :default 8}
:d {:type "timestamp" :default :current_timestamp}
:e [:uuid "not null" :default "8"]}))

(defn mk-options [options]
(->> options
(reduce-kv
Expand Down Expand Up @@ -1152,12 +1144,6 @@
(cond-> server (conj "SERVER" (name server)))
(cond-> options (conj "OPTIONS (" (mk-options options) ")"))))

(comment
(format {:ql/type :pg/create-table
:table-name "part"
:if-not-exists true
:columns {:a {:type "int" :not-null true :default 8}}}))

(defmethod ql/to-sql
:pg/drop-table
[acc opts {ex :if-exists tbl :table-name}]
Expand Down Expand Up @@ -1704,11 +1690,3 @@
:pg/columns
[acc _opts node]
(into [] (concat acc (join-vec "," (->> (rest node) (mapv parse-column))))))

(comment
(join-vec "," [[1 2] [3] [4]])
(into [] (rest [1 2 3 4]))
(format {:select [:pg/param 11] :from :user})
(format {:select [:pg/columns :a :b :c] :from :user})
(format {:select [:pg/columns :a [:b :CURRENT_TIMESTAMP] [:c 9]] :from :user})
)
17 changes: 15 additions & 2 deletions test/dsql/pg_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@
:match_tags {:type "text[]"}
:dedup_tags {:type "text[]"}}
}
["CREATE UNLOGGED TABLE IF NOT EXISTS mytable ( id text PRIMARY KEY, filelds jsonb , match_tags text[] , dedup_tags text[] )"])
["CREATE UNLOGGED TABLE IF NOT EXISTS mytable ( id text PRIMARY KEY , filelds jsonb , match_tags text[] , dedup_tags text[] )"])

(format=
{:ql/type :pg/create-table
Expand All @@ -572,7 +572,20 @@
:status [:resource_status "not null"]
:partition [:int "not null"]
:resource [:jsonb "not null"]}}
["CREATE TABLE mytable ( id uuid not null, version uuid not null, cts timestamptz not null DEFAULT current_timestamp, ts timestamptz not null DEFAULT current_timestamp, status resource_status not null, partition int not null, resource jsonb not null )"])
["CREATE TABLE mytable ( id uuid not null , version uuid not null , cts timestamptz not null DEFAULT current_timestamp , ts timestamptz not null DEFAULT current_timestamp , status resource_status not null , partition int not null , resource jsonb not null )"])

(testing "default value"
(format=
{:ql/type :pg/create-table
:table-name "mytable"
:columns {:a {:type "integer" :not-null true :default 8}}}
["CREATE TABLE mytable ( a integer NOT NULL DEFAULT ? )" 8])

(format=
{:ql/type :pg/create-table
:table-name "mytable"
:columns {:a {:type "timestamp" :not-null true :default :current_timestamp}}}
["CREATE TABLE mytable ( a timestamp NOT NULL DEFAULT current_timestamp )"]))

(testing "without columns"
(format=
Expand Down

0 comments on commit 1bf1e49

Please sign in to comment.