当前位置: 首页>>代码示例>>Python>>正文


Python sqlalchemy.ARRAY属性代码示例

本文整理汇总了Python中sqlalchemy.ARRAY属性的典型用法代码示例。如果您正苦于以下问题:Python sqlalchemy.ARRAY属性的具体用法?Python sqlalchemy.ARRAY怎么用?Python sqlalchemy.ARRAY使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在sqlalchemy的用法示例。


在下文中一共展示了sqlalchemy.ARRAY属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: upgrade

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import ARRAY [as 别名]
def upgrade():
    agentstatus.create(op.get_bind())
    kernelstatus.create(op.get_bind())
    op.add_column('agents', sa.Column('lost_at', sa.DateTime(timezone=True), nullable=True))
    op.add_column('agents', sa.Column('status', sa.Enum('ALIVE', 'LOST', 'RESTARTING', 'TERMINATED', name='agentstatus'), nullable=False))
    op.create_index(op.f('ix_agents_status'), 'agents', ['status'], unique=False)
    op.add_column('kernels', sa.Column('agent_addr', sa.String(length=128), nullable=False))
    op.add_column('kernels', sa.Column('cpu_slot', sa.Integer(), nullable=False))
    op.add_column('kernels', sa.Column('gpu_slot', sa.Integer(), nullable=False))
    op.add_column('kernels', sa.Column('mem_slot', sa.Integer(), nullable=False))
    op.add_column('kernels', sa.Column('repl_in_port', sa.Integer(), nullable=False))
    op.add_column('kernels', sa.Column('repl_out_port', sa.Integer(), nullable=False))
    op.add_column('kernels', sa.Column('stdin_port', sa.Integer(), nullable=False))
    op.add_column('kernels', sa.Column('stdout_port', sa.Integer(), nullable=False))
    op.drop_column('kernels', 'allocated_cores')
    op.add_column('kernels', sa.Column('cpu_set', sa.ARRAY(sa.Integer), nullable=True))
    op.add_column('kernels', sa.Column('gpu_set', sa.ARRAY(sa.Integer), nullable=True))
    op.alter_column('kernels', column_name='status', type_=sa.Enum(*kernelstatus_choices, name='kernelstatus'),
                    postgresql_using='status::kernelstatus') 
开发者ID:lablup,项目名称:backend.ai-manager,代码行数:21,代码来源:0f3bc98edaa0_more_status.py

示例2: downgrade

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import ARRAY [as 别名]
def downgrade():
    op.drop_column('kernels', 'stdout_port')
    op.drop_column('kernels', 'stdin_port')
    op.drop_column('kernels', 'repl_out_port')
    op.drop_column('kernels', 'repl_in_port')
    op.drop_column('kernels', 'mem_slot')
    op.drop_column('kernels', 'gpu_slot')
    op.drop_column('kernels', 'cpu_slot')
    op.drop_column('kernels', 'agent_addr')
    op.drop_index(op.f('ix_agents_status'), table_name='agents')
    op.drop_column('agents', 'status')
    op.drop_column('agents', 'lost_at')
    op.alter_column('kernels', column_name='status', type_=sa.String(length=64))
    op.add_column('kernels', sa.Column('allocated_cores', sa.ARRAY(sa.Integer), nullable=True))
    op.drop_column('kernels', 'cpu_set')
    op.drop_column('kernels', 'gpu_set')
    agentstatus.drop(op.get_bind())
    kernelstatus.drop(op.get_bind()) 
开发者ID:lablup,项目名称:backend.ai-manager,代码行数:20,代码来源:0f3bc98edaa0_more_status.py

示例3: upgrade

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import ARRAY [as 别名]
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "github_installations",
        sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
        sa.Column("account_login", sa.String(), nullable=True),
        sa.Column("account_id", sa.Integer(), nullable=True),
        sa.Column("account_url", sa.String(), nullable=True),
        sa.Column("account_type", sa.String(), nullable=True),
        sa.Column("sender_id", sa.Integer(), nullable=True),
        sa.Column("sender_login", sa.String(), nullable=True),
        sa.Column("created_at", sa.DateTime(), nullable=True),
        sa.Column(
            "repositories",
            sa.ARRAY(sa.Integer(), as_tuple=sa.ForeignKey("git_projects.id")),
            nullable=True,
        ),
        sa.PrimaryKeyConstraint("id"),
    )
    # ### end Alembic commands ### 
开发者ID:packit-service,项目名称:packit-service,代码行数:22,代码来源:d7c2f99cd14d_add_a_table_for_github_installations.py

示例4: test_arrays_pg

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import ARRAY [as 别名]
def test_arrays_pg(self, connection):
        metadata = self.metadata
        t1 = Table(
            "t",
            metadata,
            Column("x", postgresql.ARRAY(Float)),
            Column("y", postgresql.ARRAY(REAL)),
            Column("z", postgresql.ARRAY(postgresql.DOUBLE_PRECISION)),
            Column("q", postgresql.ARRAY(Numeric)),
        )
        metadata.create_all()
        connection.execute(
            t1.insert(), x=[5], y=[5], z=[6], q=[decimal.Decimal("6.4")]
        )
        row = connection.execute(t1.select()).first()
        eq_(row, ([5], [5], [6], [decimal.Decimal("6.4")])) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:18,代码来源:test_types.py

示例5: test_arrays_base

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import ARRAY [as 别名]
def test_arrays_base(self, connection):
        metadata = self.metadata
        t1 = Table(
            "t",
            metadata,
            Column("x", sqltypes.ARRAY(Float)),
            Column("y", sqltypes.ARRAY(REAL)),
            Column("z", sqltypes.ARRAY(postgresql.DOUBLE_PRECISION)),
            Column("q", sqltypes.ARRAY(Numeric)),
        )
        metadata.create_all()
        connection.execute(
            t1.insert(), x=[5], y=[5], z=[6], q=[decimal.Decimal("6.4")]
        )
        row = connection.execute(t1.select()).first()
        eq_(row, ([5], [5], [6], [decimal.Decimal("6.4")])) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:18,代码来源:test_types.py

示例6: test_array_literal_getitem_multidim

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import ARRAY [as 别名]
def test_array_literal_getitem_multidim(self):
        obj = postgresql.array(
            [postgresql.array([1, 2]), postgresql.array([3, 4])]
        )

        self.assert_compile(
            obj,
            "ARRAY[ARRAY[%(param_1)s, %(param_2)s], "
            "ARRAY[%(param_3)s, %(param_4)s]]",
        )
        self.assert_compile(
            obj[1],
            "(ARRAY[ARRAY[%(param_1)s, %(param_2)s], "
            "ARRAY[%(param_3)s, %(param_4)s]])[%(param_5)s]",
        )
        self.assert_compile(
            obj[1][0],
            "(ARRAY[ARRAY[%(param_1)s, %(param_2)s], "
            "ARRAY[%(param_3)s, %(param_4)s]])[%(param_5)s][%(param_6)s]",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:22,代码来源:test_types.py

示例7: test_array_getitem_slice_type

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import ARRAY [as 别名]
def test_array_getitem_slice_type(self):
        m = MetaData()
        arrtable = Table(
            "arrtable",
            m,
            Column("intarr", postgresql.ARRAY(Integer)),
            Column("strarr", postgresql.ARRAY(String)),
        )

        # type affinity is Array...
        is_(arrtable.c.intarr[1:3].type._type_affinity, ARRAY)
        is_(arrtable.c.strarr[1:3].type._type_affinity, ARRAY)

        # but the slice returns the actual type
        assert isinstance(arrtable.c.intarr[1:3].type, postgresql.ARRAY)
        assert isinstance(arrtable.c.strarr[1:3].type, postgresql.ARRAY) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:18,代码来源:test_types.py

示例8: test_array_plus_native_enum_create

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import ARRAY [as 别名]
def test_array_plus_native_enum_create(self):
        m = MetaData()
        t = Table(
            "t",
            m,
            Column(
                "data_1",
                self.ARRAY(postgresql.ENUM("a", "b", "c", name="my_enum_1")),
            ),
            Column(
                "data_2",
                self.ARRAY(types.Enum("a", "b", "c", name="my_enum_2")),
            ),
        )

        t.create(testing.db)
        eq_(
            set(e["name"] for e in inspect(testing.db).get_enums()),
            set(["my_enum_1", "my_enum_2"]),
        )
        t.drop(testing.db)
        eq_(inspect(testing.db).get_enums(), []) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:24,代码来源:test_types.py

示例9: upgrade

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import ARRAY [as 别名]
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('kernels', sa.Column('preopen_ports', sa.ARRAY(sa.Integer()), nullable=True))
    # ### end Alembic commands ### 
开发者ID:lablup,项目名称:backend.ai-manager,代码行数:6,代码来源:3bb80d1887d6_add_preopen_ports.py

示例10: upgrade

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import ARRAY [as 别名]
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('kernels', sa.Column('tpu_set', sa.ARRAY(sa.Integer()), nullable=True))
    op.add_column('kernels', sa.Column('tpu_slot', sa.Float(), nullable=False,
                                       server_default='0'))
    op.alter_column('kernels', 'tpu_slot', server_default=None)
    # ### end Alembic commands ### 
开发者ID:lablup,项目名称:backend.ai-manager,代码行数:9,代码来源:352fa4f88f61_add_tpu_slot_on_kernel_model.py

示例11: upgrade

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import ARRAY [as 别名]
def upgrade():
    op.add_column('kernels', sa.Column('environ', sa.ARRAY(sa.String()), nullable=True)) 
开发者ID:lablup,项目名称:backend.ai-manager,代码行数:4,代码来源:c3e74dcf1808_add_environ_to_kernels.py

示例12: _get_adapted_type

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import ARRAY [as 别名]
def _get_adapted_type(self, coltype, bind):
        compiled_type = coltype.compile(bind.dialect)
        for supercls in coltype.__class__.__mro__:
            if not supercls.__name__.startswith("_") and hasattr(supercls, "__visit_name__"):
                # Hack to fix adaptation of the Enum class which is broken since SQLAlchemy 1.2
                kw = {}
                if supercls is Enum:
                    kw["name"] = coltype.name

                new_coltype = coltype.adapt(supercls)
                for key, value in kw.items():
                    setattr(new_coltype, key, value)

                # If the adapted column type does not render the same as the original, don't
                # substitute it
                if new_coltype.compile(bind.dialect) != compiled_type:
                    # Make an exception to the rule for Float, since at least on PostgreSQL,
                    # Float can accurately represent both REAL and DOUBLE_PRECISION
                    if not isinstance(new_coltype, Float):
                        break

                if isinstance(coltype, ARRAY):
                    new_coltype.item_type = self._get_adapted_type(new_coltype.item_type, bind)

                # Stop on the first valid non-uppercase column type class
                coltype = new_coltype
                if supercls.__name__ != supercls.__name__.upper():
                    break

        return coltype 
开发者ID:thomaxxl,项目名称:safrs,代码行数:32,代码来源:codegen.py

示例13: add_imports

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import ARRAY [as 别名]
def add_imports(self, collector):
        if self.table.columns:
            collector.add_import(Column)

        for column in self.table.columns:
            collector.add_import(column.type)
            if column.server_default:
                collector.add_literal_import("sqlalchemy", "text")

            if isinstance(column.type, ARRAY):
                collector.add_import(column.type.item_type.__class__)

        for constraint in sorted(self.table.constraints, key=_get_constraint_sort_key):
            if isinstance(constraint, ForeignKeyConstraint):
                if len(constraint.columns) > 1:
                    collector.add_literal_import("sqlalchemy", "ForeignKeyConstraint")
                else:
                    collector.add_literal_import("sqlalchemy", "ForeignKey")
            elif isinstance(constraint, UniqueConstraint):
                if len(constraint.columns) > 1:
                    collector.add_literal_import("sqlalchemy", "UniqueConstraint")
            elif not isinstance(constraint, PrimaryKeyConstraint):
                collector.add_import(constraint)

        for index in self.table.indexes:
            if len(index.columns) > 1:
                collector.add_import(index) 
开发者ID:thomaxxl,项目名称:safrs,代码行数:29,代码来源:codegen.py

示例14: StringArray

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import ARRAY [as 别名]
def StringArray(
    *,
    primary_key: bool = False,
    allow_null: bool = False,
    index: bool = False,
    unique: bool = False,
) -> Type[str]:

    namespace = dict(
        primary_key=primary_key,
        allow_null=allow_null,
        index=index,
        unique=unique,
        column_type=sqlalchemy.ARRAY(sqlalchemy.String),
    )

    class StringArrayField(object):
        @classmethod
        def __get_validators__(cls) -> "CallableGenerator":
            yield cls.validate

        @classmethod
        def validate(cls, v: Any) -> Any:
            return v

    return type("StringArray", (StringArrayField, ColumnFactory), namespace) 
开发者ID:awesometoolbox,项目名称:ormantic,代码行数:28,代码来源:fields.py

示例15: upgrade

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import ARRAY [as 别名]
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('tokens',
    sa.Column('id', sa.String(), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.Column('app_id', sa.String(), nullable=True),
    sa.Column('redirect_url', sa.String(), nullable=True),
    sa.Column('permissions', sa.ARRAY(sa.String()), nullable=True),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='SET NULL'),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_tokens_user_id'), 'tokens', ['user_id'], unique=False)
    # ### end Alembic commands ### 
开发者ID:MrNaif2018,项目名称:bitcart,代码行数:15,代码来源:9232980a793a_added_api_tokens.py


注:本文中的sqlalchemy.ARRAY属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。