-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase_model.py
93 lines (66 loc) · 3.2 KB
/
database_model.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from app import app
db = SQLAlchemy()
app.app_context().push()
class User(db.Model):
"""A user"""
__tablename__ = 'users'
id = db.Column(db.Integer,
autoincrement = True,
primary_key = True)
name = db.Column(db.String(25), nullable = False)
phone = db.Column(db.String(25), nullable = False)
email = db.Column(db.String(50), unique = True, nullable = False)
resume_order = db.Column(db.String(30), nullable = False)
def __repr__(self):
return f'<User id={self.id} fname={self.name} email={self.email} resume_order={self.resume_order}>'
class Skill(db.Model):
"""A skill"""
__tablename__ = 'skills'
id = db.Column(db.Integer,
autoincrement = True,
primary_key = True)
name = db.Column(db.String(25), nullable = False)
proficiency = db.Column(db.String(25), unique = False, nullable = False)
logo = db.Column(db.String(30), nullable = True)
def __repr__(self):
return f'<Skill id={self.id} skill name={self.name} proficiency={self.proficiency}>'
class Experience(db.Model):
"""A experience"""
__tablename__ = 'experiences'
id = db.Column(db.Integer,
autoincrement = True,
primary_key = True)
title = db.Column(db.String(25), nullable = False)
company = db.Column(db.String(50), unique = False, nullable = False)
start_date = db.Column(db.String(30), nullable = False)
end_date = db.Column(db.String(30), nullable = False)
description = db.Column(db.String(500), nullable = False)
logo = db.Column(db.String(30), nullable = True)
def __repr__(self):
return f'<Experience id={self.id} title={self.title}, company={self.company}>'
class Education(db.Model):
"""A education"""
__tablename__ = 'educations'
id = db.Column(db.Integer,
autoincrement = True,
primary_key = True)
course = db.Column(db.String(25), nullable = False)
school = db.Column(db.String(50), unique = False, nullable = False)
start_date = db.Column(db.String(30), nullable = False)
end_date = db.Column(db.String(30), nullable = False)
grade = db.Column(db.String(25), nullable = False)
logo = db.Column(db.String(30), nullable = True)
def __repr__(self):
return f'Education id={self.id} course={self.course} school={self.school}>'
def connect_to_db(app, db_name):
"""Connect flask service to the database."""
app.config["SQLALCHEMY_DATABASE_URI"] = f"sqlite:///{db_name}"
app.config["SQLALCHEMY_ECHO"] = True
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
db.app = app
db.init_app(app)
print("Connected to the db!")
if __name__ == "__main__": #check if we run the file or import it
connect_to_db(app, "resume") #conncet the flask app to database