-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: define repository for the Variable entity
- Loading branch information
1 parent
69c2b32
commit b16a188
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
src/backend/base/langflow/services/database/models/variable/repo.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |