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


Python Table.create方法代码示例

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


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

示例1: test_create_drop_bound

# 需要导入模块: from test.lib.schema import Table [as 别名]
# 或者: from test.lib.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:ContextLogic,项目名称:sqlalchemy,代码行数:36,代码来源:test_bind.py

示例2: test_table_overrides_metadata_create

# 需要导入模块: from test.lib.schema import Table [as 别名]
# 或者: from test.lib.schema.Table import create [as 别名]
    def test_table_overrides_metadata_create(self):
        metadata = self.metadata
        s1 = Sequence("s1", metadata=metadata)
        s2 = Sequence("s2", metadata=metadata)
        s3 = Sequence("s3")
        t = Table('t', metadata, 
                    Column('c', Integer, s3, primary_key=True))
        assert s3.metadata is metadata


        t.create(testing.db)
        s3.drop(testing.db)

        # 't' is created, and 's3' won't be
        # re-created since it's linked to 't'.
        # 's1' and 's2' are, however.
        metadata.create_all(testing.db)
        assert self._has_sequence('s1')
        assert self._has_sequence('s2')
        assert not self._has_sequence('s3')

        s2.drop(testing.db)
        assert self._has_sequence('s1')
        assert not self._has_sequence('s2')

        metadata.drop_all(testing.db)
        assert not self._has_sequence('s1')
        assert not self._has_sequence('s2')
开发者ID:onetera,项目名称:scandatatransfer,代码行数:30,代码来源:test_defaults.py

示例3: _run_test

# 需要导入模块: from test.lib.schema import Table [as 别名]
# 或者: from test.lib.schema.Table import create [as 别名]
    def _run_test(self, *arg, **kw):
        metadata = self.metadata
        implicit_returning = kw.pop("implicit_returning", True)
        kw["primary_key"] = True
        if kw.get("autoincrement", True):
            kw["test_needs_autoincrement"] = True
        t = Table(
            "x",
            metadata,
            Column("y", self.MyInteger, *arg, **kw),
            Column("data", Integer),
            implicit_returning=implicit_returning,
        )

        t.create()
        r = t.insert().values(data=5).execute()

        # we don't pre-fetch 'server_default'.
        if "server_default" in kw and (not testing.db.dialect.implicit_returning or not implicit_returning):
            eq_(r.inserted_primary_key, [None])
        else:
            eq_(r.inserted_primary_key, ["INT_1"])
        r.close()

        eq_(t.select().execute().first(), ("INT_1", 5))
开发者ID:vishvananda,项目名称:sqlalchemy,代码行数:27,代码来源:test_defaults.py

示例4: _run_test

# 需要导入模块: from test.lib.schema import Table [as 别名]
# 或者: from test.lib.schema.Table import create [as 别名]
    def _run_test(self, *arg, **kw):
        metadata = self.metadata
        implicit_returning = kw.pop('implicit_returning', True)
        kw['primary_key'] = True
        if kw.get('autoincrement', True):
            kw['test_needs_autoincrement'] = True
        t = Table('x', metadata,
            Column('y', self.MyInteger, *arg, **kw),
            Column('data', Integer),
            implicit_returning=implicit_returning
        )

        t.create()
        r = t.insert().values(data=5).execute()

        # we don't pre-fetch 'server_default'.
        if 'server_default' in kw and (not testing.db.dialect.implicit_returning or not implicit_returning):
            eq_(r.inserted_primary_key, [None])
        else:
            eq_(r.inserted_primary_key, ['INT_1'])
        r.close()

        eq_(
            t.select().execute().first(),
            ('INT_1', 5)
        )
开发者ID:onetera,项目名称:scandatatransfer,代码行数:28,代码来源:test_defaults.py

示例5: setup_class

# 需要导入模块: from test.lib.schema import Table [as 别名]
# 或者: from test.lib.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:ContextLogic,项目名称:sqlalchemy,代码行数:10,代码来源:test_transaction.py

示例6: test_autoincrement_single_col

# 需要导入模块: from test.lib.schema import Table [as 别名]
# 或者: from test.lib.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.inserted_primary_key[0]
        eq_(id_, 1)
        eq_(1, sa.select([func.count(sa.text("*"))], from_obj=single).scalar())
开发者ID:vishvananda,项目名称:sqlalchemy,代码行数:10,代码来源:test_defaults.py

示例7: setup

# 需要导入模块: from test.lib.schema import Table [as 别名]
# 或者: from test.lib.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:ContextLogic,项目名称:sqlalchemy,代码行数:11,代码来源:test_returning.py

示例8: test_func_embedded_valuesbase

# 需要导入模块: from test.lib.schema import Table [as 别名]
# 或者: from test.lib.schema.Table import create [as 别名]
    def test_func_embedded_valuesbase(self):
        """test can use next_value() in values() of _ValuesBase"""

        metadata = self.metadata
        t1 = Table("t", metadata, Column("x", Integer))
        t1.create(testing.db)
        s = Sequence("my_sequence")
        testing.db.execute(t1.insert().values(x=s.next_value()))
        self._assert_seq_result(testing.db.scalar(t1.select()))
开发者ID:vishvananda,项目名称:sqlalchemy,代码行数:11,代码来源:test_defaults.py

示例9: test_func_embedded_whereclause

# 需要导入模块: from test.lib.schema import Table [as 别名]
# 或者: from test.lib.schema.Table import create [as 别名]
    def test_func_embedded_whereclause(self):
        """test can use next_value() in whereclause"""

        metadata = self.metadata
        t1 = Table("t", metadata, Column("x", Integer))
        t1.create(testing.db)
        testing.db.execute(t1.insert(), [{"x": 1}, {"x": 300}, {"x": 301}])
        s = Sequence("my_sequence")
        eq_(testing.db.execute(t1.select().where(t1.c.x > s.next_value())).fetchall(), [(300,), (301,)])
开发者ID:vishvananda,项目名称:sqlalchemy,代码行数:11,代码来源:test_defaults.py

示例10: test_insert_no_pk

# 需要导入模块: from test.lib.schema import Table [as 别名]
# 或者: from test.lib.schema.Table import create [as 别名]
 def test_insert_no_pk(self):
     t = Table("some_other_large_named_table", self.metadata,
         Column("this_is_the_primarykey_column", Integer,
                         Sequence("this_is_some_large_seq"),
                         primary_key=True),
         Column("this_is_the_data_column", String(30))
         )
     t.create(testing.db, checkfirst=True)
     testing.db.execute(t.insert(),
             **{"this_is_the_data_column":"data1"})
开发者ID:NoNo1234,项目名称:the_walking_project,代码行数:12,代码来源:test_labels.py

示例11: test_checkfirst_table

# 需要导入模块: from test.lib.schema import Table [as 别名]
# 或者: from test.lib.schema.Table import create [as 别名]
 def test_checkfirst_table(self):
     m = MetaData()
     s = Sequence("my_sequence")
     t = Table('t', m, Column('c', Integer, s, primary_key=True))
     t.create(testing.db, checkfirst=False)
     assert self._has_sequence('my_sequence')
     t.create(testing.db, checkfirst=True)
     t.drop(testing.db, checkfirst=False)
     assert not self._has_sequence('my_sequence')
     t.drop(testing.db, checkfirst=True)
开发者ID:onetera,项目名称:scandatatransfer,代码行数:12,代码来源:test_defaults.py

示例12: test_autoincrement_fk

# 需要导入模块: from test.lib.schema import Table [as 别名]
# 或者: from test.lib.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.inserted_primary_key[0]
        nodes.insert().execute(data='bar', parent_id=id_)
开发者ID:onetera,项目名称:scandatatransfer,代码行数:12,代码来源:test_defaults.py

示例13: test_inserted_pk_no_returning

# 需要导入模块: from test.lib.schema import Table [as 别名]
# 或者: from test.lib.schema.Table import create [as 别名]
    def test_inserted_pk_no_returning(self):
        """test inserted_primary_key contains [None] when 
        pk_col=next_value(), implicit returning is not used."""

        metadata = self.metadata
        e = engines.testing_engine(options={"implicit_returning": False})
        s = Sequence("my_sequence")
        metadata.bind = e
        t1 = Table("t", metadata, Column("x", Integer, primary_key=True))
        t1.create()
        r = e.execute(t1.insert().values(x=s.next_value()))
        eq_(r.inserted_primary_key, [None])
开发者ID:vishvananda,项目名称:sqlalchemy,代码行数:14,代码来源:test_defaults.py

示例14: test_inserted_pk_implicit_returning

# 需要导入模块: from test.lib.schema import Table [as 别名]
# 或者: from test.lib.schema.Table import create [as 别名]
    def test_inserted_pk_implicit_returning(self):
        """test inserted_primary_key contains the result when 
        pk_col=next_value(), when implicit returning is used."""

        metadata = self.metadata
        e = engines.testing_engine(options={"implicit_returning": True})
        s = Sequence("my_sequence")
        metadata.bind = e
        t1 = Table("t", metadata, Column("x", Integer, primary_key=True))
        t1.create()
        r = e.execute(t1.insert().values(x=s.next_value()))
        self._assert_seq_result(r.inserted_primary_key[0])
开发者ID:vishvananda,项目名称:sqlalchemy,代码行数:14,代码来源:test_defaults.py

示例15: test_autoincrement_fk

# 需要导入模块: from test.lib.schema import Table [as 别名]
# 或者: from test.lib.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.inserted_primary_key[0]
        nodes.insert().execute(data="bar", parent_id=id_)
开发者ID:vishvananda,项目名称:sqlalchemy,代码行数:15,代码来源:test_defaults.py


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