def update()

in asfpy/sqlite.py [0:0]


    def update(self, table: str, document: dict, **target):
        """
        Updates one or more rows in a table where the target key/value pair matches
        Example:
            update('accounts', { 'name': 'jane doe', 'password': '1245' }, user_id='janedoe')
            would update any rows where user_id is 'janedoe' and set name and password.
        @param table: The table to edit
        @param document: The document, as a dict, to update (target values)
        @param target: The search key/value pair for finding the right document.
        """
        if not target:
            raise AsfpyDBError("UPDATE must have at one defined target to specify the row to update")
        k, v = next(iter(target.items()))
        items = document.items()  # Use the same ordering for keys/values
        columns = ", ".join("%s = ?" % uk for uk, uv in items)
        statement = f'UPDATE {table} SET {columns} WHERE {k} = ?;'
        values = [uv for uk, uv in items]
        values.append(v)  # unique constraint
        self.runc(statement, *values)