Пример #1
0
    def create_client(self, client):
        sql = "INSERT INTO client VALUES (DEFAULT,%s ,%s) RETURNING *"
        cursor = connection.cursor()
        cursor.execute(sql, (client.username, client.accounts))
        connection.commit()
        record = cursor.fetchone()

        return Client(record[0], record[1])
Пример #2
0
    def create_account(self, account):
        sql = "INSERT INTO account VALUES (DEFAULT,%s,%s) RETURNING *"
        cursor = connection.cursor()
        cursor.execute(sql, (account.balance, account.client_id))
        connection.commit()
        record = cursor.fetchone()

        return Account(record[0], record[1])
Пример #3
0
    def update_account(self, change):
        sql = "UPDATE account SET balance = %s WHERE account_id = %s RETURNING *"
        cursor = connection.cursor()
        cursor.execute(sql, (change.balance, change.account_id))
        connection.commit()
        record = cursor.fetchone()

        new_account = Account(record[0], float(record[1]), record[2])

        return new_account
Пример #4
0
    def update_client(self, change):
        sql = "UPDATE client SET username = %s WHERE client_id = %s RETURNING *"
        cursor = connection.cursor()
        cursor.execute(sql, (change.username, change.client_id))
        connection.commit()

        record = cursor.fetchone()
        if record:
            return Client(record[0], record[1])
        else:
            raise ResourceNotFound(
                f"Client with ID: {change.client_id} - Not Found")
Пример #5
0
 def delete_client(self, client_id):
     sql = "DELETE FROM client WHERE client_id = %s"
     cursor = connection.cursor()
     cursor.execute(sql, [client_id])
     connection.commit()
Пример #6
0
    def delete_account(self, account_id):
        sql = "DELETE FROM account WHERE account_id = %s"

        cursor = connection.cursor()
        cursor.execute(sql, [account_id])
        connection.commit()