本文整理匯總了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")