Here are the examples of the python api sqlalchemy.String.with_variant taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
4 Examples
3
Source : test_type_expressions.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def _variant_fixture(self, inner_fixture):
type_ = inner_fixture.c.y.type
variant = String().with_variant(type_, "default")
return self._test_table(variant)
def _dialect_level_fixture(self):
0
Source : test_autogen_render.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def test_render_variant(self):
from sqlalchemy import VARCHAR, CHAR
self.autogen_context.opts["user_module_prefix"] = None
type_ = (
String(5)
.with_variant(VARCHAR(10), "mysql")
.with_variant(CHAR(15), "oracle")
)
# the new Black formatting will help a lot with this
eq_ignore_whitespace(
autogenerate.render._repr_type(type_, self.autogen_context),
"sa.String(length=5)."
"with_variant(sa.VARCHAR(length=10), 'mysql')."
"with_variant(sa.CHAR(length=15), 'oracle')",
)
def test_repr_user_type_user_prefix_None(self):
0
Source : test_types.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def test_typedec_gen_dialect_impl(self):
"""test that gen_dialect_impl passes onto a TypeDecorator, as
TypeDecorator._gen_dialect_impl() itself has special behaviors.
"""
class MyDialectString(String):
pass
class MyString(TypeDecorator):
impl = String
cache_ok = True
def load_dialect_impl(self, dialect):
return MyDialectString()
variant = String().with_variant(MyString(), "mysql")
dialect_impl = variant._gen_dialect_impl(mysql.dialect())
is_(dialect_impl.impl.__class__, MyDialectString)
def test_compile_composite(self):
0
Source : test_types.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def test_variant_default_is_not_schematype(self, metadata):
t = Table(
"my_table",
metadata,
Column(
"data",
String(50).with_variant(
Enum(
"four",
"five",
"six",
native_enum=False,
name="e2",
create_constraint=True,
),
testing.db.dialect.name,
),
),
)
# the base String() didnt create a constraint or even do any
# events. But Column looked for SchemaType in _variant_mapping
# and found our type anyway.
eq_(
len([c for c in t.constraints if isinstance(c, CheckConstraint)]),
1,
)
metadata.create_all(testing.db)
# not using the connection fixture because we need to rollback and
# start again in the middle
with testing.db.connect() as connection:
# postgresql needs this in order to continue after the exception
trans = connection.begin()
assert_raises(
(exc.DBAPIError,),
connection.exec_driver_sql,
"insert into my_table (data) values('two')",
)
trans.rollback()
with connection.begin():
connection.exec_driver_sql(
"insert into my_table (data) values ('four')"
)
eq_(connection.execute(select(t.c.data)).scalar(), "four")
@testing.requires.enforces_check_constraints