def new_object(self, client_id, account):
        sql = "INSERT INTO accounts VALUES (DEFAULT,%s,%s) RETURNING *"

        cursor = connection.cursor()
        cursor.execute(sql, (client_id, account.value))
        connection.commit()
        record = cursor.fetchone()
        return Account(record[0], record[1], record[2])
    def update_object(self, change):
        sql = "UPDATE accounts SET value=%s WHERE account_id=%s RETURNING *"

        cursor = connection.cursor()
        cursor.execute(sql, (change.value, change.account_id))
        connection.commit()

        return ""
예제 #3
0
    def new_object(self, client, null=None):
        sql = "INSERT INTO clients VALUES (DEFAULT,%s,%s) RETURNING *"

        cursor = connection.cursor()
        cursor.execute(sql, (client.username, client.password))
        connection.commit()
        record = cursor.fetchone()
        return Client(record[0], record[1], record[2])
예제 #4
0
    def update_object(self, change):
        sql = "UPDATE clients SET username=%s,password=%s WHERE client_id=%s RETURNING *"

        cursor = connection.cursor()
        cursor.execute(sql,
                       (change.username, change.password, change.client_id))
        connection.commit()

        return ""
    def get_object(self, client_id, account_id):
        sql = "SELECT * FROM accounts WHERE client_id = %s and account_id = %s"
        cursor = connection.cursor()
        cursor.execute(sql, (client_id, account_id))

        record = cursor.fetchone()

        if record:
            return Account(record[0], record[1], record[2])
        else:
            raise AccountNotFound(f"Account with ID {account_id} not found for Client with ID {client_id}.")
예제 #6
0
    def delete_object(self, client_id, null=None):
        try:
            ClientDAO.get_object(self, client_id)
        except ClientNotFound as c:
            raise c

        sql = "DELETE FROM clients WHERE client_id = %s"

        cursor = connection.cursor()
        cursor.execute(sql, [client_id])
        connection.commit()
예제 #7
0
    def get_object(self, client_id, null=None):
        sql = "SELECT * FROM clients WHERE client_id = %s"
        cursor = connection.cursor()
        cursor.execute(sql, [client_id])

        record = cursor.fetchone()

        if record:
            return Client(record[0], record[1], record[2])
        else:
            raise ClientNotFound(f"Client with ID {client_id} not found.")
    def delete_object(self, client_id, account_id):
        try:
            account = AccountDAO().get_object(client_id, account_id)
        except AccountNotFound as a:
            raise a

        sql = "DELETE FROM accounts WHERE client_id = %s and account_id = %s"
        cursor = connection.cursor()
        cursor.execute(sql, (client_id, account_id))
        connection.commit()

        return ""
    def get_all_objects_from_client(client_id):
        sql = "SELECT * FROM accounts WHERE client_id=%s"
        cursor = connection.cursor()
        cursor.execute(sql, [client_id])
        records = cursor.fetchall()

        account_list = []
        for record in records:
            account = Account(record[0], record[1], record[2])
            account_list.append(account.json())

        return account_list
예제 #10
0
    def get_all_objects(self):
        sql = "SELECT * FROM accounts"
        cursor = connection.cursor()
        cursor.execute(sql)
        records = cursor.fetchall()

        account_list = []
        for record in records:
            account = Account(record[0], record[1], record[2])
            account_list.append(account.json())

        return account_list