Skip to content

Commit

Permalink
feat: define repository for the Variable entity
Browse files Browse the repository at this point in the history
  • Loading branch information
italojohnny committed Aug 25, 2024
1 parent 69c2b32 commit b16a188
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from typing import List, Optional
from sqlmodel import select
from langflow.services.database.models.variable import Variable
from langflow.services.database.models.repo import AbstractRepository


class VariableRepository(AbstractRepository):
def add(self, entity: Variable) -> Variable:
self.session.add(entity)
self.session.commit()
self.session.refresh(entity)
return entity

def get(self, id: int) -> Optional[Variable]:
return self.session.get(Variable, id)

def list(self) -> List[Variable]:
query = select(Variable)
return list(self.session.exec(query).all())

def update(self, entity: Variable) -> Variable:
self.session.add(entity)
self.session.commit()
self.session.refresh(entity)
return entity

def delete(self, id: int) -> None:
entity = self.get(id)
if entity:
self.session.delete(entity)
self.session.commit()

0 comments on commit b16a188

Please sign in to comment.