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


Python schema.Table方法代码示例

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


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

示例1: test_not_an_executable

# 需要导入模块: from sqlalchemy.testing import schema [as 别名]
# 或者: from sqlalchemy.testing.schema import Table [as 别名]
def test_not_an_executable(self):
        for obj in (
            Table("foo", MetaData(), Column("x", Integer)),
            Column("x", Integer),
            tsa.and_(True),
            tsa.and_(True).compile(),
            column("foo"),
            column("foo").compile(),
            MetaData(),
            Integer(),
            tsa.Index(name="foo"),
            tsa.UniqueConstraint("x"),
        ):
            with testing.db.connect() as conn:
                assert_raises_message(
                    tsa.exc.ObjectNotExecutableError,
                    "Not an executable object",
                    conn.execute,
                    obj,
                ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:22,代码来源:test_execute.py

示例2: test_sequence_not_duped

# 需要导入模块: from sqlalchemy.testing import schema [as 别名]
# 或者: from sqlalchemy.testing.schema import Table [as 别名]
def test_sequence_not_duped(self):
        engine, buf = self._engine_fixture()
        metadata = MetaData()
        t = Table(
            "testtable",
            metadata,
            Column(
                "pk", Integer, Sequence("testtable_pk_seq"), primary_key=True,
            ),
        )

        t.create(engine)
        t.drop(engine)

        eq_(re.findall(r"CREATE (\w+)", buf.getvalue()), ["SEQUENCE", "TABLE"])

        eq_(re.findall(r"DROP (\w+)", buf.getvalue()), ["TABLE", "SEQUENCE"]) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:19,代码来源:test_execute.py

示例3: define_tables

# 需要导入模块: from sqlalchemy.testing import schema [as 别名]
# 或者: from sqlalchemy.testing.schema import Table [as 别名]
def define_tables(cls, metadata):
        Table(
            "users",
            metadata,
            Column("user_id", INT, primary_key=True, autoincrement=False),
            Column("user_name", VARCHAR(20)),
            test_needs_acid=True,
        )
        Table(
            "users_autoinc",
            metadata,
            Column(
                "user_id", INT, primary_key=True, test_needs_autoincrement=True
            ),
            Column("user_name", VARCHAR(20)),
            test_needs_acid=True,
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:19,代码来源:test_execute.py

示例4: test_create_drop_constructor_bound

# 需要导入模块: from sqlalchemy.testing import schema [as 别名]
# 或者: from sqlalchemy.testing.schema import Table [as 别名]
def test_create_drop_constructor_bound(self):
        for bind in (testing.db, testing.db.connect()):
            try:
                for args in (([bind], {}), ([], {"bind": bind})):
                    metadata = MetaData(*args[0], **args[1])
                    table = Table(
                        "test_table", metadata, Column("foo", Integer)
                    )
                    assert metadata.bind is table.bind is bind
                    metadata.create_all()
                    is_true(inspect(bind).has_table(table.name))
                    metadata.drop_all()
                    table.create()
                    table.drop()
                    is_false(inspect(bind).has_table(table.name))
            finally:
                if isinstance(bind, engine.Connection):
                    bind.close() 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:20,代码来源:test_bind.py

示例5: test_include_columns_indexes

# 需要导入模块: from sqlalchemy.testing import schema [as 别名]
# 或者: from sqlalchemy.testing.schema import Table [as 别名]
def test_include_columns_indexes(self):
        m = self.metadata

        t1 = Table("t1", m, Column("a", sa.Integer), Column("b", sa.Integer))
        sa.Index("foobar", t1.c.a, t1.c.b)
        sa.Index("bat", t1.c.a)
        m.create_all()
        m2 = MetaData(testing.db)
        t2 = Table("t1", m2, autoload=True)
        assert len(t2.indexes) == 2

        m2 = MetaData(testing.db)
        t2 = Table("t1", m2, autoload=True, include_columns=["a"])
        assert len(t2.indexes) == 1

        m2 = MetaData(testing.db)
        t2 = Table("t1", m2, autoload=True, include_columns=["a", "b"])
        assert len(t2.indexes) == 2 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:20,代码来源:test_reflection.py

示例6: test_unknown_types

# 需要导入模块: from sqlalchemy.testing import schema [as 别名]
# 或者: from sqlalchemy.testing.schema import Table [as 别名]
def test_unknown_types(self):
        """Test the handling of unknown types for the given dialect.

        sqlite is skipped because it has special rules for unknown types using
        'affinity types' - this feature is tested in that dialect's test spec.
        """
        meta = self.metadata
        t = Table("test", meta, Column("foo", sa.DateTime))

        ischema_names = testing.db.dialect.ischema_names
        t.create()
        testing.db.dialect.ischema_names = {}
        try:
            m2 = MetaData(testing.db)

            with testing.expect_warnings("Did not recognize type"):
                t3 = Table("test", m2, autoload_with=testing.db)
                is_(t3.c.foo.type.__class__, sa.types.NullType)

        finally:
            testing.db.dialect.ischema_names = ischema_names 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:23,代码来源:test_reflection.py

示例7: test_basic_override

# 需要导入模块: from sqlalchemy.testing import schema [as 别名]
# 或者: from sqlalchemy.testing.schema import Table [as 别名]
def test_basic_override(self):
        meta = self.metadata
        table = Table(
            "override_test",
            meta,
            Column("col1", sa.Integer, primary_key=True),
            Column("col2", sa.String(20)),
            Column("col3", sa.Numeric),
        )
        table.create()

        meta2 = MetaData(testing.db)
        table = Table(
            "override_test",
            meta2,
            Column("col2", sa.Unicode()),
            Column("col4", sa.String(30)),
            autoload=True,
        )

        self.assert_(isinstance(table.c.col1.type, sa.Integer))
        self.assert_(isinstance(table.c.col2.type, sa.Unicode))
        self.assert_(isinstance(table.c.col4.type, sa.String)) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:25,代码来源:test_reflection.py

示例8: test_override_upgrade_pk_flag

# 需要导入模块: from sqlalchemy.testing import schema [as 别名]
# 或者: from sqlalchemy.testing.schema import Table [as 别名]
def test_override_upgrade_pk_flag(self):
        meta = self.metadata
        table = Table(
            "override_test",
            meta,
            Column("col1", sa.Integer),
            Column("col2", sa.String(20)),
            Column("col3", sa.Numeric),
        )
        table.create()

        meta2 = MetaData(testing.db)
        table = Table(
            "override_test",
            meta2,
            Column("col1", sa.Integer, primary_key=True),
            autoload=True,
        )

        eq_(list(table.primary_key), [table.c.col1])
        eq_(table.c.col1.primary_key, True) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:23,代码来源:test_reflection.py

示例9: test_pks_not_uniques

# 需要导入模块: from sqlalchemy.testing import schema [as 别名]
# 或者: from sqlalchemy.testing.schema import Table [as 别名]
def test_pks_not_uniques(self):
        """test that primary key reflection not tripped up by unique
        indexes"""

        with testing.db.begin() as conn:
            conn.exec_driver_sql(
                """
                CREATE TABLE book (
                    id INTEGER NOT NULL,
                    title VARCHAR(100) NOT NULL,
                    series INTEGER,
                    series_id INTEGER,
                    UNIQUE(series, series_id),
                    PRIMARY KEY(id)
                )"""
            )

        book = Table("book", self.metadata, autoload_with=testing.db)
        assert book.primary_key.contains_column(book.c.id)
        assert not book.primary_key.contains_column(book.c.series)
        eq_(len(book.primary_key), 1) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:23,代码来源:test_reflection.py

示例10: test_composite_pks

# 需要导入模块: from sqlalchemy.testing import schema [as 别名]
# 或者: from sqlalchemy.testing.schema import Table [as 别名]
def test_composite_pks(self):
        """test reflection of a composite primary key"""

        with testing.db.begin() as conn:
            conn.exec_driver_sql(
                """
                CREATE TABLE book (
                    id INTEGER NOT NULL,
                    isbn VARCHAR(50) NOT NULL,
                    title VARCHAR(100) NOT NULL,
                    series INTEGER NOT NULL,
                    series_id INTEGER NOT NULL,
                    UNIQUE(series, series_id),
                    PRIMARY KEY(id, isbn)
                )"""
            )
        book = Table("book", self.metadata, autoload_with=testing.db)
        assert book.primary_key.contains_column(book.c.id)
        assert book.primary_key.contains_column(book.c.isbn)
        assert not book.primary_key.contains_column(book.c.series)
        eq_(len(book.primary_key), 2) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:23,代码来源:test_reflection.py

示例11: define_tables

# 需要导入模块: from sqlalchemy.testing import schema [as 别名]
# 或者: from sqlalchemy.testing.schema import Table [as 别名]
def define_tables(cls, metadata):
        Table('test_table', metadata,
              Column('id', Integer, primary_key=True),
              Column('data', String(50))
              ) 
开发者ID:jpush,项目名称:jbox,代码行数:7,代码来源:test_reflection.py

示例12: define_temp_tables

# 需要导入模块: from sqlalchemy.testing import schema [as 别名]
# 或者: from sqlalchemy.testing.schema import Table [as 别名]
def define_temp_tables(cls, metadata):
        # cheat a bit, we should fix this with some dialect-level
        # temp table fixture
        if testing.against("oracle"):
            kw = {
                'prefixes': ["GLOBAL TEMPORARY"],
                'oracle_on_commit': 'PRESERVE ROWS'
            }
        else:
            kw = {
                'prefixes': ["TEMPORARY"],
            }

        user_tmp = Table(
            "user_tmp", metadata,
            Column("id", sa.INT, primary_key=True),
            Column('name', sa.VARCHAR(50)),
            Column('foo', sa.INT),
            sa.UniqueConstraint('name', name='user_tmp_uq'),
            sa.Index("user_tmp_ix", "foo"),
            **kw
        )
        if testing.requires.view_reflection.enabled and \
                testing.requires.temporary_views.enabled:
            event.listen(
                user_tmp, "after_create",
                DDL("create temporary view user_tmp_v as "
                    "select * from user_tmp")
            )
            event.listen(
                user_tmp, "before_drop",
                DDL("drop view user_tmp_v")
            ) 
开发者ID:jpush,项目名称:jbox,代码行数:35,代码来源:test_reflection.py

示例13: _type_round_trip

# 需要导入模块: from sqlalchemy.testing import schema [as 别名]
# 或者: from sqlalchemy.testing.schema import Table [as 别名]
def _type_round_trip(self, *types):
        t = Table('t', self.metadata,
                  *[
                      Column('t%d' % i, type_)
                      for i, type_ in enumerate(types)
                  ]
                  )
        t.create()

        return [
            c['type'] for c in
            inspect(self.metadata.bind).get_columns('t')
        ] 
开发者ID:jpush,项目名称:jbox,代码行数:15,代码来源:test_reflection.py

示例14: test_nullable_reflection

# 需要导入模块: from sqlalchemy.testing import schema [as 别名]
# 或者: from sqlalchemy.testing.schema import Table [as 别名]
def test_nullable_reflection(self):
        t = Table('t', self.metadata,
                  Column('a', Integer, nullable=True),
                  Column('b', Integer, nullable=False))
        t.create()
        eq_(
            dict(
                (col['name'], col['nullable'])
                for col in inspect(self.metadata.bind).get_columns('t')
            ),
            {"a": True, "b": False}
        ) 
开发者ID:jpush,项目名称:jbox,代码行数:14,代码来源:test_reflection.py

示例15: _test_get_check_constraints

# 需要导入模块: from sqlalchemy.testing import schema [as 别名]
# 或者: from sqlalchemy.testing.schema import Table [as 别名]
def _test_get_check_constraints(self, schema=None):
        orig_meta = self.metadata
        Table(
            'sa_cc', orig_meta,
            Column('a', Integer()),
            sa.CheckConstraint('a > 1 AND a < 5', name='cc1'),
            sa.CheckConstraint('a = 1 OR (a > 2 AND a < 5)', name='cc2'),
            schema=schema
        )

        orig_meta.create_all()

        inspector = inspect(orig_meta.bind)
        reflected = sorted(
            inspector.get_check_constraints('sa_cc', schema=schema),
            key=operator.itemgetter('name')
        )

        reflected = [
            {"name": item["name"],
             # trying to minimize effect of quoting, parenthesis, etc.
             # may need to add more to this as new dialects get CHECK
             # constraint reflection support
             "sqltext": re.sub(r"[`'\(\)]", '', item["sqltext"].lower())}
            for item in reflected
        ]
        eq_(
            reflected,
            [
                {'name': 'cc1', 'sqltext': 'a > 1 and a < 5'},
                {'name': 'cc2', 'sqltext': 'a = 1 or a > 2 and a < 5'}
            ]
        ) 
开发者ID:yfauser,项目名称:planespotter,代码行数:35,代码来源:test_reflection.py


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