Skip to content

Commit

Permalink
add column comment to get_columns method (#253)
Browse files Browse the repository at this point in the history
* add column comment to get_columns method

---------

Co-authored-by: Gord Thompson <gord@gordthompson.com>
  • Loading branch information
dotan-mor and gordthompson committed Sep 9, 2024
1 parent c4fe341 commit b5afb7d
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 116 deletions.
8 changes: 5 additions & 3 deletions sqlalchemy_cockroachdb/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,10 @@ def get_columns(self, conn, table_name, schema=None, **kw):
if not self._is_v191plus:
# v2.x does not have is_generated or generation_expression
sql = (
"SELECT column_name, data_type, is_nullable::bool, column_default, "
"SELECT column_name, data_type, is_nullable::bool, column_default,"
"numeric_precision, numeric_scale, character_maximum_length, "
"NULL AS is_generated, NULL AS generation_expression, is_hidden::bool "
"NULL AS is_generated, NULL AS generation_expression, is_hidden::bool,"
"column_comment AS comment "
"FROM information_schema.columns "
"WHERE table_schema = :table_schema AND table_name = :table_name "
)
Expand All @@ -200,7 +201,7 @@ def get_columns(self, conn, table_name, schema=None, **kw):
"numeric_precision, numeric_scale, character_maximum_length, "
"CASE is_generated WHEN 'ALWAYS' THEN true WHEN 'NEVER' THEN false "
"ELSE is_generated::bool END AS is_generated, "
"generation_expression, is_hidden::bool, crdb_sql_type "
"generation_expression, is_hidden::bool, crdb_sql_type, column_comment AS comment "
"FROM information_schema.columns "
"WHERE table_schema = :table_schema AND table_name = :table_name "
)
Expand Down Expand Up @@ -281,6 +282,7 @@ def get_columns(self, conn, table_name, schema=None, **kw):
default=default,
autoincrement=autoincrement,
is_hidden=row.is_hidden,
comment=row.comment,
)
if computed is not None:
column_info["computed"] = computed
Expand Down
5 changes: 5 additions & 0 deletions test/test_column_reflect.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def test_reflect_hidden_columns(self):
"default": "unique_rowid()",
"autoincrement": True,
"is_hidden": False,
"comment": None,
},
{
"name": "txt",
Expand All @@ -52,6 +53,7 @@ def test_reflect_hidden_columns(self):
"default": None,
"autoincrement": False,
"is_hidden": False,
"comment": None,
},
],
)
Expand All @@ -66,6 +68,7 @@ def test_reflect_hidden_columns(self):
"default": None,
"autoincrement": False,
"is_hidden": False,
"comment": None,
},
],
)
Expand All @@ -80,6 +83,7 @@ def test_reflect_hidden_columns(self):
"default": None,
"autoincrement": False,
"is_hidden": False,
"comment": None,
},
{
"name": "rowid",
Expand All @@ -88,6 +92,7 @@ def test_reflect_hidden_columns(self):
"default": "unique_rowid()",
"autoincrement": True,
"is_hidden": True,
"comment": None,
},
],
)
Loading

0 comments on commit b5afb7d

Please sign in to comment.