Skip to content

Commit be7788c

Browse files
committed
Move code to datatype.py
1 parent 20f41d2 commit be7788c

File tree

3 files changed

+18
-30
lines changed

3 files changed

+18
-30
lines changed

tests/integration/test_sqlalchemy_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import sqlalchemy as sqla
1414
from sqlalchemy.sql import and_, or_, not_
1515

16-
from trino.sqlalchemy.types import JSON
16+
from trino.sqlalchemy.datatype import JSON
1717

1818

1919
@pytest.fixture

trino/sqlalchemy/datatype.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1010
# See the License for the specific language governing permissions and
1111
# limitations under the License.
12+
import json
1213
import re
1314
from typing import Iterator, List, Optional, Tuple, Type, Union, Dict, Any
1415

1516
from sqlalchemy import util
1617
from sqlalchemy.sql import sqltypes
17-
from sqlalchemy.sql.type_api import TypeEngine
18+
from sqlalchemy.sql.type_api import TypeDecorator, TypeEngine
19+
from sqlalchemy.types import String
1820

1921
SQLType = Union[TypeEngine, Type[TypeEngine]]
2022

@@ -71,6 +73,19 @@ def __init__(self, precision=None, timezone=False):
7173
self.precision = precision
7274

7375

76+
class JSON(TypeDecorator):
77+
impl = String
78+
79+
def process_bind_param(self, value, dialect):
80+
return json.dumps(value)
81+
82+
def process_result_value(self, value, dialect):
83+
return json.loads(value)
84+
85+
def get_col_spec(self, **kw):
86+
return 'JSON'
87+
88+
7489
# https://trino.io/docs/current/language/types.html
7590
_type_map = {
7691
# === Boolean ===
@@ -90,7 +105,7 @@ def __init__(self, precision=None, timezone=False):
90105
"varchar": sqltypes.VARCHAR,
91106
"char": sqltypes.CHAR,
92107
"varbinary": sqltypes.VARBINARY,
93-
"json": sqltypes.JSON,
108+
"json": JSON,
94109
# === Date and time ===
95110
"date": sqltypes.DATE,
96111
"time": TIME,

trino/sqlalchemy/types.py

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)