🔀 refactor(custom_component.py): modify get_flow method to accept keyword arguments for flow_name and flow_id to improve flexibility and readability
This commit is contained in:
parent
5de0b2d5ad
commit
566c48166e
1 changed files with 5 additions and 7 deletions
|
|
@ -158,15 +158,13 @@ class CustomComponent(Component, extra=Extra.allow):
|
||||||
flows = session.query(Flow).all()
|
flows = session.query(Flow).all()
|
||||||
return flows
|
return flows
|
||||||
|
|
||||||
def get_flow(self, flow_name: str) -> Flow:
|
def get_flow(self, *, flow_name: str = None, flow_id: str = None) -> Flow:
|
||||||
with session_getter() as session:
|
with session_getter() as session:
|
||||||
|
if flow_id:
|
||||||
|
flow = session.query(Flow).get(flow_id)
|
||||||
|
elif flow_name:
|
||||||
flow = session.query(Flow).filter(Flow.name == flow_name).first()
|
flow = session.query(Flow).filter(Flow.name == flow_name).first()
|
||||||
return flow
|
return flow
|
||||||
|
|
||||||
def get_flow_by_id(self, flow_id: str) -> Flow:
|
|
||||||
with session_getter() as session:
|
|
||||||
flow = session.query(Flow).filter(Flow.id == flow_id).first()
|
|
||||||
return flow
|
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue