Replies: 12 comments
-
Consider also:
|
Beta Was this translation helpful? Give feedback.
-
Good ones! |
Beta Was this translation helpful? Give feedback.
-
On the other hand, I love how extendable FastCRUD class is. I was able to easily override So while flexible FastCRUD is great and highly boosts flexibility of the EndpointCreater, at some point I started wondering if it would be good to incentivize users to override That's probably very conceptual discussion for far future, as the CRUD part is the focus for now, but I'm curious about your thoughts. |
Beta Was this translation helpful? Give feedback.
-
Totally agree with you, @JakNowy, I think the goal is: if a solution is more complex than just overriding |
Beta Was this translation helpful? Give feedback.
-
SQLAlchemy2 provides comprehensive list of supported operators. We might pick those which we consider worth supporting. I could volunteer on working on that, I'm just not sure how we would like to tackle cases like distinct() and group_by(). For the endpoint creator, I've issued a PR. It's just a general demonstration, not finished yet, I'm looking forward to hearing your thoughts. I could finalize that after addressing the issue of SQLAlchemy operators and getting aligned on what you'd like to see. |
Beta Was this translation helpful? Give feedback.
-
Sounds good to me. We may leave the harder stuff aside until it's necessary, maybe by then we'll have a clearer path ahead.
To be honest, I'm not sure I understood exactly where it's headed. Is the Idea for |
Beta Was this translation helpful? Give feedback.
-
Exactly, that's the idea. Let's say in 75% cases generic CRUD will be sufficient. In other 25% cases, user should be able to override the statement (eg. to perform some joins or complex filters). To be honest I thought all the improvements we make in the FastCRUD also apply to EndpointCreator and I was surprised to see that we only support generic |
Beta Was this translation helpful? Give feedback.
-
Also the concept of my |
Beta Was this translation helpful? Give feedback.
-
That is the idea eventually, but I'm prioritizing improving
I think it's a good way to overcome while we're not applying this stuff do |
Beta Was this translation helpful? Give feedback.
-
We could if we wanted to apply a filter or something like it to all endpoints at once. |
Beta Was this translation helpful? Give feedback.
-
Sounds reasonable to me. I think that's something for you to think about and make a final design decision. When it comes to this issue, I'm going to implement it this week, also including |
Beta Was this translation helpful? Give feedback.
-
Sure. I think the class EndpointCreator:
def __init__(self, model, db_session: AsyncSession, query_configs=None):
self.model = model
self.db_session = db_session
self.query_configs = query_configs or {}
def default_read_item_query(self):
return select(self.model)
def default_read_item_query(self):
return self.default_base_query()
def default_create_item_query(self):
return self.default_base_query()
def default_update_item_query(self):
return self.default_base_query()
def default_delete_item_query(self):
return self.default_base_query()
def get_base_query(self, operation_type):
if operation_type in self.query_configs:
return self.query_configs[operation_type]
else:
return getattr(self, f"default_{operation_type}_query")()
def _read_item(self):
"""Creates an endpoint for reading a single item from the database."""
@apply_model_pk(**self._primary_keys_types)
async def endpoint(db: AsyncSession = Depends(self.session), **pkeys):
base_query = self.get_base_query('read_item')
for key, value in pkeys.items():
base_query = base_query.where(getattr(self.model, key) == value)
result = await db.execute(base_query)
item = result.scalars().first()
if not item: # pragma: no cover
raise NotFoundException(detail="Item not found")
return item # pragma: no cover
return endpoint Maybe something like this. Btw, this would close #41. |
Beta Was this translation helpful? Give feedback.
-
There are a few sql things that are relevant and are currently missing from
FastCRUD
, I'll list some of them and you guys may add what I forgetdistinct
clausegroup by
like
,ilike
,between
operatorsis_
andisnot_
operatorsBeta Was this translation helpful? Give feedback.
All reactions