summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/ext/compiler.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-09-09 14:39:25 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2012-09-09 14:39:25 -0400
commit1c325dc9c73820e78ab79d4aa160dc0f6cbe3b65 (patch)
tree02b1a3fb6f24fe0bddd582a3fec519c99d40d36c /lib/sqlalchemy/ext/compiler.py
parentb96250d0063cd7ce9cc1f95abade68e6656d6acb (diff)
downloadsqlalchemy-1c325dc9c73820e78ab79d4aa160dc0f6cbe3b65.tar.gz
- [feature] Added a hook to the system of rendering
CREATE TABLE that provides access to the render for each Column individually, by constructing a @compiles function against the new schema.CreateColumn construct. [ticket:2463]
Diffstat (limited to 'lib/sqlalchemy/ext/compiler.py')
-rw-r--r--lib/sqlalchemy/ext/compiler.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/sqlalchemy/ext/compiler.py b/lib/sqlalchemy/ext/compiler.py
index d5fbec518..e3e668364 100644
--- a/lib/sqlalchemy/ext/compiler.py
+++ b/lib/sqlalchemy/ext/compiler.py
@@ -368,8 +368,12 @@ Example usage::
"""
from .. import exc
+from ..sql import visitors
def compiles(class_, *specs):
+ """Register a function as a compiler for a
+ given :class:`.ClauseElement` type."""
+
def decorate(fn):
existing = class_.__dict__.get('_compiler_dispatcher', None)
existing_dispatch = class_.__dict__.get('_compiler_dispatch')
@@ -392,6 +396,17 @@ def compiles(class_, *specs):
return fn
return decorate
+def deregister(class_):
+ """Remove all custom compilers associated with a given
+ :class:`.ClauseElement` type."""
+
+ if hasattr(class_, '_compiler_dispatcher'):
+ # regenerate default _compiler_dispatch
+ visitors._generate_dispatch(class_)
+ # remove custom directive
+ del class_._compiler_dispatcher
+
+
class _dispatcher(object):
def __init__(self):
self.specs = {}