🎉 feat(database): add database module with base and models modules
The database module has been added to the project, which includes the base and models modules. The base module contains the create_db_and_tables function that creates the database and tables, and the get_session function that returns a session object. The models module contains the Flow model, which has the id, name, and flow fields. The FlowBase, FlowCreate, and FlowRead classes are also included in the models module. These classes are used to define the schema for the Flow model.
This commit is contained in:
parent
6cacfced09
commit
4958e5030a
4 changed files with 38 additions and 0 deletions
0
src/backend/langflow/database/__init__.py
Normal file
0
src/backend/langflow/database/__init__.py
Normal file
17
src/backend/langflow/database/base.py
Normal file
17
src/backend/langflow/database/base.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
from langflow.settings import settings
|
||||
from sqlmodel import SQLModel, Session, create_engine
|
||||
|
||||
sqlite_file_name = "database.db"
|
||||
sqlite_url = f"sqlite:///{sqlite_file_name}"
|
||||
|
||||
connect_args = {"check_same_thread": False}
|
||||
engine = create_engine(sqlite_url, connect_args=connect_args)
|
||||
|
||||
|
||||
def create_db_and_tables():
|
||||
SQLModel.metadata.create_all(engine)
|
||||
|
||||
|
||||
def get_session():
|
||||
with Session(engine) as session:
|
||||
yield session
|
||||
0
src/backend/langflow/database/models/__init__.py
Normal file
0
src/backend/langflow/database/models/__init__.py
Normal file
21
src/backend/langflow/database/models/flow.py
Normal file
21
src/backend/langflow/database/models/flow.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
from typing import List
|
||||
from pydantic import BaseModel
|
||||
from sqlmodel import Field, SQLModel
|
||||
from uuid import UUID, uuid4
|
||||
|
||||
|
||||
class FlowBase(SQLModel):
|
||||
name: str = Field(index=True)
|
||||
flow: str = Field(index=False)
|
||||
|
||||
|
||||
class Flow(FlowBase, table=True):
|
||||
id: UUID = Field(default_factory=uuid4, primary_key=True, unique=True)
|
||||
|
||||
|
||||
class FlowCreate(FlowBase):
|
||||
pass
|
||||
|
||||
|
||||
class FlowRead(FlowBase):
|
||||
id: UUID
|
||||
Loading…
Add table
Add a link
Reference in a new issue