Beispiel #1
0
class Genre(Base):
    __tablename__ = "genres"
    __table_args__ = {'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8'}
    id = Column(Integer, primary_key=True)
    global mysql_active
    if mysql_active:
        name = ColumnProperty(Column('name', String(1000), unique=True),
                              comparator_factory=MyComparator)
    else:
        name = ColumnProperty(Column('name', String, unique=True),
                              comparator_factory=MyComparator)
Beispiel #2
0
    def test_get_form_field_for_field(self):
        fs = SQLAlchemyModelFilterSet()

        assert isinstance(
            fs._get_form_field_for_field(
                ColumnProperty(Column('name', String(50)))), forms.CharField)
        assert isinstance(
            fs._get_form_field_for_field(
                ColumnProperty(Column('name', Integer))), forms.IntegerField)

        with pytest.raises(SkipFilter):
            fs._get_form_field_for_field(
                ColumnProperty(Column('name', TypeEngine)))
Beispiel #3
0
class Character(Base):
    __tablename__ = "characters"
    __table_args__ = {'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8'}
    id = Column(Integer, primary_key=True)
    global mysql_active
    if mysql_active:
        name = ColumnProperty(Column('name', String(1000), unique=True),
                              comparator_factory=MyComparator)
    else:
        name = ColumnProperty(Column('name', String, unique=True),
                              comparator_factory=MyComparator)

    def __repr__(self):
        out = u"<Character(id={0},name='{1}')>".format(self.id, self.name)
        return out
    def test_fail_when_a_field_type_not_found(self):
        class VehicleSerializer(ModelSerializer):
            class Meta:
                model = Vehicle
                session = session
                fields = ('paint', )

        serializer = VehicleSerializer()
        col = Column('test', types.JSON())
        prop = ColumnProperty(col)
        prop.key = col.key
        info = _column_info(prop, col)

        with self.assertRaises(KeyError):
            serializer.build_standard_field('test', info)
Beispiel #5
0
def column_property(*args, **kwargs):
    """Provide a column-level property for use with a Mapper.

    Column-based properties can normally be applied to the mapper's
    ``properties`` dictionary using the ``schema.Column`` element directly.
    Use this function when the given column is not directly present within
    the mapper's selectable; examples include SQL expressions, functions,
    and scalar SELECT queries.

    Columns that aren't present in the mapper's selectable won't be persisted
    by the mapper and are effectively "read-only" attributes.

      \*cols
          list of Column objects to be mapped.

      group
          a group name for this property when marked as deferred.

      deferred
          when True, the column property is "deferred", meaning that
          it does not load immediately, and is instead loaded when the
          attribute is first accessed on an instance.  See also
          [sqlalchemy.orm#deferred()].

    """

    return ColumnProperty(*args, **kwargs)
Beispiel #6
0
def deferred(*columns, **kwargs):
    """Return a ``DeferredColumnProperty``, which indicates this
    object attributes should only be loaded from its corresponding
    table column when first accessed.

    Used with the `properties` dictionary sent to ``mapper()``.
    """

    return ColumnProperty(deferred=True, *columns, **kwargs)
Beispiel #7
0
class Character(Base):
    __tablename__ = "characters"
    id = Column(Integer, primary_key=True)
    #name = Column(String, unique=True)
    name = ColumnProperty(Column('name', String, unique=True),
                          #comparator_factory=MyComparator
                          )

    def __repr__(self):
        out = u"<Character(id={0},name='{1}')>".format(self.id, self.name)
        return out
Beispiel #8
0
class Character(Base):
    __tablename__ = "characters"
    id = Column(Integer, primary_key=True)
    # name = Column(String, unique=True)
    name = ColumnProperty(
        Column('name', String, unique=True),
        # comparator_factory=MyComparator
    )
    comics = relationship('Comic', secondary=comics_characters_table, back_populates='characters_raw')

    def __repr__(self):
        out = u"<Character(id={0},name='{1}')>".format(self.id, self.name)
        return out
Beispiel #9
0
def column_property(*args, **kwargs):
    """Provide a column-level property for use with a Mapper.

    Column-based properties can normally be applied to the mapper's
    ``properties`` dictionary using the ``schema.Column`` element directly.
    Use this function when the given column is not directly present within the
    mapper's selectable; examples include SQL expressions, functions, and
    scalar SELECT queries.

    Columns that aren't present in the mapper's selectable won't be persisted
    by the mapper and are effectively "read-only" attributes.

      \*cols
          list of Column objects to be mapped.

      comparator_factory
        a class which extends ``sqlalchemy.orm.properties.ColumnProperty.Comparator``
        which provides custom SQL clause generation for comparison operations.

      group
          a group name for this property when marked as deferred.

      deferred
          when True, the column property is "deferred", meaning that
          it does not load immediately, and is instead loaded when the
          attribute is first accessed on an instance.  See also
          :func:`~sqlalchemy.orm.deferred`.
      
      doc
          optional string that will be applied as the doc on the
          class-bound descriptor.
          
      extension
        an :class:`~sqlalchemy.orm.interfaces.AttributeExtension` instance,
        or list of extensions, which will be prepended to the list of
        attribute listeners for the resulting descriptor placed on the class.
        These listeners will receive append and set events before the
        operation proceeds, and may be used to halt (via exception throw)
        or change the value used in the operation.

    """

    return ColumnProperty(*args, **kwargs)
Beispiel #10
0
class Genre(Base):
    __tablename__ = "genres"
    id = Column(Integer, primary_key=True)
    name = ColumnProperty(Column('name', String, unique=True),
                          comparator_factory=MyComparator)
Beispiel #11
0
class Genre(Base):
    __tablename__ = "genres"
    id = Column(Integer, primary_key=True)
    name = ColumnProperty(Column('name', String, unique=True), comparator_factory=MyComparator)
    comics = relationship('Comic', secondary=comics_genres_table, back_populates='genres_raw')