Skip to content
This repository was archived by the owner on May 5, 2022. It is now read-only.

Commit 4d749cf

Browse files
committed
refactor: remove types.py
1 parent d891479 commit 4d749cf

File tree

2 files changed

+14
-71
lines changed

2 files changed

+14
-71
lines changed

sqlalchemy_trino/dialect.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from . import dbapi as trino_dbapi
1212
from . import error
1313
from . import result
14-
from . import types
1514

1615

1716
class TrinoExecutionContext(DefaultExecutionContext):
@@ -89,13 +88,13 @@ def create_connect_args(self, url: URL) -> Tuple[List[Any], Dict[str, Any]]:
8988
return args, kwargs
9089

9190
def get_columns(self, connection: Connection,
92-
table_name: str, schema: str = None, **kw) -> List[types.ColumnInfo]:
91+
table_name: str, schema: str = None, **kw) -> List[Dict[str, Any]]:
9392
full_table = self._get_full_table(table_name, schema)
9493
try:
9594
rows = self._get_table_columns(connection, full_table)
9695
columns = []
9796
for row in rows:
98-
columns.append(types.ColumnInfo(
97+
columns.append(dict(
9998
name=row.Column,
10099
type=compiler.parse_sqltype(row.Type, row.Column),
101100
nullable=getattr(row, 'Null', True),
@@ -108,18 +107,18 @@ def get_columns(self, connection: Connection,
108107
raise
109108

110109
def get_pk_constraint(self, connection: Connection,
111-
table_name: str, schema: str = None, **kw) -> types.PrimaryKeyInfo:
110+
table_name: str, schema: str = None, **kw) -> Dict[str, Any]:
112111
"""Trino has no support for primary keys. Returns a dummy"""
113-
return types.PrimaryKeyInfo(name=None, constrained_columns=[])
112+
return dict(name=None, constrained_columns=[])
114113

115114
get_primary_keys = get_pk_constraint
116115

117116
def get_foreign_keys(self, connection: Connection,
118-
table_name: str, schema: str = None, **kw) -> List[types.ForeignKeyInfo]:
117+
table_name: str, schema: str = None, **kw) -> List[Dict[str, Any]]:
119118
"""Trino has no support for foreign keys. Returns an empty list."""
120119
return []
121120

122-
def get_schema_names(self, connection: Connection, **kw):
121+
def get_schema_names(self, connection: Connection, **kw) -> List[str]:
123122
query = "SHOW SCHEMAS"
124123
res = connection.execute(sql.text(query))
125124
return [row.Schema for row in res]
@@ -151,7 +150,7 @@ def get_temp_view_names(self, connection: Connection, schema: str = None, **kw)
151150
"""Trino has no support for temporary views. Returns an empty list."""
152151
return []
153152

154-
def get_view_definition(self, connection: Connection, view_name: str, schema: str = None, **kw):
153+
def get_view_definition(self, connection: Connection, view_name: str, schema: str = None, **kw) -> str:
155154
full_view = self._get_full_table(view_name, schema)
156155
query = f"SHOW CREATE VIEW {full_view}"
157156
try:
@@ -163,16 +162,16 @@ def get_view_definition(self, connection: Connection, view_name: str, schema: st
163162
raise
164163

165164
def get_indexes(self, connection: Connection,
166-
table_name: str, schema: str = None, **kw) -> List[types.IndexInfo]:
165+
table_name: str, schema: str = None, **kw) -> List[Dict[str, Any]]:
167166
pass
168167

169168
def get_unique_constraints(self, connection: Connection,
170-
table_name: str, schema: str = None, **kw) -> List[types.UniqueConstraintInfo]:
169+
table_name: str, schema: str = None, **kw) -> List[Dict[str, Any]]:
171170
"""Trino has no support for unique constraints. Returns an empty list."""
172171
return []
173172

174173
def get_check_constraints(self, connection: Connection,
175-
table_name: str, schema: str = None, **kw) -> List[types.CheckConstraintInfo]:
174+
table_name: str, schema: str = None, **kw) -> List[Dict[str, Any]]:
176175
"""Trino has no support for check constraints. Returns an empty list."""
177176
return []
178177

@@ -209,7 +208,7 @@ def has_sequence(self, connection: Connection,
209208
"""Trino has no support for sequence. Returns False indicate that given sequence does not exists."""
210209
return False
211210

212-
def _get_server_version_info(self, connection: Connection):
211+
def _get_server_version_info(self, connection: Connection) -> Tuple[int, ...]:
213212
query = dedent("""
214213
SELECT *
215214
FROM system.runtime.nodes
@@ -219,7 +218,7 @@ def _get_server_version_info(self, connection: Connection):
219218
version = int(res.node_version)
220219
return tuple([version])
221220

222-
def _get_default_schema_name(self, connection: Connection):
221+
def _get_default_schema_name(self, connection: Connection) -> Optional[str]:
223222
dbapi_connection: trino_dbapi.Connection = connection.connection
224223
return dbapi_connection.schema
225224

@@ -244,7 +243,7 @@ def do_commit_twophase(self, connection: Connection, xid,
244243
def do_recover_twophase(self, connection: Connection) -> None:
245244
pass
246245

247-
def set_isolation_level(self, dbapi_conn: trino_dbapi.Connection, level):
246+
def set_isolation_level(self, dbapi_conn: trino_dbapi.Connection, level) -> None:
248247
dbapi_conn._isolation_level = getattr(trino_dbapi.IsolationLevel, level)
249248

250249
def get_isolation_level(self, dbapi_conn: trino_dbapi.Connection) -> str:
@@ -260,7 +259,7 @@ def _get_table_columns(connection: Connection, full_table: str):
260259
stmt = sql.text(f'SHOW COLUMNS FROM {full_table}')
261260
return connection.execute(stmt)
262261

263-
def _get_full_table(self, table_name: str, schema: str = None, quote: bool = True):
262+
def _get_full_table(self, table_name: str, schema: str = None, quote: bool = True) -> str:
264263
table_part = self.identifier_preparer.quote_identifier(table_name) if quote else table_name
265264
if schema:
266265
schema_part = self.identifier_preparer.quote_identifier(schema) if quote else schema

sqlalchemy_trino/types.py

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

0 commit comments

Comments
 (0)