本文整理汇总了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)