Skip to content

Commit

Permalink
add column comment to get_columns method
Browse files Browse the repository at this point in the history
  • Loading branch information
dotan-mor committed Sep 8, 2024
1 parent c4fe341 commit 726b05d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 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,"
"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, 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,
},
],
)

0 comments on commit 726b05d

Please sign in to comment.