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


Python Table.create方法代码示例

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


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

示例1: test_unknown_types

# 需要导入模块: from sqlalchemy.test.schema import Table [as 别名]
# 或者: from sqlalchemy.test.schema.Table import create [as 别名]
    def test_unknown_types(self):
        meta = MetaData(testing.db)
        t = Table("test", meta,
            Column('foo', sa.DateTime))

        import sys
        dialect_module = sys.modules[testing.db.dialect.__module__]

        # we're relying on the presence of "ischema_names" in the
        # dialect module, else we can't test this.  we need to be able
        # to get the dialect to not be aware of some type so we temporarily
        # monkeypatch.  not sure what a better way for this could be,
        # except for an established dialect hook or dialect-specific tests
        if not hasattr(dialect_module, 'ischema_names'):
            return

        ischema_names = dialect_module.ischema_names
        t.create()
        dialect_module.ischema_names = {}
        try:
            m2 = MetaData(testing.db)
            assert_raises(tsa.exc.SAWarning, Table, "test", m2, autoload=True)

            @testing.emits_warning('Did not recognize type')
            def warns():
                m3 = MetaData(testing.db)
                t3 = Table("test", m3, autoload=True)
                assert t3.c.foo.type.__class__ == sa.types.NullType

        finally:
            dialect_module.ischema_names = ischema_names
            t.drop()
开发者ID:gajop,项目名称:springgrid,代码行数:34,代码来源:test_reflection.py

示例2: test_create_drop_bound

# 需要导入模块: from sqlalchemy.test.schema import Table [as 别名]
# 或者: from sqlalchemy.test.schema.Table import create [as 别名]
    def test_create_drop_bound(self):

        for meta in (MetaData, ThreadLocalMetaData):
            for bind in (testing.db, testing.db.connect()):
                metadata = meta()
                table = Table("test_table", metadata, Column("foo", Integer))
                metadata.bind = bind
                assert metadata.bind is table.bind is bind
                metadata.create_all()
                assert table.exists()
                metadata.drop_all()
                table.create()
                table.drop()
                assert not table.exists()

                metadata = meta()
                table = Table("test_table", metadata, Column("foo", Integer))

                metadata.bind = bind

                assert metadata.bind is table.bind is bind
                metadata.create_all()
                assert table.exists()
                metadata.drop_all()
                table.create()
                table.drop()
                assert not table.exists()
                if isinstance(bind, engine.Connection):
                    bind.close()
开发者ID:,项目名称:,代码行数:31,代码来源:

示例3: test_prefixes

# 需要导入模块: from sqlalchemy.test.schema import Table [as 别名]
# 或者: from sqlalchemy.test.schema.Table import create [as 别名]
 def test_prefixes(self):
     table1 = Table("temporary_table_1", self.metadata, Column("col1", Integer), prefixes=["TEMPORARY"])
     table1.create()
     assert [str(x) for x in self.engine.mock if "CREATE TEMPORARY TABLE" in str(x)]
     del self.engine.mock[:]
     table2 = Table("temporary_table_2", self.metadata, Column("col1", Integer), prefixes=["VIRTUAL"])
     table2.create()
     assert [str(x) for x in self.engine.mock if "CREATE VIRTUAL TABLE" in str(x)]
开发者ID:hughperkins,项目名称:ailadder,代码行数:10,代码来源:test_metadata.py

示例4: setup_class

# 需要导入模块: from sqlalchemy.test.schema import Table [as 别名]
# 或者: from sqlalchemy.test.schema.Table import create [as 别名]
 def setup_class(cls):
     global counters, metadata
     metadata = MetaData()
     counters = Table('forupdate_counters', metadata,
                      Column('counter_id', INT, primary_key=True),
                      Column('counter_value', INT),
                      test_needs_acid=True)
     counters.create(testing.db)
开发者ID:AndryulE,项目名称:kitsune,代码行数:10,代码来源:test_transaction.py

示例5: test_autoincrement_single_col

# 需要导入模块: from sqlalchemy.test.schema import Table [as 别名]
# 或者: from sqlalchemy.test.schema.Table import create [as 别名]
    def test_autoincrement_single_col(self):
        single = Table('single', self.metadata,
                       Column('id', Integer, primary_key=True))
        single.create()

        r = single.insert().execute()
        id_ = r.last_inserted_ids()[0]
        assert id_ is not None
        eq_(1, sa.select([func.count(sa.text('*'))], from_obj=single).scalar())
开发者ID:gajop,项目名称:springgrid,代码行数:11,代码来源:test_defaults.py

示例6: setup

# 需要导入模块: from sqlalchemy.test.schema import Table [as 别名]
# 或者: from sqlalchemy.test.schema.Table import create [as 别名]
 def setup(self):
     meta = MetaData(testing.db)
     global table, seq
     seq = Sequence('tid_seq')
     table = Table('tables', meta,
                 Column('id', Integer, seq, primary_key=True),
                 Column('data', String(50))
             )
     table.create(checkfirst=True)
开发者ID:clones,项目名称:sqlalchemy,代码行数:11,代码来源:test_returning.py

示例7: test_autoincrement_fk

# 需要导入模块: from sqlalchemy.test.schema import Table [as 别名]
# 或者: from sqlalchemy.test.schema.Table import create [as 别名]
    def test_autoincrement_fk(self):
        nodes = Table('nodes', self.metadata,
            Column('id', Integer, primary_key=True),
            Column('parent_id', Integer, ForeignKey('nodes.id')),
            Column('data', String(30)))
        nodes.create()

        r = nodes.insert().execute(data='foo')
        id_ = r.last_inserted_ids()[0]
        nodes.insert().execute(data='bar', parent_id=id_)
开发者ID:gajop,项目名称:springgrid,代码行数:12,代码来源:test_defaults.py

示例8: setup_class

# 需要导入模块: from sqlalchemy.test.schema import Table [as 别名]
# 或者: from sqlalchemy.test.schema.Table import create [as 别名]
 def setup_class(cls):
     global users, metadata, tlengine
     tlengine = create_engine(testing.db.url, strategy='threadlocal')
     metadata = MetaData()
     users = Table('query_users', metadata,
         Column('user_id', INT, Sequence('query_users_id_seq', optional=True), primary_key=True),
         Column('user_name', VARCHAR(20)),
         test_needs_acid=True,
     )
     users.create(tlengine)
开发者ID:gajop,项目名称:springgrid,代码行数:12,代码来源:test_transaction.py

示例9: test_create_drop_explicit

# 需要导入模块: from sqlalchemy.test.schema import Table [as 别名]
# 或者: from sqlalchemy.test.schema.Table import create [as 别名]
 def test_create_drop_explicit(self):
     metadata = MetaData()
     table = Table("test_table", metadata, Column("foo", Integer))
     for bind in (testing.db, testing.db.connect()):
         for args in [([], {"bind": bind}), ([bind], {})]:
             metadata.create_all(*args[0], **args[1])
             assert table.exists(*args[0], **args[1])
             metadata.drop_all(*args[0], **args[1])
             table.create(*args[0], **args[1])
             table.drop(*args[0], **args[1])
             assert not table.exists(*args[0], **args[1])
开发者ID:,项目名称:,代码行数:13,代码来源:

示例10: test_create_drop_constructor_bound

# 需要导入模块: from sqlalchemy.test.schema import Table [as 别名]
# 或者: from sqlalchemy.test.schema.Table import create [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()
                 assert table.exists()
                 metadata.drop_all()
                 table.create()
                 table.drop()
                 assert not table.exists()
         finally:
             if isinstance(bind, engine.Connection):
                 bind.close()
开发者ID:,项目名称:,代码行数:18,代码来源:

示例11: test_non_autoincrement

# 需要导入模块: from sqlalchemy.test.schema import Table [as 别名]
# 或者: from sqlalchemy.test.schema.Table import create [as 别名]
    def test_non_autoincrement(self):
        # sqlite INT primary keys can be non-unique! (only for ints)
        nonai = Table("nonaitest", self.metadata,
            Column('id', Integer, autoincrement=False, primary_key=True),
            Column('data', String(20)))
        nonai.create()


        try:
            # postgres + mysql strict will fail on first row,
            # mysql in legacy mode fails on second row
            nonai.insert().execute(data='row 1')
            nonai.insert().execute(data='row 2')
            assert False
        except sa.exc.SQLError, e:
            assert True
开发者ID:gajop,项目名称:springgrid,代码行数:18,代码来源:test_defaults.py

示例12: test_rollback_deadlock

# 需要导入模块: from sqlalchemy.test.schema import Table [as 别名]
# 或者: from sqlalchemy.test.schema.Table import create [as 别名]
    def test_rollback_deadlock(self):
        """test that returning connections to the pool clears any object locks."""
        conn1 = testing.db.connect()
        conn2 = testing.db.connect()
        users = Table('deadlock_users', metadata,
            Column('user_id', INT, primary_key = True),
            Column('user_name', VARCHAR(20)),
            test_needs_acid=True,
        )
        users.create(conn1)
        conn1.execute("select * from deadlock_users")
        conn1.close()

        # without auto-rollback in the connection pool's return() logic, this
        # deadlocks in PostgreSQL, because conn1 is returned to the pool but
        # still has a lock on "deadlock_users".
        # comment out the rollback in pool/ConnectionFairy._close() to see !
        users.drop(conn2)
        conn2.close()
开发者ID:gajop,项目名称:springgrid,代码行数:21,代码来源:test_transaction.py

示例13: test_unknown_types

# 需要导入模块: from sqlalchemy.test.schema import Table [as 别名]
# 或者: from sqlalchemy.test.schema.Table import create [as 别名]
    def test_unknown_types(self):
        meta = MetaData(testing.db)
        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)
            assert_raises(sa.exc.SAWarning, Table, "test", m2, autoload=True)

            @testing.emits_warning('Did not recognize type')
            def warns():
                m3 = MetaData(testing.db)
                t3 = Table("test", m3, autoload=True)
                assert t3.c.foo.type.__class__ == sa.types.NullType

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

示例14: test_row_c_sequence_check

# 需要导入模块: from sqlalchemy.test.schema import Table [as 别名]
# 或者: from sqlalchemy.test.schema.Table import create [as 别名]
    def test_row_c_sequence_check(self):
        import csv
        import collections
        from StringIO import StringIO

        metadata = MetaData()
        metadata.bind = 'sqlite://'
        users = Table('users', metadata,
            Column('id', Integer, primary_key=True),
            Column('name', String(40)),
        )
        users.create()

        users.insert().execute(name='Test')
        row = users.select().execute().fetchone()

        s = StringIO()
        writer = csv.writer(s)
        # csv performs PySequenceCheck call
        writer.writerow(row)
        assert s.getvalue().strip() == '1,Test'
开发者ID:chatch,项目名称:pinyin-toolkit,代码行数:23,代码来源:test_execute.py

示例15: test_basic_override

# 需要导入模块: from sqlalchemy.test.schema import Table [as 别名]
# 或者: from sqlalchemy.test.schema.Table import create [as 别名]
    def test_basic_override(self):
        meta = MetaData(testing.db)
        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)
        try:
            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))
        finally:
            table.drop()
开发者ID:gajop,项目名称:springgrid,代码行数:24,代码来源:test_reflection.py


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