MCPcopy Index your code
hub / github.com/piccolo-orm/piccolo / reflect

Method reflect

piccolo/table_reflection.py:94–144  ·  view source on GitHub ↗

Imports tables from the database into ``Table`` objects without hard-coding them. If a table has a reference to another table, the referenced table will be imported too. Reflection can have a performance impact based on the number of tables. If you

(
        self,
        schema_name: str = "public",
        include: Union[list[str], str, None] = None,
        exclude: Union[list[str], str, None] = None,
        keep_existing: bool = False,
    )

Source from the content-addressed store, hash-verified

92 self._schema_tables: dict[str, list[str]] = {}
93
94 async def reflect(
95 self,
96 schema_name: str = "public",
97 include: Union[list[str], str, None] = None,
98 exclude: Union[list[str], str, None] = None,
99 keep_existing: bool = False,
100 ) -> None:
101 """
102 Imports tables from the database into ``Table`` objects without
103 hard-coding them.
104
105 If a table has a reference to another table, the referenced table will
106 be imported too. Reflection can have a performance impact based on the
107 number of tables.
108
109 If you want to reflect your whole database, make sure to only do it
110 once or use the provided parameters instead of reflecting the whole
111 database every time.
112
113 :param schema_name:
114 Name of the schema you want to reflect.
115 :param include:
116 It will only reflect the specified tables. Can be a list of tables
117 or a single table.
118 :param exclude:
119 It won't reflect the specified tables. Can be a list of tables or
120 a single table.
121 :param keep_existing:
122 If True, it will exclude the available tables and reflects the
123 currently unavailable ones. Default is False.
124 :returns:
125 None
126
127 """
128 include_list = self._to_list(include)
129 exclude_list = self._to_list(exclude)
130
131 if keep_existing:
132 exclude_list += self._schema_tables.get(schema_name, [])
133
134 output_schema = await get_output_schema(
135 schema_name=schema_name,
136 include=include_list,
137 exclude=exclude_list,
138 engine=self.engine,
139 )
140 add_tables = [
141 self._add_table(schema_name=schema_name, table=table)
142 for table in output_schema.tables
143 ]
144 await asyncio.gather(*add_tables)
145
146 def clear(self) -> None:
147 """

Callers 6

get_tableMethod · 0.95

Calls 4

_to_listMethod · 0.95
_add_tableMethod · 0.95
get_output_schemaFunction · 0.90
getMethod · 0.80

Tested by 5