-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathdatabase.py
47 lines (39 loc) · 1.31 KB
/
database.py
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
37
38
39
40
41
42
43
44
45
46
47
from sqlalchemy import create_engine, text
import os
db_connection_string = os.environ['DB_CONNECTION_STRING']
engine = create_engine(
db_connection_string,
connect_args={
"ssl": {
"ssl_ca": "/etc/ssl/cert.pem"
}
})
def load_jobs_from_db():
with engine.connect() as conn:
result = conn.execute(text("select * from jobs"))
jobs = []
for row in result.all():
jobs.append(dict(row))
return jobs
def load_job_from_db(id):
with engine.connect() as conn:
result = conn.execute(
text("SELECT * FROM jobs WHERE id = :val"),
val=id
)
rows = result.all()
if len(rows) == 0:
return None
else:
return dict(rows[0])
def add_application_to_db(job_id, data):
with engine.connect() as conn:
query = text("INSERT INTO applications (job_id, full_name, email, linkedin_url, education, work_experience, resume_url) VALUES (:job_id, :full_name, :email, :linkedin_url, :education, :work_experience, :resume_url)")
conn.execute(query,
job_id=job_id,
full_name=data['full_name'],
email=data['email'],
linkedin_url=data['linkedin_url'],
education=data['education'],
work_experience=data['work_experience'],
resume_url=data['resume_url'])