MCPcopy
hub / github.com/ormar-orm/ormar / prefixed_columns

Method prefixed_columns

ormar/relations/alias_manager.py:62–92  ·  view source on GitHub ↗

Creates a list of aliases sqlalchemy text clauses from string alias and sqlalchemy.Table. Optional list of fields to include can be passed to extract only those columns. List has to have sqlalchemy names of columns (ormar aliases) not the ormar ones. :param

(
        alias: str, table: sqlalchemy.Table, fields: Optional[list] = None
    )

Source from the content-addressed store, hash-verified

60
61 @staticmethod
62 def prefixed_columns(
63 alias: str, table: sqlalchemy.Table, fields: Optional[list] = None
64 ) -> list[Label[Any]]:
65 """
66 Creates a list of aliases sqlalchemy text clauses from
67 string alias and sqlalchemy.Table.
68
69 Optional list of fields to include can be passed to extract only those columns.
70 List has to have sqlalchemy names of columns (ormar aliases) not the ormar ones.
71
72 :param alias: alias of given table
73 :type alias: str
74 :param table: table from which fields should be aliased
75 :type table: sqlalchemy.Table
76 :param fields: fields to include
77 :type fields: Optional[list[str]]
78 :return: list of sqlalchemy text clauses with "column name as aliased name"
79 :rtype: list[text]
80 """
81 alias = f"{alias}_" if alias else ""
82 aliased_fields = [f"{alias}{x}" for x in fields] if fields else []
83 all_columns = (
84 table.columns
85 if not fields
86 else [
87 col
88 for col in table.columns
89 if col.name in fields or col.name in aliased_fields
90 ]
91 )
92 return [column.label(f"{alias}{column.name}") for column in all_columns]
93
94 def prefixed_table_name(
95 self, alias: str, table: sqlalchemy.Table

Callers 2

_process_joinMethod · 0.80

Calls 1

labelMethod · 0.80

Tested by

no test coverage detected