42 lines
1.1 KiB
Python
42 lines
1.1 KiB
Python
from database.db import get_connection
|
|
|
|
class Account:
|
|
@staticmethod
|
|
def all():
|
|
conn = get_connection()
|
|
cur = conn.cursor()
|
|
cur.execute("SELECT * FROM accounts")
|
|
rows = cur.fetchall()
|
|
conn.close()
|
|
return rows
|
|
|
|
@staticmethod
|
|
def create(email, password, is_active=1):
|
|
conn = get_connection()
|
|
cur = conn.cursor()
|
|
cur.execute(
|
|
"INSERT INTO accounts (email, password, is_active) VALUES (?, ?, ?)",
|
|
(email, password, is_active)
|
|
)
|
|
conn.commit()
|
|
conn.close()
|
|
|
|
@staticmethod
|
|
def update(account_id, email, password, is_active):
|
|
conn = get_connection()
|
|
cur = conn.cursor()
|
|
cur.execute(
|
|
"UPDATE accounts SET email = ?, password = ?, is_active = ? WHERE id = ?",
|
|
(email, password, is_active, account_id)
|
|
)
|
|
conn.commit()
|
|
conn.close()
|
|
|
|
@staticmethod
|
|
def delete(account_id):
|
|
conn = get_connection()
|
|
cur = conn.cursor()
|
|
cur.execute("DELETE FROM accounts WHERE id = ?", (account_id,))
|
|
conn.commit()
|
|
conn.close()
|