-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
33 lines (23 loc) · 1.17 KB
/
models.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
from flask_sqlalchemy import SQLAlchemy
from werkzeug.security import generate_password_hash, check_password_hash
db = SQLAlchemy()
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
first_name = db.Column(db.String(50), nullable=False)
last_name = db.Column(db.String(50), nullable=False)
email = db.Column(db.String(100), unique=True, nullable=False)
password = db.Column(db.String(200), nullable=False)
def set_password(self, password):
self.password = generate_password_hash(password, method='sha256')
def check_password(self, password):
return check_password_hash(self.password, password)
def __repr__(self):
return f'<User {self.email}>'
# 소켓 통신을 위한 데이터베이스 모델 추가 (테이블) => 소캣 통신에서 Http프로토콜 이용한 통신으로 전향
# 차이는 연결형 => 비연결형 / TCP => UDP로 전향
class Log(db.Model):
id = db.Column(db.Integer, primary_key=True)
data = db.Column(db.String(500), nullable=False)
timestamp = db.Column(db.DateTime, default=db.func.current_timestamp())
def __repr__(self):
return f'<Log {self.data[:20]}...>'