def insert_uniques(self, table, columns, values):
        """
        Insert multiple rows into a table that do not already exist.

        If the rows primary key already exists, the rows values will be updated.
        If the rows primary key does not exists, a new row will be inserted
        """
        # Rows that exist in the table
        existing_rows = self.select(table, columns)

        # Rows that DO NOT exist in the table
        unique = diff(existing_rows, values, y_only=True)  # Get values that are not in existing_rows

        # Keys that exist in the table
        keys = self.get_primary_key_vals(table)

        # Primary key's column index
        pk_col = self.get_primary_key(table)
        pk_index = columns.index(pk_col)

        # Split list of unique rows into list of rows to update and rows to insert
        to_insert, to_update = [], []
        for index, row in enumerate(unique):
            # Primary key is not in list of pk values, insert new row
            if row[pk_index] not in keys:
                to_insert.append(unique[index])

            # Primary key exists, update row rather than insert
            elif row[pk_index] in keys:
                to_update.append(unique[index])

        # Insert new rows
        if len(to_insert) > 0:
            self.insert_many(table, columns, to_insert)

        # Update existing rows
        if len(to_update) > 0:
            self.update_many(table, columns, to_update, pk_col, 0)

        # No inserted or updated rows
        if len(to_insert) < 1 and len(to_update) < 0:
            self._printer('No rows added to', table)
def insert_uniques ( self , table , columns , values ) : existing_rows = self . select ( table , columns ) unique = diff ( existing_rows , values , y_only = True ) keys = self . get_primary_key_vals ( table ) pk_col = self . get_primary_key ( table ) pk_index = columns . index ( pk_col ) to_insert , to_update = [ ] , [ ] for index , row in enumerate ( unique ) : if row [ pk_index ] not in keys : to_insert . append ( unique [ index ] ) elif row [ pk_index ] in keys : to_update . append ( unique [ index ] ) if len ( to_insert ) > 0 : self . insert_many ( table , columns , to_insert ) if len ( to_update ) > 0 : self . update_many ( table , columns , to_update , pk_col , 0 ) if len ( to_insert ) < 1 and len ( to_update ) < 0 : self . _printer ( 'No rows added to' , table )
Insert multiple rows into a table that do not already exist.

        If the rows primary key already exists, the rows values will be updated.
        If the rows primary key does not exists, a new row will be inserted