本文整理汇总了Python中alembic.operations.Operations.inline_literal方法的典型用法代码示例。如果您正苦于以下问题:Python Operations.inline_literal方法的具体用法?Python Operations.inline_literal怎么用?Python Operations.inline_literal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类alembic.operations.Operations
的用法示例。
在下文中一共展示了Operations.inline_literal方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PostgresqlInlineLiteralTest
# 需要导入模块: from alembic.operations import Operations [as 别名]
# 或者: from alembic.operations.Operations import inline_literal [as 别名]
class PostgresqlInlineLiteralTest(TestBase):
__only_on__ = "postgresql"
__backend__ = True
@classmethod
def setup_class(cls):
cls.bind = config.db
cls.bind.execute(
"""
create table tab (
col varchar(50)
)
"""
)
cls.bind.execute(
"""
insert into tab (col) values
('old data 1'),
('old data 2.1'),
('old data 3')
"""
)
@classmethod
def teardown_class(cls):
cls.bind.execute("drop table tab")
def setUp(self):
self.conn = self.bind.connect()
ctx = MigrationContext.configure(self.conn)
self.op = Operations(ctx)
def tearDown(self):
self.conn.close()
def test_inline_percent(self):
# TODO: here's the issue, you need to escape this.
tab = table("tab", column("col"))
self.op.execute(
tab.update()
.where(tab.c.col.like(self.op.inline_literal("%.%")))
.values(col=self.op.inline_literal("new data")),
execution_options={"no_parameters": True},
)
eq_(
self.conn.execute(
"select count(*) from tab where col='new data'"
).scalar(),
1,
)
示例2: PostgresqlInlineLiteralTest
# 需要导入模块: from alembic.operations import Operations [as 别名]
# 或者: from alembic.operations.Operations import inline_literal [as 别名]
class PostgresqlInlineLiteralTest(TestCase):
@classmethod
def setup_class(cls):
cls.bind = db_for_dialect("postgresql")
cls.bind.execute("""
create table tab (
col varchar(50)
)
""")
cls.bind.execute("""
insert into tab (col) values
('old data 1'),
('old data 2.1'),
('old data 3')
""")
@classmethod
def teardown_class(cls):
cls.bind.execute("drop table tab")
def setUp(self):
self.conn = self.bind.connect()
ctx = MigrationContext.configure(self.conn)
self.op = Operations(ctx)
def tearDown(self):
self.conn.close()
def test_inline_percent(self):
# TODO: here's the issue, you need to escape this.
tab = table('tab', column('col'))
self.op.execute(
tab.update().where(
tab.c.col.like(self.op.inline_literal('%.%'))
).values(col=self.op.inline_literal('new data')),
execution_options={'no_parameters': True}
)
eq_(
self.conn.execute(
"select count(*) from tab where col='new data'").scalar(),
1,
)