File tree Expand file tree Collapse file tree 5 files changed +18
-10
lines changed Expand file tree Collapse file tree 5 files changed +18
-10
lines changed Original file line number Diff line number Diff line change 11# Changelog
22
3+ ## 0.7.1 : 2020-08-27
4+
5+ - ** Fix** : Use quotes in JSON column type keys in ` Property `
6+
37## 0.7.0 : 2020-08-27
48
59- ** Feature** : Now is possible to pass ` Distinct ` to ` Count ` to have ` COUNT(DISTINCT property) ` syntax in pSQL
Original file line number Diff line number Diff line change 1- from pydantic import validator
1+ from exceptions import ParseError
22
33try :
44 from typing import Literal
@@ -19,11 +19,15 @@ class Config:
1919 'description' : "Object representation of SQL column/property"
2020 }
2121
22- @validator ('name' , pre = True )
23- def escape_name (cls , v ):
24- return cls .escape (v )
25-
2622 def to_sql (self ) -> str :
23+ if '->' in self .name :
24+ bits = self .name .split ('->' )
25+ if len (bits ) != 2 :
26+ raise ParseError ("duckQL doesn't support nested JSON lookups." )
27+ self .name = f"{ self .escape (bits [0 ].strip ())} -> '{ self .escape (bits [1 ].strip ())} '"
28+ else :
29+ self .name = self .escape (self .name )
30+
2731 sql = f"{ self .name } "
2832
2933 if self .alias is not None :
Original file line number Diff line number Diff line change @@ -23,15 +23,15 @@ def test_json_field():
2323 json_property = Property (
2424 name = 'users.additional_data -> title'
2525 )
26- assert str (json_property ) == ' users.additional_data -> title'
26+ assert str (json_property ) == " users.additional_data -> ' title'"
2727
2828
2929def test_json_field_parser ():
3030 json_property = Property .parse_raw (
3131 '{"obj": "properties.Property", "name": "users.additional_data -> title", "alias": "title"}'
3232 )
33- assert json_property .name == ' users.additional_data -> title'
34- assert str (json_property ) == ' users.additional_data -> title AS "title"'
33+ assert json_property .name == " users.additional_data -> title"
34+ assert str (json_property ) == " users.additional_data -> ' title' AS \ " title\" "
3535
3636
3737def test_json_parse (valid_instance : Property ):
Original file line number Diff line number Diff line change 1- __version__ = '0.7.0 '
1+ __version__ = '0.7.1 '
Original file line number Diff line number Diff line change 11[tool .poetry ]
22name = " duckql-python"
3- version = " 0.7.0 "
3+ version = " 0.7.1 "
44description = " JSON declarative SQL conversion library"
55authors = [" Jakub Dubec <jakub.dubec@gmail.com>" ]
66license = " MIT"
You canβt perform that action at this time.
0 commit comments