本文整理匯總了Python中sqlalchemy.sql.compiler.SQLCompiler方法的典型用法代碼示例。如果您正苦於以下問題:Python compiler.SQLCompiler方法的具體用法?Python compiler.SQLCompiler怎麽用?Python compiler.SQLCompiler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sqlalchemy.sql.compiler
的用法示例。
在下文中一共展示了compiler.SQLCompiler方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: compile_query
# 需要導入模塊: from sqlalchemy.sql import compiler [as 別名]
# 或者: from sqlalchemy.sql.compiler import SQLCompiler [as 別名]
def compile_query(query):
""" 把一個 sqlalchemy query object 編譯成mysql風格的 sql 語句 """
from sqlalchemy.sql import compiler
from sqlalchemy.dialects import mysql as mysql_dialetct
from pymysql.converters import conversions, escape_item, encoders
dialect = mysql_dialetct.dialect()
statement = query.statement
comp = compiler.SQLCompiler(dialect, statement)
comp.compile()
enc = dialect.encoding
comp_params = comp.params
params = []
for k in comp.positiontup:
v = comp_params[k]
if six.PY2 and isinstance(v, six.string_types) and not isinstance(v, six.text_type):
v = v.decode("utf8")
v = escape_item(v, conversions, encoders)
params.append(v)
return (comp.string % tuple(params))
示例2: function_argspec
# 需要導入模塊: from sqlalchemy.sql import compiler [as 別名]
# 或者: from sqlalchemy.sql.compiler import SQLCompiler [as 別名]
def function_argspec(self, fn, **kw):
if len(fn.clauses) > 0 or fn.name.upper() not in NO_ARG_FNS:
return compiler.SQLCompiler.function_argspec(self, fn, **kw)
else:
return ""
示例3: visit_join
# 需要導入模塊: from sqlalchemy.sql import compiler [as 別名]
# 或者: from sqlalchemy.sql.compiler import SQLCompiler [as 別名]
def visit_join(self, join, **kwargs):
if self.dialect.use_ansi:
return compiler.SQLCompiler.visit_join(self, join, **kwargs)
else:
kwargs['asfrom'] = True
if isinstance(join.right, expression.FromGrouping):
right = join.right.element
else:
right = join.right
return self.process(join.left, **kwargs) + \
", " + self.process(right, **kwargs)
示例4: setUp
# 需要導入模塊: from sqlalchemy.sql import compiler [as 別名]
# 或者: from sqlalchemy.sql.compiler import SQLCompiler [as 別名]
def setUp(self):
class MyTypeCompiler(compiler.GenericTypeCompiler):
def visit_mytype(self, type_, **kw):
return "MYTYPE"
def visit_myothertype(self, type_, **kw):
return "MYOTHERTYPE"
class MyCompiler(compiler.SQLCompiler):
def visit_json_getitem_op_binary(self, binary, operator, **kw):
return self._generate_generic_binary(
binary, " -> ", eager_grouping=True, **kw
)
def visit_json_path_getitem_op_binary(
self, binary, operator, **kw
):
return self._generate_generic_binary(
binary, " #> ", eager_grouping=True, **kw
)
def visit_getitem_binary(self, binary, operator, **kw):
raise NotImplementedError()
class MyDialect(default.DefaultDialect):
statement_compiler = MyCompiler
type_compiler = MyTypeCompiler
class MyType(JSON):
__visit_name__ = "mytype"
pass
self.MyType = MyType
self.__dialect__ = MyDialect()
示例5: test_select_precol_compile_ordering
# 需要導入模塊: from sqlalchemy.sql import compiler [as 別名]
# 或者: from sqlalchemy.sql.compiler import SQLCompiler [as 別名]
def test_select_precol_compile_ordering(self):
s1 = (
select([column("x")])
.select_from(text("a"))
.limit(5)
.scalar_subquery()
)
s2 = select([s1]).limit(10)
class MyCompiler(compiler.SQLCompiler):
def get_select_precolumns(self, select, **kw):
result = ""
if select._limit:
result += "FIRST %s " % self.process(
literal(select._limit), **kw
)
if select._offset:
result += "SKIP %s " % self.process(
literal(select._offset), **kw
)
return result
def limit_clause(self, select, **kw):
return ""
dialect = default.DefaultDialect()
dialect.statement_compiler = MyCompiler
dialect.paramstyle = "qmark"
dialect.positional = True
self.assert_compile(
s2,
"SELECT FIRST ? (SELECT FIRST ? x FROM a) AS anon_1",
checkpositional=(10, 5),
dialect=dialect,
)
示例6: visit_join
# 需要導入模塊: from sqlalchemy.sql import compiler [as 別名]
# 或者: from sqlalchemy.sql.compiler import SQLCompiler [as 別名]
def visit_join(self, join, **kwargs):
if self.dialect.use_ansi:
return compiler.SQLCompiler.visit_join(self, join, **kwargs)
else:
kwargs['asfrom'] = True
if isinstance(join.right, expression.FromGrouping):
right = join.right.element
else:
right = join.right
return self.process(join.left, **kwargs) + \
", " + self.process(right, **kwargs)