Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add column comment to get_columns method #253

Merged
merged 5 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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