本文整理汇总了Python中sqlalchemy.CHAR属性的典型用法代码示例。如果您正苦于以下问题:Python sqlalchemy.CHAR属性的具体用法?Python sqlalchemy.CHAR怎么用?Python sqlalchemy.CHAR使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类sqlalchemy
的用法示例。
在下文中一共展示了sqlalchemy.CHAR属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_render_variant
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import CHAR [as 别名]
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')",
)
示例2: schema_downgrades
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import CHAR [as 别名]
def schema_downgrades():
"""schema downgrade migrations go here."""
op.create_table('payload_dependencies',
sa.Column('payload_uuid', sa.CHAR(length=32), nullable=True),
sa.Column('depends_on_payload_uuid', sa.CHAR(length=32), nullable=True),
sa.ForeignKeyConstraint(['depends_on_payload_uuid'], ['payloads.uuid'], ),
sa.ForeignKeyConstraint(['payload_uuid'], ['payloads.uuid'], )
)
op.create_table('users',
sa.Column('id', sa.INTEGER(), nullable=False),
sa.Column('name', sa.VARCHAR(), nullable=True),
sa.Column('fullname', sa.VARCHAR(), nullable=True),
sa.Column('password', sa.VARCHAR(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.drop_table('dep_configurations')
op.drop_table('mdm_payload')
op.drop_table('certificate_payload')
op.drop_table('command_sequences')
示例3: test_char_length
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import CHAR [as 别名]
def test_char_length(self):
metadata = self.metadata
t1 = Table(
"t1",
metadata,
Column("c1", VARCHAR(50)),
Column("c2", NVARCHAR(250)),
Column("c3", CHAR(200)),
Column("c4", NCHAR(180)),
)
t1.create()
m2 = MetaData(testing.db)
t2 = Table("t1", m2, autoload=True)
eq_(t2.c.c1.type.length, 50)
eq_(t2.c.c2.type.length, 250)
eq_(t2.c.c3.type.length, 200)
eq_(t2.c.c4.type.length, 180)
示例4: test_decorator_doesnt_cache
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import CHAR [as 别名]
def test_decorator_doesnt_cache(self):
from sqlalchemy.dialects import postgresql
class MyType(TypeDecorator):
impl = CHAR
def load_dialect_impl(self, dialect):
if dialect.name == "postgresql":
return dialect.type_descriptor(postgresql.UUID())
else:
return dialect.type_descriptor(CHAR(32))
t1 = MyType()
d = postgresql.dialect()
assert t1._type_affinity is String
assert t1.dialect_impl(d)._type_affinity is postgresql.UUID
示例5: define_tables
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import CHAR [as 别名]
def define_tables(cls, metadata):
Table(
"keyed1",
metadata,
Column("a", CHAR(2), key="b"),
Column("c", CHAR(2), key="q"),
)
Table("keyed2", metadata, Column("a", CHAR(2)), Column("b", CHAR(2)))
Table("keyed3", metadata, Column("a", CHAR(2)), Column("d", CHAR(2)))
Table("keyed4", metadata, Column("b", CHAR(2)), Column("q", CHAR(2)))
Table("content", metadata, Column("t", String(30), key="type"))
Table("bar", metadata, Column("ctype", String(30), key="content_type"))
if testing.requires.schemas.enabled:
Table(
"wschema",
metadata,
Column("a", CHAR(2), key="b"),
Column("c", CHAR(2), key="q"),
schema=testing.config.test_schema,
)
示例6: test_fewer_cols_than_sql_non_positional
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import CHAR [as 别名]
def test_fewer_cols_than_sql_non_positional(self, connection):
c1, c2 = column("a"), column("p")
stmt = text("select a, b, c, d from text1").columns(c2, c1, d=CHAR)
# no warning as this can be similar for non-positional
result = connection.execute(stmt)
row = result.first()
# c1 name matches, locates
eq_(row._mapping[c1], "a1")
eq_(row._mapping["c"], "c1")
# c2 name does not match, doesn't locate
assert_raises_message(
exc.NoSuchColumnError,
"in row for column 'p'",
lambda: row._mapping[c2],
)
示例7: test_render_modify_type
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import CHAR [as 别名]
def test_render_modify_type(self):
op_obj = ops.AlterColumnOp(
"sometable",
"somecolumn",
modify_type=CHAR(10),
existing_type=CHAR(20),
)
eq_ignore_whitespace(
autogenerate.render_op_text(self.autogen_context, op_obj),
"op.alter_column('sometable', 'somecolumn', "
"existing_type=sa.CHAR(length=20), type_=sa.CHAR(length=10))",
)
示例8: test_render_modify_type_w_schema
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import CHAR [as 别名]
def test_render_modify_type_w_schema(self):
op_obj = ops.AlterColumnOp(
"sometable",
"somecolumn",
modify_type=CHAR(10),
existing_type=CHAR(20),
schema="foo",
)
eq_ignore_whitespace(
autogenerate.render_op_text(self.autogen_context, op_obj),
"op.alter_column('sometable', 'somecolumn', "
"existing_type=sa.CHAR(length=20), type_=sa.CHAR(length=10), "
"schema='foo')",
)
示例9: load_dialect_impl
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import CHAR [as 别名]
def load_dialect_impl(self, dialect):
return dialect.type_descriptor(sql.types.CHAR(32))
示例10: make_create_ddl
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import CHAR [as 别名]
def make_create_ddl(self, metadata: MetaData) -> DdlString:
return (super()
.make_create_ddl(metadata)
.replace("CREATE SCHEMA", "CREATE DATABASE")
.replace("ENGINE = Memory", "Engine = File(Parquet)")
.replace(" CHAR(", " FixedString(")
)
示例11: test_no_cast_pre_4
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import CHAR [as 别名]
def test_no_cast_pre_4(self):
self.assert_compile(
cast(Column("foo", Integer), String), "CAST(foo AS CHAR)"
)
dialect = mysql.dialect()
dialect.server_version_info = (3, 2, 3)
with expect_warnings("Current MySQL version does not support CAST;"):
self.assert_compile(
cast(Column("foo", Integer), String), "foo", dialect=dialect
)
示例12: test_columnclause_schema_column_five
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import CHAR [as 别名]
def test_columnclause_schema_column_five(self, connection):
keyed2 = self.tables.keyed2
# this is also addressed by [ticket:2932]
stmt = text("select a AS keyed2_a, b AS keyed2_b from keyed2").columns(
keyed2_a=CHAR, keyed2_b=CHAR
)
row = connection.execute(stmt).first()
with testing.expect_deprecated(
"Retrieving row values using Column objects "
"with only matching names"
):
in_(keyed2.c.a, row)
with testing.expect_deprecated(
"Retrieving row values using Column objects "
"with only matching names"
):
in_(keyed2.c.b, row)
with testing.expect_deprecated(
"Retrieving row values using Column objects "
"with only matching names",
"The SelectBase.c and SelectBase.columns",
):
in_(stmt.c.keyed2_a, row)
with testing.expect_deprecated(
"Retrieving row values using Column objects "
"with only matching names",
"The SelectBase.c and SelectBase.columns",
):
in_(stmt.c.keyed2_b, row)
示例13: define_tables
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import CHAR [as 别名]
def define_tables(cls, metadata):
Table(
"text1",
metadata,
Column("a", CHAR(2)),
Column("b", CHAR(2)),
Column("c", CHAR(2)),
Column("d", CHAR(2)),
)
示例14: test_literal_adapt
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import CHAR [as 别名]
def test_literal_adapt(self):
# literals get typed based on the types dictionary, unless
# compatible with the left side type
expr = column("foo", String) == 5
eq_(expr.right.type._type_affinity, Integer)
expr = column("foo", String) == "asdf"
eq_(expr.right.type._type_affinity, String)
expr = column("foo", CHAR) == 5
eq_(expr.right.type._type_affinity, Integer)
expr = column("foo", CHAR) == "asdf"
eq_(expr.right.type.__class__, CHAR)
示例15: test_char_length
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import CHAR [as 别名]
def test_char_length(self):
self.assert_compile(CHAR(50), "CHAR(50)")