Skip to content

Commit

Permalink
AS expression
Browse files Browse the repository at this point in the history
  • Loading branch information
Aitem committed Nov 1, 2023
1 parent 1181f28 commit 09ca3bb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/dsql/pg.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1445,6 +1445,14 @@
(conj "resource ||")
(ql/reduce-separated2 "||" (fn [acc expr] (ql/to-sql acc opts expr)) exprs)))

(defmethod ql/to-sql
:as
[acc opts [_ expr alias]]
(-> acc
(ql/to-sql opts expr)
(conj "AS")
(conj alias)))

(defmethod ql/to-sql
:->>
[acc opts [_ col k]]
Expand Down
11 changes: 11 additions & 0 deletions test/dsql/pg_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@

(deftest test-dsql-pgi

(testing "insert params"
(format=
{:ql/type :pg/insert
:into :patient
:as :p
:value {:id [:pg/param "id"] :gender [:pg/param "male"]}
:returning [:as [:pg/jsonb_strip_nulls [:pg/cast ^:pg/fn[:row_to_json :p.*] :jsonb]] "row"]}

["INSERT INTO patient AS p ( \"id\", \"gender\" ) VALUES ( ? , ? ) RETURNING jsonb_strip_nulls( ( row_to_json( p.* ) )::jsonb ) AS row"
"id" "male"]))

(testing "insert params"
(format=
{:ql/type :pg/insert
Expand Down

0 comments on commit 09ca3bb

Please sign in to comment.