python类ARRAY的实例源码

test_sa_validator.py 文件源码 项目:aiohttp_admin 作者: aio-libs 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def table():

    meta = sa.MetaData()
    post = sa.Table(
        'post', meta,
        sa.Column('id', sa.Integer, nullable=False),
        sa.Column('title', sa.String(200), nullable=False),
        sa.Column('body', sa.Text, nullable=False),
        sa.Column('views', sa.Integer, nullable=False),
        sa.Column('average_note', sa.Float, nullable=False),
        sa.Column('pictures', postgresql.JSON, server_default='{}'),
        sa.Column('published_at', sa.Date, nullable=False),
        sa.Column('tags', postgresql.ARRAY(sa.Integer), server_default='[]'),

        # Indexes #
        sa.PrimaryKeyConstraint('id', name='post_id_pkey'))
    return post
test_asserts.py 文件源码 项目:deb-python-sqlalchemy-utils 作者: openstack 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def User(Base):
    class User(Base):
        __tablename__ = 'user'
        id = sa.Column('_id', sa.Integer, primary_key=True)
        name = sa.Column('_name', sa.String(20))
        age = sa.Column('_age', sa.Integer, nullable=False)
        email = sa.Column(
            '_email', sa.String(200), nullable=False, unique=True
        )
        fav_numbers = sa.Column('_fav_numbers', ARRAY(sa.Integer))

        __table_args__ = (
            sa.CheckConstraint(sa.and_(age >= 0, age <= 150)),
            sa.CheckConstraint(
                sa.and_(
                    sa.func.array_length(fav_numbers, 1) <= 8
                )
            )
        )
    return User
20160509115712_icdcm_create_table.py 文件源码 项目:collectors 作者: opentrials 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def upgrade():
    op.create_table('icdcm',

        # Meta

        sa.Column('meta_id', sa.Text, unique=True),
        sa.Column('meta_source', sa.Text),
        sa.Column('meta_created', sa.DateTime(timezone=True)),
        sa.Column('meta_updated', sa.DateTime(timezone=True)),

        # General

        sa.Column('name', sa.Text, primary_key=True),
        sa.Column('desc', sa.Text),
        sa.Column('terms', ARRAY(sa.Text)),
        sa.Column('version', sa.Text),
        sa.Column('last_updated', sa.Date),

    )
9a83475c60c3_add_favorites_user_ids.py 文件源码 项目:FRG-Crowdsourcing 作者: 97amarnathk 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def upgrade():
    op.add_column('task', sa.Column(field, postgresql.ARRAY(sa.Integer)))
4f12d8650050_add_results_table.py 文件源码 项目:FRG-Crowdsourcing 作者: 97amarnathk 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def upgrade():
    op.create_table(
        'result',
        sa.Column('id', sa.Integer, primary_key=True),
        sa.Column('created', sa.Text, default=make_timestamp),
        sa.Column('project_id', sa.Integer, sa.ForeignKey('project.id'), nullable=False),
        sa.Column('task_id', sa.Integer, sa.ForeignKey('task.id'), nullable=False),
        sa.Column('task_run_ids', ARRAY(sa.Integer), nullable=False),
        sa.Column('last_version', sa.Boolean, default=True),
        sa.Column('info', JSON)
    )
61e52d26ebea_message_blacklist.py 文件源码 项目:pushkin 作者: Nordeus 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def upgrade():
    context = op.get_context()
    connection = op.get_bind()

    op.create_table('message_blacklist',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('login_id', sa.BigInteger(), nullable=False),
        sa.Column('blacklist', postgresql.ARRAY(sa.Integer)),
        sa.ForeignKeyConstraint(['login_id'], ['login.id'], ondelete='CASCADE', name="ref_message_blacklist_login_id_to_login"),
        sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('idx_message_blacklist_login_id'), 'message_blacklist', ['login_id'], unique=True)
array.py 文件源码 项目:ShelbySearch 作者: Agentscreech 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def Any(other, arrexpr, operator=operators.eq):
    """A synonym for the :meth:`.ARRAY.Comparator.any` method.

    This method is legacy and is here for backwards-compatibility.

    .. seealso::

        :func:`.expression.any_`

    """

    return arrexpr.any(other, operator)
array.py 文件源码 项目:ShelbySearch 作者: Agentscreech 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def All(other, arrexpr, operator=operators.eq):
    """A synonym for the :meth:`.ARRAY.Comparator.all` method.

    This method is legacy and is here for backwards-compatibility.

    .. seealso::

        :func:`.expression.all_`

    """

    return arrexpr.all(other, operator)
array.py 文件源码 项目:ShelbySearch 作者: Agentscreech 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __init__(self, clauses, **kw):
        super(array, self).__init__(*clauses, **kw)
        self.type = ARRAY(self.type)
b07014167199_.py 文件源码 项目:heutagogy-backend 作者: heutagogy 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def upgrade():
    op.add_column('bookmark', sa.Column('tags', postgresql.ARRAY(sa.Text()), nullable=True))
fd28e46e46a6_.py 文件源码 项目:doorman 作者: mwielgoszewski 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('rule',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('type', sa.String(), nullable=False),
    sa.Column('name', sa.String(), nullable=False),
    sa.Column('action', sa.Enum('added', 'removed', 'both', name='rule_actions'), nullable=False),
    sa.Column('alerters', postgresql.ARRAY(sa.String()), nullable=False),
    sa.Column('config', postgresql.JSONB(), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    ### end Alembic commands ###
array.py 文件源码 项目:Price-Comparator 作者: Thejas-1 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def Any(other, arrexpr, operator=operators.eq):
    """A synonym for the :meth:`.ARRAY.Comparator.any` method.

    This method is legacy and is here for backwards-compatibility.

    .. seealso::

        :func:`.expression.any_`

    """

    return arrexpr.any(other, operator)
array.py 文件源码 项目:Price-Comparator 作者: Thejas-1 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def All(other, arrexpr, operator=operators.eq):
    """A synonym for the :meth:`.ARRAY.Comparator.all` method.

    This method is legacy and is here for backwards-compatibility.

    .. seealso::

        :func:`.expression.all_`

    """

    return arrexpr.all(other, operator)
array.py 文件源码 项目:Price-Comparator 作者: Thejas-1 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def __init__(self, clauses, **kw):
        super(array, self).__init__(*clauses, **kw)
        self.type = ARRAY(self.type)
sa_utils.py 文件源码 项目:aiohttp_admin 作者: aio-libs 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def build_trafaret(sa_type, **kwargs):

    if isinstance(sa_type, sa.sql.sqltypes.Enum):
        trafaret = t.Enum(*sa_type.enums, **kwargs)

    # check for Text should be before String
    elif isinstance(sa_type, sa.sql.sqltypes.Text):
        trafaret = t.String(**kwargs)

    elif isinstance(sa_type, sa.sql.sqltypes.String):
        trafaret = t.String(max_length=sa_type.length, **kwargs)

    elif isinstance(sa_type, sa.sql.sqltypes.Integer):
        trafaret = t.Int(**kwargs)

    elif isinstance(sa_type, sa.sql.sqltypes.Float):
        trafaret = t.Float(**kwargs)

    elif isinstance(sa_type, sa.sql.sqltypes.DateTime):
        trafaret = DateTime(**kwargs)  # RFC3339

    elif isinstance(sa_type, sa.sql.sqltypes.Date):
        trafaret = DateTime(**kwargs)  # RFC3339

    elif isinstance(sa_type, sa.sql.sqltypes.Boolean):
        trafaret = t.StrBool(**kwargs)

    # Add PG related JSON and ARRAY
    elif isinstance(sa_type, postgresql.JSON):
        trafaret = AnyDict | t.List(AnyDict)

    # Add PG related JSON and ARRAY
    elif isinstance(sa_type, postgresql.ARRAY):
        item_trafaret = build_trafaret(sa_type.item_type)
        trafaret = t.List(item_trafaret)

    else:
        type_ = str(sa_type)
        msg = 'Validator for type {} not implemented'.format(type_)
        raise NotImplementedError(msg)
    return trafaret
4b3c2ca23454_identity_scopes.py 文件源码 项目:zeus 作者: getsentry 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column(
        'identity',
        sa.Column(
            'scopes',
            postgresql.ARRAY(
                sa.String(
                    length=64)),
            nullable=True))
    # ### end Alembic commands ###
array.py 文件源码 项目:webapp 作者: superchilli 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def Any(other, arrexpr, operator=operators.eq):
    """A synonym for the :meth:`.ARRAY.Comparator.any` method.

    This method is legacy and is here for backwards-compatibility.

    .. seealso::

        :func:`.expression.any_`

    """

    return arrexpr.any(other, operator)
array.py 文件源码 项目:webapp 作者: superchilli 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def All(other, arrexpr, operator=operators.eq):
    """A synonym for the :meth:`.ARRAY.Comparator.all` method.

    This method is legacy and is here for backwards-compatibility.

    .. seealso::

        :func:`.expression.all_`

    """

    return arrexpr.all(other, operator)
array.py 文件源码 项目:webapp 作者: superchilli 项目源码 文件源码 阅读 48 收藏 0 点赞 0 评论 0
def __init__(self, clauses, **kw):
        super(array, self).__init__(*clauses, **kw)
        self.type = ARRAY(self.type)
16bcbf5554c2_add_draft.py 文件源码 项目:hreftoday 作者: soasme 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('draft',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=False),
    sa.Column('link_ids', postgresql.ARRAY(sa.Integer()), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('user_id', name='ux_draft_user')
    )
    ### end Alembic commands ###
test_field_mapping.py 文件源码 项目:django-rest-witchcraft 作者: shosca 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def test_get_field_type_can_map_pg_array_column(self):

        column = sqa.Column(postgresql.ARRAY(item_type=sqa.Integer()))
        field = field_mapping.get_field_type(column)

        self.assertTrue(issubclass(field, fields.ListField))
        self.assertIsInstance(field().child, fields.IntegerField)
test_field_mapping.py 文件源码 项目:django-rest-witchcraft 作者: shosca 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def test_get_field_type_pg_array_column_raises_when_item_type_not_found(self):

        class DummyType(object):
            python_type = None

        column = sqa.Column(postgresql.ARRAY(item_type=DummyType))

        with self.assertRaises(KeyError):
            field_mapping.get_field_type(column)
field_mapping.py 文件源码 项目:django-rest-witchcraft 作者: shosca 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def get_field_type(column):
    """
    Returns the field type to be used determined by the sqlalchemy column type or the column type's python type
    """
    if isinstance(column.type, sqltypes.Enum) and not column.type.enum_class:
        return fields.ChoiceField

    if isinstance(column.type, postgresql.ARRAY):
        child_field = SERIALIZER_FIELD_MAPPING.get(column.type.item_type.__class__
                                                   ) or SERIALIZER_FIELD_MAPPING.get(column.type.item_type.python_type)

        if child_field is None:
            raise KeyError("Could not figure out field for ARRAY item type '{}'".format(column.type.__class__))

        class ArrayField(fields.ListField):
            """Nested array field for PostreSQL's ARRAY type"""

            def __init__(self, *args, **kwargs):
                kwargs['child'] = child_field()
                super(ArrayField, self).__init__(*args, **kwargs)

        return ArrayField

    if column.type.__class__ in SERIALIZER_FIELD_MAPPING:
        return SERIALIZER_FIELD_MAPPING.get(column.type.__class__)

    if issubclass(column.type.python_type, bool):
        return fields.NullBooleanField if column.nullable else fields.BooleanField

    return SERIALIZER_FIELD_MAPPING.get(column.type.python_type)
array.py 文件源码 项目:QualquerMerdaAPI 作者: tiagovizoto 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def Any(other, arrexpr, operator=operators.eq):
    """A synonym for the :meth:`.ARRAY.Comparator.any` method.

    This method is legacy and is here for backwards-compatibility.

    .. seealso::

        :func:`.expression.any_`

    """

    return arrexpr.any(other, operator)
array.py 文件源码 项目:QualquerMerdaAPI 作者: tiagovizoto 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def All(other, arrexpr, operator=operators.eq):
    """A synonym for the :meth:`.ARRAY.Comparator.all` method.

    This method is legacy and is here for backwards-compatibility.

    .. seealso::

        :func:`.expression.all_`

    """

    return arrexpr.all(other, operator)
array.py 文件源码 项目:QualquerMerdaAPI 作者: tiagovizoto 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def __init__(self, clauses, **kw):
        super(array, self).__init__(*clauses, **kw)
        self.type = ARRAY(self.type)
array.py 文件源码 项目:gardenbot 作者: GoestaO 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def Any(other, arrexpr, operator=operators.eq):
    """A synonym for the :meth:`.ARRAY.Comparator.any` method.

    This method is legacy and is here for backwards-compatibility.

    .. seealso::

        :func:`.expression.any_`

    """

    return arrexpr.any(other, operator)
array.py 文件源码 项目:gardenbot 作者: GoestaO 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def All(other, arrexpr, operator=operators.eq):
    """A synonym for the :meth:`.ARRAY.Comparator.all` method.

    This method is legacy and is here for backwards-compatibility.

    .. seealso::

        :func:`.expression.all_`

    """

    return arrexpr.all(other, operator)
array.py 文件源码 项目:gardenbot 作者: GoestaO 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self, clauses, **kw):
        super(array, self).__init__(*clauses, **kw)
        self.type = ARRAY(self.type)
array.py 文件源码 项目:flask-zhenai-mongo-echarts 作者: Fretice 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def Any(other, arrexpr, operator=operators.eq):
    """A synonym for the :meth:`.ARRAY.Comparator.any` method.

    This method is legacy and is here for backwards-compatibility.

    .. seealso::

        :func:`.expression.any_`

    """

    return arrexpr.any(other, operator)


问题


面经


文章

微信
公众号

扫码关注公众号