Queries the database with the given parameters. Args: **kwargs: Field names and values for the query. Returns: List[T]: A list of instances that match the query.
(self, **kwargs)
| 202 | return instance |
| 203 | |
| 204 | def query(self, **kwargs) -> List[T]: |
| 205 | """Queries the database with the given parameters. |
| 206 | |
| 207 | Args: |
| 208 | **kwargs: Field names and values for the query. |
| 209 | |
| 210 | Returns: |
| 211 | List[T]: A list of instances that match the query. |
| 212 | """ |
| 213 | data = self._read_data()["data"] |
| 214 | if not kwargs: |
| 215 | return [self.model(**record) for record in data] # type: ignore |
| 216 | |
| 217 | filtered_data = [ |
| 218 | record |
| 219 | for record in data |
| 220 | if all(record.get(k) == v for k, v in kwargs.items()) |
| 221 | ] |
| 222 | return [self.model(**record) for record in filtered_data] # type: ignore |
| 223 | |
| 224 | def get(self, id_value: int) -> Optional[T]: |
| 225 | """Retrieves an instance from the database by its ID. |