mirror of
https://github.com/Pythagora-io/gpt-pilot.git
synced 2026-01-08 12:53:50 -05:00
This is a complete rewrite of the GPT Pilot core, from the ground up, making the agentic architecture front and center, and also fixing some long-standing problems with the database architecture that weren't feasible to solve without breaking compatibility. As the database structure and config file syntax have changed, we have automatic imports for projects and current configs, see the README.md file for details. This also relicenses the project to FSL-1.1-MIT license.
48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
from typing import TYPE_CHECKING
|
|
|
|
from sqlalchemy import select
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from core.db.models import Base
|
|
|
|
if TYPE_CHECKING:
|
|
from core.db.models import File
|
|
|
|
|
|
class FileContent(Base):
|
|
__tablename__ = "file_contents"
|
|
|
|
# ID and parent FKs
|
|
id: Mapped[str] = mapped_column(primary_key=True)
|
|
|
|
# Attributes
|
|
content: Mapped[str] = mapped_column()
|
|
|
|
# Relationships
|
|
files: Mapped[list["File"]] = relationship(back_populates="content")
|
|
|
|
@classmethod
|
|
async def store(cls, session: AsyncSession, hash: str, content: str) -> "FileContent":
|
|
"""
|
|
Store the file content in the database.
|
|
|
|
If the content is already stored, returns the reference to the existing
|
|
content object. Otherwise stores it to the database and returns the newly
|
|
created content object.
|
|
|
|
:param session: The database session.
|
|
:param hash: The hash of the file content, used as an unique ID.
|
|
:param content: The file content as unicode string.
|
|
:return: The file content object.
|
|
"""
|
|
result = await session.execute(select(FileContent).where(FileContent.id == hash))
|
|
fc = result.scalar_one_or_none()
|
|
if fc is not None:
|
|
return fc
|
|
|
|
fc = cls(id=hash, content=content)
|
|
session.add(fc)
|
|
|
|
return fc
|