本文整理汇总了Python中test.lib.schema.Table.insert方法的典型用法代码示例。如果您正苦于以下问题:Python Table.insert方法的具体用法?Python Table.insert怎么用?Python Table.insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类test.lib.schema.Table
的用法示例。
在下文中一共展示了Table.insert方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup
# 需要导入模块: from test.lib.schema import Table [as 别名]
# 或者: from test.lib.schema.Table import insert [as 别名]
def setup(self):
global meta, table, engine
engine = engines.reconnecting_engine()
meta = MetaData(engine)
table = Table("sometable", meta, Column("id", Integer, primary_key=True), Column("name", String(50)))
meta.create_all()
table.insert().execute([{"id": i, "name": "row %d" % i} for i in range(1, 100)])
示例2: test_autoincrement_fk
# 需要导入模块: from test.lib.schema import Table [as 别名]
# 或者: from test.lib.schema.Table import insert [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_)
示例3: setup
# 需要导入模块: from test.lib.schema import Table [as 别名]
# 或者: from test.lib.schema.Table import insert [as 别名]
def setup(self):
global meta, table, engine
engine = engines.reconnecting_engine()
meta = MetaData(engine)
table = Table('sometable', meta,
Column('id', Integer, primary_key=True),
Column('name', String(50)))
meta.create_all()
table.insert().execute(
[{'id':i, 'name':'row %d' % i} for i in range(1, 100)]
)
示例4: test_autoincrement_fk
# 需要导入模块: from test.lib.schema import Table [as 别名]
# 或者: from test.lib.schema.Table import insert [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_)
示例5: test_int_default_none_on_insert_reflected
# 需要导入模块: from test.lib.schema import Table [as 别名]
# 或者: from test.lib.schema.Table import insert [as 别名]
def test_int_default_none_on_insert_reflected(self):
metadata = self.metadata
t = Table('x', metadata,
Column('y', Integer,
server_default='5', primary_key=True),
Column('data', String(10)),
implicit_returning=False
)
metadata.create_all()
m2 = MetaData(metadata.bind)
t2 = Table('x', m2, autoload=True, implicit_returning=False)
r = t2.insert().execute(data='data')
eq_(r.inserted_primary_key, [None])
if testing.against('sqlite'):
eq_(
t2.select().execute().fetchall(),
[(1, 'data')]
)
else:
eq_(
t2.select().execute().fetchall(),
[(5, 'data')]
)
示例6: test_non_autoincrement
# 需要导入模块: from test.lib.schema import Table [as 别名]
# 或者: from test.lib.schema.Table import insert [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:
# postgresql + 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.DBAPIError, e:
assert True
示例7: _run_test
# 需要导入模块: from test.lib.schema import Table [as 别名]
# 或者: from test.lib.schema.Table import insert [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)
)
示例8: _run_test
# 需要导入模块: from test.lib.schema import Table [as 别名]
# 或者: from test.lib.schema.Table import insert [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))
示例9: test_int_default_on_insert_with_returning
# 需要导入模块: from test.lib.schema import Table [as 别名]
# 或者: from test.lib.schema.Table import insert [as 别名]
def test_int_default_on_insert_with_returning(self):
metadata = self.metadata
t = Table("x", metadata, Column("y", Integer, server_default="5", primary_key=True), Column("data", String(10)))
metadata.create_all()
r = t.insert().execute(data="data")
eq_(r.inserted_primary_key, [5])
eq_(t.select().execute().fetchall(), [(5, "data")])
示例10: test_autoincrement_single_col
# 需要导入模块: from test.lib.schema import Table [as 别名]
# 或者: from test.lib.schema.Table import insert [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())
示例11: test_func_embedded_valuesbase
# 需要导入模块: from test.lib.schema import Table [as 别名]
# 或者: from test.lib.schema.Table import insert [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()))
示例12: test_func_embedded_whereclause
# 需要导入模块: from test.lib.schema import Table [as 别名]
# 或者: from test.lib.schema.Table import insert [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,)])
示例13: test_insert_no_pk
# 需要导入模块: from test.lib.schema import Table [as 别名]
# 或者: from test.lib.schema.Table import insert [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"})
示例14: test_empty_insert
# 需要导入模块: from test.lib.schema import Table [as 别名]
# 或者: from test.lib.schema.Table import insert [as 别名]
def test_empty_insert(self):
metadata = MetaData(testing.db)
t1 = Table("t1", metadata, Column("is_true", Boolean, server_default=("1")))
metadata.create_all()
try:
result = t1.insert().execute()
eq_(1, select([func.count(text("*"))], from_obj=t1).scalar())
eq_(True, t1.select().scalar())
finally:
metadata.drop_all()
示例15: test_inserted_pk_implicit_returning
# 需要导入模块: from test.lib.schema import Table [as 别名]
# 或者: from test.lib.schema.Table import insert [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])