#6: new currency stored function

This commit is contained in:
Dominik Pantůček 2025-04-20 19:15:23 +02:00
parent 8f42145bee
commit 9235607d4c
3 changed files with 54 additions and 3 deletions

View file

@ -42,7 +42,7 @@ class Account:
""" Constructor for new account """
# id = db.execute_and_fetch("INSERT INTO accounts (name, currency, acctype) VALUES (%s, %s, %s) RETURNING id", [name, currency.id, acctype])
id = db.execute_and_fetch("SELECT public.create_account(%s, %s, %s)", [name, currency.id, acctype])
id = id[0]
# id = id[0]
return cls(db, name = name, id = id, currency = currency, acctype = acctype)
def balance(self):

View file

@ -31,8 +31,9 @@ class Currency:
@classmethod
def create(cls, db, name):
""" Constructor for new currency """
id = db.execute_and_fetch("INSERT INTO currencies (name) VALUES (%s) RETURNING id", [name])
id = id[0]
# id = db.execute_and_fetch("INSERT INTO currencies (name) VALUES (%s) RETURNING id", [name])
id = db.execute_and_fetch("SELECT public.create_currency(%s)", [name])
# id = id[0]
return cls(db, name = name, id = id)
def rates(self, other):