<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def upsert(self, table: str, record: dict, create_cols: bool=False, dtypes: list=None, pks=["id"], namefields=["id"]):
 """ Upsert a record in a table """

        try:
            self.db[table].upsert(record, pks, create_cols, dtypes)
        except Exception as e:
            self.err(e, "Can not upsert data")
            return
        names = ""
        for el in namefields:
            names += " " + record[el]
        self.ok("Upserted record"+names)