-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
36 lines (29 loc) · 1.11 KB
/
database.py
File metadata and controls
36 lines (29 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from sqlalchemy import create_engine, Column, Integer, String, DateTime, Boolean
from sqlalchemy.orm import declarative_base
from dotenv import load_dotenv
import os
# table definition SQLAlchemy uses to generate SQL
# This pattern is called an ORM (Object Relational Mapper)
# — it maps Python objects to database rows so you never have to write raw SQL.
# loads .env file into environment
load_dotenv()
Base = declarative_base()
class Job(Base):
__tablename__ = "jobs"
id = Column(Integer, primary_key=True)
title = Column(String)
company = Column(String)
category = Column(String)
location = Column(String)
salary = Column(String)
tags = Column(String)
url = Column(String)
is_active = Column(Boolean, default=True)
last_checked = Column(DateTime, nullable=True)
DATABASE_URL = os.getenv("DATABASE_URL")
# Create Engine and Table
engine = create_engine(DATABASE_URL)
# Reads model classes and writes the table structure
# "create_all" is safe to call on every run - skips existing tables
Base.metadata.create_all(engine)
print("Database and table created successfully")