-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
a668ef4
commit fda9585
Showing
7 changed files
with
110 additions
and
16 deletions.
There are no files selected for viewing
Empty file.
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 @@ | ||
SUB_FOLDERS = ["Trained models", "Compressed models", "Pretrained models"] |
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
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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
from netspresso.utils.db.models.project import Project | ||
from netspresso.utils.db.models.user import User | ||
from netspresso.utils.db.session import Base, engine | ||
|
||
Base.metadata.create_all(engine) | ||
|
||
|
||
__all__ = [ | ||
"Project", | ||
"User", | ||
] |
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,15 @@ | ||
from sqlalchemy import Column, Integer, String | ||
|
||
from netspresso.utils.db.generate_uuid import generate_uuid | ||
from netspresso.utils.db.mixins import TimestampMixin | ||
from netspresso.utils.db.session import Base | ||
|
||
|
||
class Project(Base, TimestampMixin): | ||
__tablename__ = "project" | ||
|
||
id = Column(Integer, primary_key=True, index=True, unique=True, autoincrement=True, nullable=False) | ||
project_id = Column(String(36), index=True, unique=True, nullable=False, default=lambda: generate_uuid(entity="project")) | ||
project_name = Column(String(30), nullable=False) | ||
user_id = Column(String(36), nullable=False) | ||
project_abs_path = Column(String(500), nullable=False) |
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,53 @@ | ||
from typing import List, Optional | ||
|
||
from sqlalchemy.orm import Session | ||
|
||
from netspresso.utils.db.models.project import Project | ||
from netspresso.utils.db.repositories.base import BaseRepository, Order | ||
|
||
|
||
class ProjectRepository(BaseRepository[Project]): | ||
def get_by_project_id(self, db: Session, project_id: str) -> Optional[Project]: | ||
project = db.query(self.model).filter(self.model.project_id == project_id) | ||
|
||
return project | ||
|
||
def _get_projects( | ||
self, | ||
db: Session, | ||
condition, | ||
start: Optional[int] = None, | ||
size: Optional[int] = None, | ||
order: Optional[Order] = None, | ||
) -> Optional[List[Project]]: | ||
ordering_func = self.choose_order_func(order) | ||
query = db.query(self.model).filter(condition) | ||
|
||
if order: | ||
query = query.order_by(ordering_func(self.model.created_at)) | ||
|
||
if start is not None and size is not None: | ||
query = query.offset(start).limit(size) | ||
|
||
projects = query.all() | ||
|
||
return projects | ||
|
||
def get_all_by_user_id( | ||
self, | ||
db: Session, | ||
user_id: str, | ||
start: Optional[int] = None, | ||
size: Optional[int] = None, | ||
order: Optional[Order] = None, | ||
) -> Optional[List[Project]]: | ||
return self._get_projects( | ||
db=db, | ||
condition=self.model.user_id == user_id, | ||
start=start, | ||
size=size, | ||
order=order, | ||
) | ||
|
||
|
||
project_repository = ProjectRepository(Project) |
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