forked from TheRareFox/amazing-race
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.py
33 lines (28 loc) · 755 Bytes
/
user.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
from flask_login import UserMixin
from db import get_db
class User(UserMixin):
def __init__(self, id_, name, email):
self.id = id_
self.name = name
self.email = email
@staticmethod
def get(user_id):
db = get_db()
user = db.execute(
"SELECT * FROM user WHERE id = ?", (user_id,)
).fetchone()
if not user:
return None
user = User(
id_=user[0], name=user[1], email=user[2]
)
return user
@staticmethod
def create(id_, name, email):
db = get_db()
db.execute(
"INSERT INTO user (id, name, email) "
"VALUES (?, ?, ?)",
(id_, name, email),
)
db.commit()