MCPcopy
hub / github.com/piccolo-orm/piccolo / run

Method run

piccolo/query/methods/refresh.py:147–196  ·  view source on GitHub ↗

Run it asynchronously. For example:: await my_instance.refresh().run() # or for convenience: await my_instance.refresh() Modifies the instance in place, but also returns it as a convenience.

(
        self, in_pool: bool = True, node: Optional[str] = None
    )

Source from the content-addressed store, hash-verified

145 )
146
147 async def run(
148 self, in_pool: bool = True, node: Optional[str] = None
149 ) -> Table:
150 """
151 Run it asynchronously. For example::
152
153 await my_instance.refresh().run()
154
155 # or for convenience:
156 await my_instance.refresh()
157
158 Modifies the instance in place, but also returns it as a convenience.
159
160 """
161 instance = self.instance
162
163 if not instance._exists_in_db:
164 raise ValueError("The instance doesn't exist in the database.")
165
166 pk_column = instance._meta.primary_key
167
168 primary_key_value = getattr(instance, pk_column._meta.name, None)
169
170 if primary_key_value is None:
171 raise ValueError("The instance's primary key value isn't defined.")
172
173 columns = self._columns
174 if not columns:
175 raise ValueError("No columns to fetch.")
176
177 select_columns = self._get_columns(
178 instance=self.instance, columns=columns
179 )
180
181 data_dict = (
182 await instance.__class__.select(*select_columns)
183 .where(pk_column == primary_key_value)
184 .output(nested=True, load_json=self.load_json)
185 .first()
186 .run(node=node, in_pool=in_pool)
187 )
188
189 if data_dict is None:
190 raise ValueError(
191 "The object doesn't exist in the database any more."
192 )
193
194 self._update_instance(instance=instance, data_dict=data_dict)
195
196 return instance
197
198 def __await__(self):
199 """

Callers 2

__await__Method · 0.95
run_syncMethod · 0.95

Calls 6

_get_columnsMethod · 0.95
_update_instanceMethod · 0.95
selectMethod · 0.80
firstMethod · 0.45
outputMethod · 0.45
whereMethod · 0.45

Tested by

no test coverage detected