Spaces:
Sleeping
Sleeping
from typing import List | |
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column | |
from sqlalchemy import ForeignKey, create_engine | |
ENGINE = create_engine('sqlite:///application_dev.db') | |
class Base(DeclarativeBase): | |
pass | |
class Employee(Base): | |
__tablename__ = 'employees' | |
employee_id: Mapped[str] = mapped_column(primary_key = True) | |
email_id: Mapped[str] = mapped_column(unique = True,nullable = False) | |
first_name: Mapped[str] = mapped_column(nullable = True) | |
last_name: Mapped[str] = mapped_column(nullable = True) | |
password: Mapped[str] | |
department: Mapped[str] | |
# jobs_posted: Mapped[list["Job"]] = relationship(back_populates="jobs") | |
def __repr__(self): | |
return f'Employee({self.employee_id!r},{self.email_id!r},{self.first_name!r},{self.department!r})' | |
def full_name(self): | |
return f'{self.first_name.title()} {self.last_name.title()}' | |
class Job(Base): | |
__tablename__ = 'jobs' | |
job_id :Mapped[str] = mapped_column(primary_key = True) | |
employee_id :Mapped[str] #= mapped_column(ForeignKey('employees.employee_id')) | |
post_name: Mapped[str] = mapped_column(nullable = False) | |
description: Mapped[str] = mapped_column(nullable= False) | |
responsibilities: Mapped[str] | |
min_experience: Mapped[int] = mapped_column(nullable = False) | |
max_experience: Mapped[int] = mapped_column(nullable = False) | |
primary_skills: Mapped[str] = mapped_column(nullable = False) | |
secondary_skills: Mapped[str] = mapped_column(nullable = True) | |
vacancies: Mapped[int] = mapped_column(nullable=False) | |
# employee: Mapped["Employee"] = relationship(back_populates="employee") | |
# users_applied: Mapped[list["User"]] = relationship(back_populates="users") | |
created_at: Mapped[str] = mapped_column(nullable=False) | |
expires_at: Mapped[str] = mapped_column(nullable = False) | |
def __repr__(self): | |
return f"Job({self.job_id!r},{self.post_name!r},{self.min_experience},{self.max_experience})" | |
class User(Base): | |
__tablename__ = "users" | |
email_id: Mapped[str] = mapped_column(primary_key=True) | |
password: Mapped[str] = mapped_column(nullable=False) | |
first_name: Mapped[str] = mapped_column(nullable = False) | |
last_name: Mapped[str] = mapped_column(nullable = False) | |
def __repr__(self): | |
return f'User({self.email_id!r},{self.first_name!r},{self.last_name!r})' | |
def full_name(self): | |
return f'{self.first_name.title()} {self.last_name.title()}' | |
class JobsApplied(Base): | |
__tablename__ = 'jobs_applied' | |
email_id: Mapped[str] = mapped_column(primary_key=True) | |
job_id: Mapped[str] = mapped_column(ForeignKey('jobs.job_id')) | |
rank: Mapped[int] = mapped_column(nullable=False) | |
experience: Mapped[int] = mapped_column(nullable=False) | |
round_number: Mapped[int] = mapped_column(nullable=False) | |
primary_skills: Mapped[int] | |
secondary_skills: Mapped[int] | |
def __repr__(self): | |
return f'JobsApplied({self.email_id!r},{self.job_id!r},{self.rank},{self.experience},{self.round_number})' | |
def __create_tables(): | |
Base.metadata.create_all(bind = ENGINE) | |