コード例 #1
0
    def find_by_primary_key(self, key_fields, field_list=None):
        '''

        :param key_fields: The list with the values for the key_columns, in order, to use to find a record.
        :param field_list: A subset of the fields of the record to return.
        :return: None, or a dictionary containing the requested fields for the record identified
            by the key.
        '''
        if Helper.is_empty(self._data['key_columns']):
            self._logger.error('Table has no primary keys')
            raise Exception

        if not Helper.are_key_fields_valid(key_fields,
                                           self._data['key_columns']):
            self._logger.error('Key fields are not valid')
            raise Exception

        template = Helper.convert_key_fields_to_template(
            key_fields, self._data['key_columns'])
        result = self.find_by_template(template, field_list, 1)

        if Helper.is_empty(result):
            return None

        return result[0]
コード例 #2
0
    def delete_by_key(self, key_fields):
        '''

        Deletes the record that matches the key.

        :param template: A template.
        :return: A count of the rows deleted.
        '''
        if Helper.is_empty(self._data['key_columns']):
            self._logger.error('Table has no primary keys')
            raise Exception

        if not Helper.are_key_fields_valid(key_fields,
                                           self._data['key_columns']):
            self._logger.error('Key fields are not valid')
            raise Exception

        template = Helper.convert_key_fields_to_template(
            key_fields, self._data['key_columns'])
        return self.delete_by_template(template)
コード例 #3
0
    def update_by_key(self, key_fields, new_values):
        '''

        :param key_fields: List of value for the key fields.
        :param new_values: A dict of field:value to set for updated row.
        :return: Number of rows updated.
        '''
        if Helper.is_empty(self._data['key_columns']):
            self._logger.error('Table has no primary keys')
            raise Exception

        if not Helper.are_key_fields_valid(key_fields,
                                           self._data['key_columns']):
            self._logger.error('Key fields are not valid')
            raise Exception

        if Helper.is_empty(new_values):
            return 0

        template = Helper.convert_key_fields_to_template(
            key_fields, self._data['key_columns'])
        return self.update_by_template(template, new_values)