-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Encoding map objects to string during escaping process #13
base: master
Are you sure you want to change the base?
Conversation
@@ -104,6 +104,11 @@ defmodule Clickhousex.Codec.Values do | |||
["'", escape(param), "'"] | |||
end | |||
|
|||
defp escape(s) when is_map(s) do | |||
m = Jason.encode!(s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can it be Jason.encode_to_iodata!/1
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! Thank you for the suggestion!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't JSON iodata still need to be escaped?
With the current implementation I'm getting
Code: 62. DB::Exception: Cannot parse expression of type Object('json') here: '{\"should\":{\"'\":\"%\",\"\\\\\":\"\",\"_\":\"?\",\"it be\":\"escaped?\"}}'
for a map like
%{"should" => %{"it be" => "escaped?", "_" => "?", "'" => "%", "\\" => ""}}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the confusion. I think the previous approach with Jason.encode!
is the way to go since escaping iodata seems like too much work.
Encoding of incoming data in map format to JSON to prevent an error like those below
It happened when I tried to save data in the JSON field. The Clickhouse supports that as an experimental feature (https://clickhouse.com/docs/en/sql-reference/data-types/json/).