本文整理汇总了Python中sqlalchemy.schema.DDLElement方法的典型用法代码示例。如果您正苦于以下问题:Python schema.DDLElement方法的具体用法?Python schema.DDLElement怎么用?Python schema.DDLElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy.schema
的用法示例。
在下文中一共展示了schema.DDLElement方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _exec
# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import DDLElement [as 别名]
def _exec(self, construct, execution_options=None,
multiparams=(),
params=util.immutabledict()):
if isinstance(construct, string_types):
construct = text(construct)
if self.as_sql:
if multiparams or params:
# TODO: coverage
raise Exception("Execution arguments not allowed with as_sql")
if self.literal_binds and not isinstance(
construct, schema.DDLElement):
compile_kw = dict(compile_kwargs={"literal_binds": True})
else:
compile_kw = {}
self.static_output(text_type(
construct.compile(dialect=self.dialect, **compile_kw)
).replace("\t", " ").strip() + self.command_terminator)
else:
conn = self.connection
if execution_options:
conn = conn.execution_options(**execution_options)
return conn.execute(construct, *multiparams, **params)
示例2: __init__
# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import DDLElement [as 别名]
def __init__(self, name, if_exists=False, cascade=False):
"""
Build the DropMaterializedView DDLElement.
Parameters
----------
name: str
name of the materialized view to drop
if_exists: bool, optional
if True, the IF EXISTS clause is added. This will make the query
successful even if the view does not exist, i.e. it lets you drop
a non-existant view. Defaults to False.
cascade: bool, optional
if True, the CASCADE clause is added. This will drop all
views/objects in the DB that depend on this materialized view.
Defaults to False.
"""
self.name = name
self.if_exists = if_exists
self.cascade = cascade
示例3: _exec
# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import DDLElement [as 别名]
def _exec(
self,
construct,
execution_options=None,
multiparams=(),
params=util.immutabledict(),
):
if isinstance(construct, string_types):
construct = text(construct)
if self.as_sql:
if multiparams or params:
# TODO: coverage
raise Exception("Execution arguments not allowed with as_sql")
if self.literal_binds and not isinstance(
construct, schema.DDLElement
):
compile_kw = dict(compile_kwargs={"literal_binds": True})
else:
compile_kw = {}
self.static_output(
text_type(
construct.compile(dialect=self.dialect, **compile_kw)
)
.replace("\t", " ")
.strip()
+ self.command_terminator
)
else:
conn = self.connection
if execution_options:
conn = conn.execution_options(**execution_options)
return conn.execute(construct, *multiparams, **params)
示例4: test_dialect_specific
# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import DDLElement [as 别名]
def test_dialect_specific(self):
class AddThingy(DDLElement):
__visit_name__ = "add_thingy"
class DropThingy(DDLElement):
__visit_name__ = "drop_thingy"
@compiles(AddThingy, "sqlite")
def visit_add_thingy_sqlite(thingy, compiler, **kw):
return "ADD SPECIAL SL THINGY"
@compiles(AddThingy)
def visit_add_thingy(thingy, compiler, **kw):
return "ADD THINGY"
@compiles(DropThingy)
def visit_drop_thingy(thingy, compiler, **kw):
return "DROP THINGY"
self.assert_compile(AddThingy(), "ADD THINGY")
self.assert_compile(DropThingy(), "DROP THINGY")
from sqlalchemy.dialects.sqlite import base
self.assert_compile(
AddThingy(), "ADD SPECIAL SL THINGY", dialect=base.dialect()
)
self.assert_compile(
DropThingy(), "DROP THINGY", dialect=base.dialect()
)
@compiles(DropThingy, "sqlite")
def visit_drop_thingy_sqlite(thingy, compiler, **kw):
return "DROP SPECIAL SL THINGY"
self.assert_compile(
DropThingy(), "DROP SPECIAL SL THINGY", dialect=base.dialect()
)
self.assert_compile(DropThingy(), "DROP THINGY")