本文整理汇总了Python中sqlalchemy.sql.compiler.GenericTypeCompiler方法的典型用法代码示例。如果您正苦于以下问题:Python compiler.GenericTypeCompiler方法的具体用法?Python compiler.GenericTypeCompiler怎么用?Python compiler.GenericTypeCompiler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy.sql.compiler
的用法示例。
在下文中一共展示了compiler.GenericTypeCompiler方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_kwarg_legacy_typecompiler
# 需要导入模块: from sqlalchemy.sql import compiler [as 别名]
# 或者: from sqlalchemy.sql.compiler import GenericTypeCompiler [as 别名]
def test_kwarg_legacy_typecompiler(self):
from sqlalchemy.sql import compiler
class SomeTypeCompiler(compiler.GenericTypeCompiler):
# transparently decorated w/ kw decorator
def visit_VARCHAR(self, type_):
return "MYVARCHAR"
# not affected
def visit_INTEGER(self, type_, **kw):
return "MYINTEGER %s" % kw["type_expression"].name
dialect = default.DefaultDialect()
dialect.type_compiler = SomeTypeCompiler(dialect)
self.assert_compile(
ddl.CreateColumn(Column("bar", VARCHAR(50))),
"bar MYVARCHAR",
dialect=dialect,
)
self.assert_compile(
ddl.CreateColumn(Column("bar", INTEGER)),
"bar MYINTEGER bar",
dialect=dialect,
)
示例2: setUp
# 需要导入模块: from sqlalchemy.sql import compiler [as 别名]
# 或者: from sqlalchemy.sql.compiler import GenericTypeCompiler [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()