Python sqlalchemy.sql.compiler.GenericTypeCompiler() Examples
The following are 3
code examples of sqlalchemy.sql.compiler.GenericTypeCompiler().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
sqlalchemy.sql.compiler
, or try the search function
.
Example #1
Source File: test_types.py From sqlalchemy with MIT License | 6 votes |
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, )
Example #2
Source File: test_operators.py From sqlalchemy with MIT License | 5 votes |
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()
Example #3
Source File: test_operators.py From sqlalchemy with MIT License | 5 votes |
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_slice(self, element, **kw): return "%s:%s" % ( self.process(element.start, **kw), self.process(element.stop, **kw), ) def visit_getitem_binary(self, binary, operator, **kw): return "%s[%s]" % ( self.process(binary.left, **kw), self.process(binary.right, **kw), ) class MyDialect(default.DefaultDialect): statement_compiler = MyCompiler type_compiler = MyTypeCompiler class MyType(ARRAY): __visit_name__ = "mytype" def __init__(self, zero_indexes=False, dimensions=1): if zero_indexes: self.zero_indexes = zero_indexes self.dimensions = dimensions self.item_type = Integer() self.MyType = MyType self.__dialect__ = MyDialect()