-
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 model class for entity repository
- Loading branch information
1 parent
0818d88
commit 69c2b32
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/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 abc import ABC, abstractmethod | ||
from typing import Generic, TypeVar, List, Optional | ||
from sqlmodel import SQLModel, Session | ||
|
||
|
||
T = TypeVar("T", bound=SQLModel) | ||
|
||
|
||
class AbstractRepository(ABC, Generic[T]): | ||
def __init__(self, session: Session): | ||
self.session = session | ||
|
||
@abstractmethod | ||
def add(self, entity: T) -> T: | ||
pass | ||
|
||
@abstractmethod | ||
def get(self, id: int) -> Optional[T]: | ||
pass | ||
|
||
@abstractmethod | ||
def list(self) -> List[T]: | ||
pass | ||
|
||
@abstractmethod | ||
def update(self, entity: T) -> T: | ||
pass | ||
|
||
@abstractmethod | ||
def delete(self, id: int) -> None: | ||
pass |