Skip to content

Commit

Permalink
توحيد طريقة الاستعلامات المباشرة لنموذج قواعد البيانات
Browse files Browse the repository at this point in the history
  • Loading branch information
vzool committed Nov 17, 2024
1 parent ef3309a commit 977067d
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions zakat/zakat_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2823,7 +2823,7 @@ def _track(self, unscaled_value: float | int | Decimal = 0, desc: str = '', acco
print(f"account {account} created")
if self.raw_sql:
db.execute(f'''
INSERT INTO "account" (id, hide, zakatable, created_at)
INSERT INTO account (id, hide, zakatable, created_at)
VALUES({account}, 0, 1, "{str(datetime.datetime.now())}");
''')
else:
Expand All @@ -2843,7 +2843,7 @@ def _track(self, unscaled_value: float | int | Decimal = 0, desc: str = '', acco
raise ValueError(f"The box transaction happened again in the same time({created}).")
if self.raw_sql:
db.execute(f'''
INSERT INTO "box" (account_id, record_date, capital, count, last, rest, total, created_at)
INSERT INTO box (account_id, record_date, capital, count, last, rest, total, created_at)
VALUES(
{account},
"{created}",
Expand Down Expand Up @@ -2879,13 +2879,13 @@ def _add_file(self, account: int, ref: str, path: str) -> str | None:
if self.raw_sql:
log = db.execute(f'''
SELECT id
FROM "log"
FROM log
WHERE record_date = "{ref}";
''').fetchone()
print(f'log = {log}')
if log:
db.execute(f'''
INSERT INTO "file" (log_id, record_date, path, name, created_at)
INSERT INTO file (log_id, record_date, path, name, created_at)
VALUES(
{log[0]},
"{file_ref}",
Expand Down Expand Up @@ -2915,12 +2915,12 @@ def _remove_file(self, account: int, ref: str, file_ref: str) -> bool:
if self.raw_sql:
file = db.execute(f'''
SELECT id
FROM "file"
FROM file
WHERE record_date = "{file_ref}";
''').fetchone()
if file:
db.execute(f'''
DELETE FROM "file"
DELETE FROM file
WHERE id = {file[0]};
''')
return True
Expand Down Expand Up @@ -2952,14 +2952,14 @@ def _zakatable(self, account_id: int, status: bool = None) -> bool:
if self.raw_sql:
if status is not None:
db.execute(f'''
UPDATE "account"
UPDATE account
SET zakatable = {1 if status else 0},
updated_at = "{str(datetime.datetime.now())}"
WHERE id = {account_id};
''')
account = db.execute(f'''
SELECT zakatable
FROM "account"
FROM account
WHERE id = {account_id};
''').fetchone()
if not account:
Expand Down Expand Up @@ -3231,7 +3231,7 @@ def _account_exists(self, account: int) -> bool:
if self.raw_sql:
x = db.execute(f'''
SELECT COUNT(*) > 0
FROM "account"
FROM account
WHERE id = {account};
''').fetchone()
if not x:
Expand Down Expand Up @@ -3549,11 +3549,11 @@ def _log(self, value: float, desc: str = '', account_id: int = 1, created: str =
raise ValueError(f'The created must be a str, {type(created)} was provided.')
if self.raw_sql:
db.execute(f'''
UPDATE "account"
SET balance = COALESCE(balance, 0) + {value},
count = COALESCE(count, 0) + 1,
updated_at = "{str(datetime.datetime.now())}"
WHERE id = {account_id};
UPDATE account
SET balance = COALESCE(balance, 0) + {value},
count = COALESCE(count, 0) + 1,
updated_at = "{str(datetime.datetime.now())}"
WHERE id = {account_id};
''')
else:
account = Account.get(id=account_id)
Expand All @@ -3571,7 +3571,7 @@ def _log(self, value: float, desc: str = '', account_id: int = 1, created: str =
print('created-log', created)
if self.raw_sql:
db.execute(f'''
INSERT INTO "log" (account_id, record_date, value, desc, ref, created_at)
INSERT INTO log (account_id, record_date, value, desc, ref, created_at)
VALUES(
{account_id},
"{created}",
Expand Down Expand Up @@ -3600,7 +3600,7 @@ def ref_exists(self, account_id: int, ref_type: str, ref: str) -> bool:
if self.raw_sql:
box = db.execute(f'''
SELECT COUNT(*)
FROM "box"
FROM box
WHERE account_id = {account_id} AND
record_date = "{ref}";
''').fetchone()
Expand All @@ -3612,7 +3612,7 @@ def ref_exists(self, account_id: int, ref_type: str, ref: str) -> bool:
if self.raw_sql:
log = db.execute(f'''
SELECT COUNT(*)
FROM "log"
FROM log
WHERE account_id = {account_id} AND
record_date = "{ref}";
''').fetchone()
Expand Down

0 comments on commit 977067d

Please sign in to comment.