Compare commits
No commits in common. "9ef8f3f5136facdf33488c4d17b7113de24d6ded" and "a704c3a0c8fcf476f9ac20a974aab6564c5baa80" have entirely different histories.
9ef8f3f513
...
a704c3a0c8
@ -39,35 +39,3 @@ def get_user_by_email(email: str):
|
|||||||
user = cursor.fetchone()
|
user = cursor.fetchone()
|
||||||
conn.close()
|
conn.close()
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
||||||
def create_habit(name: str, times: int, note: str | None=None):
|
|
||||||
now = datetime.now().isoformat()
|
|
||||||
query = (f"INSERT INTO habits (name, note, times, created_at, updated_at) VALUES ('{name}', '{note}', "
|
|
||||||
f"'{times}', '{now}', '{now}');")
|
|
||||||
conn = con3()
|
|
||||||
cursor = conn.cursor()
|
|
||||||
cursor.execute(query)
|
|
||||||
conn.commit()
|
|
||||||
conn.close()
|
|
||||||
return cursor.lastrowid
|
|
||||||
|
|
||||||
|
|
||||||
def get_habits():
|
|
||||||
query = f"SELECT * FROM habits;"
|
|
||||||
conn = con3()
|
|
||||||
cursor = conn.cursor()
|
|
||||||
cursor.execute(query)
|
|
||||||
habits = cursor.fetchone()
|
|
||||||
conn.close()
|
|
||||||
return habits
|
|
||||||
|
|
||||||
|
|
||||||
def get_habit(id: int):
|
|
||||||
query = f"SELECT * FROM habits WHERE id = {id};"
|
|
||||||
conn = con3()
|
|
||||||
cursor = conn.cursor()
|
|
||||||
cursor.execute(query)
|
|
||||||
habits = cursor.fetchone()
|
|
||||||
conn.close()
|
|
||||||
return habits
|
|
||||||
@ -2,8 +2,8 @@ CREATE TABLE IF NOT EXISTS habits
|
|||||||
(
|
(
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
name TEXT NOT NULL,
|
name TEXT NOT NULL,
|
||||||
note TEXT NULL,
|
note TEXT NOT NULL,
|
||||||
times INTEGER NOT NULL,
|
times TEXT NOT NULL,
|
||||||
created_at TEXT NOT NULL,
|
created_at TEXT NOT NULL,
|
||||||
updated_at TEXT NOT NULL
|
updated_at TEXT NOT NULL
|
||||||
);
|
);
|
||||||
|
|||||||
@ -1,28 +0,0 @@
|
|||||||
from dataclasses import dataclass
|
|
||||||
from db.SQLiteClient import create_habit, get_habits, get_habit
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class Habit:
|
|
||||||
id: int
|
|
||||||
name: str
|
|
||||||
note: str
|
|
||||||
times: int
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def create(name: str, times: int, note: str | None=None):
|
|
||||||
id = create_habit(name, note, times)
|
|
||||||
return Habit(id, name, note, times)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get(id: int):
|
|
||||||
habit = get_habit(id)
|
|
||||||
return Habit(habit[0], habit[1], habit[2], habit[3]) if habit else None
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_all():
|
|
||||||
raw_habits = get_habits()
|
|
||||||
habits = []
|
|
||||||
for habit in raw_habits:
|
|
||||||
habit = Habit(habit[0], habit[1], habit[2], habit[3])
|
|
||||||
habits.append(habit)
|
|
||||||
return habits if habits else None
|
|
||||||
@ -1,4 +1,5 @@
|
|||||||
from flask_login import UserMixin
|
from flask_login import UserMixin
|
||||||
|
|
||||||
from db.SQLiteClient import create_user, get_user, get_user_by_email
|
from db.SQLiteClient import create_user, get_user, get_user_by_email
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user