本文整理汇总了Python中sqlalchemy.testing.schema.Table.create方法的典型用法代码示例。如果您正苦于以下问题:Python Table.create方法的具体用法?Python Table.create怎么用?Python Table.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy.testing.schema.Table
的用法示例。
在下文中一共展示了Table.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _dont_test_numeric_nan_decimal
# 需要导入模块: from sqlalchemy.testing.schema import Table [as 别名]
# 或者: from sqlalchemy.testing.schema.Table import create [as 别名]
def _dont_test_numeric_nan_decimal(self):
m = self.metadata
t1 = Table('t1', m,
Column("intcol", Integer),
Column("numericcol", oracle.BINARY_DOUBLE(asdecimal=True)))
t1.create()
t1.insert().execute([
dict(
intcol=1,
numericcol=decimal.Decimal("NaN")
),
dict(
intcol=2,
numericcol=decimal.Decimal("-NaN")
),
])
eq_(
select([t1.c.numericcol]).
order_by(t1.c.intcol).execute().fetchall(),
[(decimal.Decimal("NaN"), ), (decimal.Decimal("NaN"), )]
)
eq_(
testing.db.execute(
"select numericcol from t1 order by intcol").fetchall(),
[(decimal.Decimal("NaN"), ), (decimal.Decimal("NaN"), )]
)
示例2: setup
# 需要导入模块: from sqlalchemy.testing.schema import Table [as 别名]
# 或者: from sqlalchemy.testing.schema.Table import create [as 别名]
def setup(self):
meta = MetaData(testing.db)
global table, GoofyType
class GoofyType(TypeDecorator):
impl = String
def process_bind_param(self, value, dialect):
if value is None:
return None
return "FOO" + value
def process_result_value(self, value, dialect):
if value is None:
return None
return value + "BAR"
table = Table(
'tables', meta,
Column(
'id', Integer, primary_key=True,
test_needs_autoincrement=True),
Column('persons', Integer),
Column('full', Boolean),
Column('goofy', GoofyType(50)))
table.create(checkfirst=True)
示例3: _run_test
# 需要导入模块: from sqlalchemy.testing.schema import Table [as 别名]
# 或者: from sqlalchemy.testing.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)
)
示例4: test_fixed_char
# 需要导入模块: from sqlalchemy.testing.schema import Table [as 别名]
# 或者: from sqlalchemy.testing.schema.Table import create [as 别名]
def test_fixed_char(self):
m = MetaData(testing.db)
t = Table('t1', m,
Column('id', Integer, primary_key=True),
Column('data', CHAR(30), nullable=False))
t.create()
try:
t.insert().execute(
dict(id=1, data="value 1"),
dict(id=2, data="value 2"),
dict(id=3, data="value 3")
)
eq_(
t.select().where(t.c.data == 'value 2').execute().fetchall(),
[(2, 'value 2 ')]
)
m2 = MetaData(testing.db)
t2 = Table('t1', m2, autoload=True)
assert type(t2.c.data.type) is CHAR
eq_(
t2.select().where(t2.c.data == 'value 2').execute().fetchall(),
[(2, 'value 2 ')]
)
finally:
t.drop()
示例5: test_create_drop_bound
# 需要导入模块: from sqlalchemy.testing.schema import Table [as 别名]
# 或者: from sqlalchemy.testing.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()
示例6: test_insert_from_select_fn_defaults
# 需要导入模块: from sqlalchemy.testing.schema import Table [as 别名]
# 或者: from sqlalchemy.testing.schema.Table import create [as 别名]
def test_insert_from_select_fn_defaults(self):
data = self._fixture()
counter = itertools.count(1)
def foo(ctx):
return next(counter)
table = Table('sometable', self.metadata,
Column('x', Integer),
Column('foo', Integer, default=foo),
Column('y', Integer))
table.create()
sel = select([data.c.x, data.c.y])
ins = table.insert().\
from_select(["x", "y"], sel)
testing.db.execute(ins)
# counter is only called once!
eq_(
testing.db.execute(table.select().order_by(table.c.x)).fetchall(),
[(2, 1, 5), (7, 1, 12)]
)
示例7: test_numeric_nan_float
# 需要导入模块: from sqlalchemy.testing.schema import Table [as 别名]
# 或者: from sqlalchemy.testing.schema.Table import create [as 别名]
def test_numeric_nan_float(self):
m = self.metadata
t1 = Table(
"t1",
m,
Column("intcol", Integer),
Column("numericcol", oracle.BINARY_DOUBLE(asdecimal=False)),
)
t1.create()
t1.insert().execute(
[
dict(intcol=1, numericcol=float("nan")),
dict(intcol=2, numericcol=float("-nan")),
]
)
eq_(
[
tuple(str(col) for col in row)
for row in select([t1.c.numericcol])
.order_by(t1.c.intcol)
.execute()
],
[("nan",), ("nan",)],
)
eq_(
[
tuple(str(col) for col in row)
for row in testing.db.execute(
"select numericcol from t1 order by intcol"
)
],
[("nan",), ("nan",)],
)
示例8: test_nullable_reflection
# 需要导入模块: from sqlalchemy.testing.schema import Table [as 别名]
# 或者: from sqlalchemy.testing.schema.Table import create [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},
)
示例9: _run_test
# 需要导入模块: from sqlalchemy.testing.schema import Table [as 别名]
# 或者: from sqlalchemy.testing.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))
示例10: test_numeric_infinity_float
# 需要导入模块: from sqlalchemy.testing.schema import Table [as 别名]
# 或者: from sqlalchemy.testing.schema.Table import create [as 别名]
def test_numeric_infinity_float(self):
m = self.metadata
t1 = Table('t1', m,
Column("intcol", Integer),
Column("numericcol", oracle.BINARY_DOUBLE(asdecimal=False)))
t1.create()
t1.insert().execute([
dict(
intcol=1,
numericcol=float("inf")
),
dict(
intcol=2,
numericcol=float("-inf")
),
])
eq_(
select([t1.c.numericcol]).
order_by(t1.c.intcol).execute().fetchall(),
[(float('inf'), ), (float('-inf'), )]
)
eq_(
testing.db.execute(
"select numericcol from t1 order by intcol").fetchall(),
[(float('inf'), ), (float('-inf'), )]
)
示例11: test_table_overrides_metadata_create
# 需要导入模块: from sqlalchemy.testing.schema import Table [as 别名]
# 或者: from sqlalchemy.testing.schema.Table import create [as 别名]
def test_table_overrides_metadata_create(self):
metadata = self.metadata
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, checkfirst=True)
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')
示例12: setup_class
# 需要导入模块: from sqlalchemy.testing.schema import Table [as 别名]
# 或者: from sqlalchemy.testing.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)
示例13: test_autoincrement_single_col
# 需要导入模块: from sqlalchemy.testing.schema import Table [as 别名]
# 或者: from sqlalchemy.testing.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())
示例14: test_func_embedded_whereclause
# 需要导入模块: from sqlalchemy.testing.schema import Table [as 别名]
# 或者: from sqlalchemy.testing.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,)])
示例15: setup_class
# 需要导入模块: from sqlalchemy.testing.schema import Table [as 别名]
# 或者: from sqlalchemy.testing.schema.Table import create [as 别名]
def setup_class(cls):
global users, metadata
metadata = MetaData()
users = Table('query_users', metadata,
Column('user_id', INT, primary_key = True),
Column('user_name', VARCHAR(20)),
test_needs_acid=True,
)
users.create(testing.db)