Skip to content

Commit f1e8c07

Browse files
committed
improve coding style
1 parent b7d6e31 commit f1e8c07

File tree

1 file changed

+31
-48
lines changed

1 file changed

+31
-48
lines changed

src/snowflake/sqlalchemy/snowdialect.py

Lines changed: 31 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -319,21 +319,17 @@ def get_check_constraints(self, connection, table_name, schema, **kw):
319319

320320
@reflection.cache
321321
def _get_schema_primary_keys(self, connection, schema, table_name=None, **kw):
322-
if table_name is not None:
323-
fully_qualified_path = self._denormalize_quote_join(
324-
schema, self.denormalize_name(table_name)
325-
)
326-
result = connection.execute(
327-
text(
328-
f"SHOW /* sqlalchemy:_get_schema_primary_keys */ PRIMARY KEYS IN TABLE {fully_qualified_path}"
329-
)
330-
)
331-
else:
332-
result = connection.execute(
333-
text(
334-
f"SHOW /* sqlalchemy:_get_schema_primary_keys */PRIMARY KEYS IN SCHEMA {schema}"
335-
)
322+
fully_qualified_path = (
323+
self._denormalize_quote_join(schema, self.denormalize_name(table_name))
324+
if table_name is not None
325+
else schema
326+
)
327+
result = connection.execute(
328+
text(
329+
f"SHOW /* sqlalchemy:_get_schema_primary_keys */ PRIMARY KEYS IN "
330+
f"{'TABLE' if table_name is not None else 'SCHEMA'} {fully_qualified_path}"
336331
)
332+
)
337333
ans = {}
338334
for row in result:
339335
table_name = self.normalize_name(row._mapping["table_name"])
@@ -364,19 +360,17 @@ def get_pk_constraint(self, connection, table_name, schema=None, **kw):
364360

365361
@reflection.cache
366362
def _get_schema_unique_constraints(self, connection, schema, table_name=None, **kw):
367-
if table_name is not None:
368-
fully_qualified_path = self._denormalize_quote_join(schema, table_name)
369-
result = connection.execute(
370-
text(
371-
f"SHOW /* sqlalchemy:_get_schema_unique_constraints */ UNIQUE KEYS IN TABLE {fully_qualified_path}"
372-
)
373-
)
374-
else:
375-
result = connection.execute(
376-
text(
377-
f"SHOW /* sqlalchemy:_get_schema_unique_constraints */ UNIQUE KEYS IN SCHEMA {schema}"
378-
)
363+
fully_qualified_path = (
364+
self._denormalize_quote_join(schema, self.denormalize_name(table_name))
365+
if table_name is not None
366+
else schema
367+
)
368+
result = connection.execute(
369+
text(
370+
f"SHOW /* sqlalchemy:_get_schema_unique_constraints */ UNIQUE KEYS IN "
371+
f"{'TABLE' if table_name is not None else 'SCHEMA'} {fully_qualified_path}"
379372
)
373+
)
380374
unique_constraints = {}
381375
for row in result:
382376
name = self.normalize_name(row._mapping["constraint_name"])
@@ -415,21 +409,17 @@ def get_unique_constraints(self, connection, table_name, schema, **kw):
415409
@reflection.cache
416410
def _get_schema_foreign_keys(self, connection, schema, table_name=None, **kw):
417411
_, current_schema = self._current_database_schema(connection, **kw)
418-
if table_name is not None:
419-
fully_qualified_path = self._denormalize_quote_join(
420-
schema, self.denormalize_name(table_name)
421-
)
422-
result = connection.execute(
423-
text(
424-
f"SHOW /* sqlalchemy:_get_schema_foreign_keys */ IMPORTED KEYS IN TABLE {fully_qualified_path}"
425-
)
426-
)
427-
else:
428-
result = connection.execute(
429-
text(
430-
f"SHOW /* sqlalchemy:_get_schema_foreign_keys */ IMPORTED KEYS IN SCHEMA {schema}"
431-
)
412+
fully_qualified_path = (
413+
self._denormalize_quote_join(schema, self.denormalize_name(table_name))
414+
if table_name is not None
415+
else schema
416+
)
417+
result = connection.execute(
418+
text(
419+
f"SHOW /* sqlalchemy:_get_schema_foreign_keys */ IMPORTED KEYS IN "
420+
f"{'TABLE' if table_name is not None else 'SCHEMA'} {fully_qualified_path}"
432421
)
422+
)
433423
foreign_key_map = {}
434424
for row in result:
435425
name = self.normalize_name(row._mapping["fk_name"])
@@ -711,14 +701,7 @@ def get_columns(self, connection, table_name, schema=None, **kw):
711701
if not schema:
712702
_, schema = self._current_database_schema(connection, **kw)
713703

714-
if table_name is not None:
715-
return self._get_table_columns(connection, table_name, schema, **kw)
716-
else:
717-
schema_columns = self._get_schema_columns(connection, schema, **kw)
718-
if schema_columns is None:
719-
# Too many results, fall back to only query about single table
720-
return self._get_table_columns(connection, table_name, schema, **kw)
721-
return schema_columns[self.normalize_name(table_name)]
704+
return self._get_table_columns(connection, table_name, schema, **kw)
722705

723706
@reflection.cache
724707
def get_table_names(self, connection, schema=None, **kw):

0 commit comments

Comments
 (0)