diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-04-10 19:45:34 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-04-10 19:45:34 -0400 |
| commit | cf9cac34ac8df5613ef2d24884030df8aa749580 (patch) | |
| tree | c96e90ee2283b64b4fa84c12729316c28caeb41c /lib/sqlalchemy/ext/compiler.py | |
| parent | 44c67fef8cc578ffbca409ad95e6471b4cb4d02a (diff) | |
| parent | 36c05de373f9cbb198573704f2bc28fea8ca9113 (diff) | |
| download | sqlalchemy-cf9cac34ac8df5613ef2d24884030df8aa749580.tar.gz | |
merge default
Diffstat (limited to 'lib/sqlalchemy/ext/compiler.py')
| -rw-r--r-- | lib/sqlalchemy/ext/compiler.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/sqlalchemy/ext/compiler.py b/lib/sqlalchemy/ext/compiler.py index 20d6aa05f..68c434fd9 100644 --- a/lib/sqlalchemy/ext/compiler.py +++ b/lib/sqlalchemy/ext/compiler.py @@ -119,6 +119,23 @@ overriding routine and cause an endless loop. Such as, to add "prefix" to all The above compiler will prefix all INSERT statements with "some prefix" when compiled. +Changing Compilation of Types +============================= + +``compiler`` works for types, too, such as below where we implement the MS-SQL specific 'max' keyword for ``String``/``VARCHAR``:: + + @compiles(String, 'mssql') + @compiles(VARCHAR, 'mssql') + def compile_varchar(element, compiler, **kw): + if element.length == 'max': + return "VARCHAR('max')" + else: + return compiler.visit_VARCHAR(element, **kw) + + foo = Table('foo', metadata, + Column('data', VARCHAR('max')) + ) + Subclassing Guidelines ====================== @@ -175,7 +192,7 @@ A big part of using the compiler extension is subclassing SQLAlchemy expression used with any expression class that represents a "standalone" SQL statement that can be passed directly to an ``execute()`` method. It is already implicit within ``DDLElement`` and ``FunctionElement``. - + """ def compiles(class_, *specs): |
