def find_field(self, field=None, alias=None):
     """
     Finds a field by name or alias.
     @param field: string of the field name or alias, dict of {'alias': field}, or a Field instance
     @type field: str or dict or Field
     @return: The field if it is found, otherwise None
     @rtype: Field or None
     """
     if alias:
         field = alias
     field = FieldFactory(field, table=self, alias=alias)
     identifier = field.get_identifier()
     for field in self.fields:
         if field.get_identifier() == identifier:
             return field
     return None
Exemple #2
0
    def remove_field(self, field):
        """
        Removes a field from this table

        :param field: This can be a string of a field name, a dict of {'alias': field}, or
            a ``Field`` instance
        :type field: str or dict or :class:`Field <querybuilder.fields.Field>`
        """
        new_field = FieldFactory(field, )
        new_field.set_table(self)
        new_field_identifier = new_field.get_identifier()
        for field in self.fields:
            if field.get_identifier() == new_field_identifier:
                self.fields.remove(field)
                return field
        return None
 def remove_field(self, field):
     """
     Removes a field from this table
     @param field: This can be a string of a field name, a dict of {'alias': field}, or
         a ``Field`` instance
     @type field: str or dict or Field
     """
     new_field = FieldFactory(
         field,
     )
     new_field.set_table(self)
     new_field_identifier = new_field.get_identifier()
     for field in self.fields:
         if field.get_identifier() == new_field_identifier:
             self.fields.remove(field)
             return
Exemple #4
0
    def find_field(self, field=None, alias=None):
        """
        Finds a field by name or alias.

        :param field: string of the field name or alias, dict of {'alias': field}, or a Field instance
        :type field: str or dict or Field

        :returns: The field if it is found, otherwise None
        :rtype: :class:`Field <querybuilder.fields.Field>` or None
        """
        if alias:
            field = alias
        field = FieldFactory(field, table=self, alias=alias)
        identifier = field.get_identifier()
        for field in self.fields:
            if field.get_identifier() == identifier:
                return field
        return None
    def find_field(self, field=None, alias=None):
        """
        Finds a field by name or alias.

        :param field: string of the field name or alias, dict of {'alias': field}, or a Field instance
        :type field: str or dict or Field

        :returns: The field if it is found, otherwise None
        :rtype: :class:`Field <querybuilder.fields.Field>` or None
        """
        if alias:
            field = alias
        field = FieldFactory(field, table=self, alias=alias)
        identifier = field.get_identifier()
        for field in self.fields:
            if field.get_identifier() == identifier:
                return field
        return None
    def remove_field(self, field):
        """
        Removes a field from this table

        :param field: This can be a string of a field name, a dict of {'alias': field}, or
            a ``Field`` instance
        :type field: str or dict or :class:`Field <querybuilder.fields.Field>`
        """
        new_field = FieldFactory(
            field,
        )
        new_field.set_table(self)
        new_field_identifier = new_field.get_identifier()
        for field in self.fields:
            if field.get_identifier() == new_field_identifier:
                self.fields.remove(field)
                return field
        return None
    def add_field(self, field):
        """
        Adds a field to this table

        :param field: This can be a string of a field name, a dict of {'alias': field}, or
            a ``Field`` instance
        :type field: str or dict or Field
        """
        field = FieldFactory(
            field,
        )
        field.set_table(self)

        # make sure field is not already added
        field_name = field.get_name()
        for existing_field in self.fields:
            if existing_field.get_name() == field_name:
                return None

        self.before_add_field(field)
        field.before_add()

        if field.ignore is False:
            self.fields.append(field)

        return field
Exemple #8
0
    def add_field(self, field):
        """
        Adds a field to this table

        :param field: This can be a string of a field name, a dict of {'alias': field}, or
            a ``Field`` instance
        :type field: str or dict or Field
        """
        field = FieldFactory(field, )
        field.set_table(self)

        # make sure field is not already added
        field_name = field.get_name()
        for existing_field in self.fields:
            if existing_field.get_name() == field_name:
                return None

        self.before_add_field(field)
        field.before_add()

        if field.ignore is False:
            self.fields.append(field)

        return field