spectra/models.py

35 lines
1.0 KiB
Python
Raw Normal View History

2024-10-20 15:26:49 -04:00
from sqlalchemy import create_engine, Column, Integer, String, DateTime, Float
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
Base = declarative_base()
class Photo(Base):
__tablename__ = 'photos'
id = Column(Integer, primary_key=True, autoincrement=True)
input_filename = Column(String, nullable=False)
thumbnail_filename = Column(String, nullable=False)
focal_length = Column(String)
aperture = Column(String)
shutter_speed = Column(String)
date_taken = Column(DateTime)
iso = Column(Integer)
width = Column(Integer)
height = Column(Integer)
highlight_color = Column(String)
orientation = Column(Integer)
2024-10-20 16:36:31 -04:00
unique_key = Column(String(16), nullable=False) # Add this line
2024-10-20 15:26:49 -04:00
engine = create_engine('sqlite:///photos.db')
2024-11-05 15:03:32 -05:00
def init_db():
try:
Base.metadata.create_all(engine)
except Exception as e:
# Tables already exist, skip creation
pass
init_db()
2024-10-20 15:26:49 -04:00
Session = sessionmaker(bind=engine)