Skip to content

Commit

Permalink
Fix long and double in jackson
Browse files Browse the repository at this point in the history
  • Loading branch information
Aitem committed Jan 4, 2024
1 parent fcb374e commit 7e1564e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/dsql/pg.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(:require [dsql.core :as ql]
[jsonista.core :as json]
[clojure.string :as str])
(:import [com.fasterxml.jackson.databind.node ObjectNode ArrayNode TextNode IntNode BooleanNode]
(:import [com.fasterxml.jackson.databind.node ObjectNode ArrayNode TextNode IntNode BooleanNode DoubleNode LongNode]
[com.fasterxml.jackson.databind JsonNode ObjectMapper]
[java.util Iterator])
(:refer-clojure :exclude [format]))
Expand Down Expand Up @@ -412,13 +412,16 @@
(.writeValueAsString object-mapper json))

(defn jackson-param [acc v] (conj acc ["?" (to-json-string v)]))
(defn jackson-param-as-text [acc ^JsonNode v] (conj acc ["?" (.asText v)]))
(defn jackson-param-as-text [acc ^JsonNode v]
(conj acc ["?" (.asText v)]))

(defmethod ql/to-sql ObjectNode [acc opts v] (jackson-param acc v))
(defmethod ql/to-sql ArrayNode [acc opts v] (jackson-param acc v))
(defmethod ql/to-sql TextNode [acc opts v] (jackson-param-as-text acc v))
(defmethod ql/to-sql IntNode [acc opts v] (jackson-param-as-text acc v))
(defmethod ql/to-sql BooleanNode [acc opts v] (jackson-param-as-text acc v))
(defmethod ql/to-sql DoubleNode [acc opts v] (jackson-param-as-text acc v))
(defmethod ql/to-sql LongNode [acc opts v] (jackson-param-as-text acc v))



Expand Down
6 changes: 5 additions & 1 deletion test/dsql/pg_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
(def r
{:id "fd209869-1f1c-42eb-b0bf-b5942370452c"
:meta_partition 123
:long 1234567890123
:double 123.123
:birthDate "1991-11-08"
:name [{:given "Ibragim"}]
:deceasedBoolean false
Expand All @@ -61,9 +63,11 @@
:into :patient
:value (to-jackson r)
:returning :*}
["INSERT INTO patient ( \"id\", \"meta_partition\", \"birthDate\", \"name\", \"deceasedBoolean\", \"extension\" ) VALUES ( ? , ? , ? , ? , ? , ? ) RETURNING *"
["INSERT INTO patient ( \"id\", \"meta_partition\", \"long\", \"double\", \"birthDate\", \"name\", \"deceasedBoolean\", \"extension\" ) VALUES ( ? , ? , ? , ? , ? , ? , ? , ? ) RETURNING *"
"fd209869-1f1c-42eb-b0bf-b5942370452c"
"123"
"1234567890123"
"123.123"
"1991-11-08"
"[{\"given\":\"Ibragim\"}]"
"false"
Expand Down

0 comments on commit 7e1564e

Please sign in to comment.