mirror of
https://github.com/Paillat-dev/viralfactory.git
synced 2026-01-02 01:06:19 +00:00
Add new models and database manager
This commit is contained in:
3
src/models/Base.py
Normal file
3
src/models/Base.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from sqlalchemy.orm import declarative_base
|
||||
|
||||
Base = declarative_base()
|
||||
15
src/models/DatabaseManager.py
Normal file
15
src/models/DatabaseManager.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import os
|
||||
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import Session, sessionmaker
|
||||
|
||||
from . import Base
|
||||
|
||||
engine = create_engine(f"sqlite:///local/database/db.db")
|
||||
|
||||
SessionLocal = sessionmaker(bind=engine)
|
||||
|
||||
|
||||
def init_db():
|
||||
Base.metadata.create_all(engine)
|
||||
pass
|
||||
14
src/models/File.py
Normal file
14
src/models/File.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from . import Base
|
||||
from typing import Optional
|
||||
from sqlalchemy import String, Column, JSON, Integer
|
||||
from sqlalchemy.ext.mutable import MutableDict
|
||||
|
||||
|
||||
class File(Base):
|
||||
__tablename__ = "files"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
provider: str = Column(String, nullable=False)
|
||||
type: str = Column(String, nullable=True)
|
||||
path: str = Column(String, nullable=False)
|
||||
data: dict = Column(MutableDict.as_mutable(JSON), nullable=False, default={})
|
||||
3
src/models/__init__.py
Normal file
3
src/models/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from .Base import Base
|
||||
from .DatabaseManager import SessionLocal, init_db
|
||||
from .File import File
|
||||
Reference in New Issue
Block a user