diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-08-26 18:01:21 -0400 | 
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-08-26 18:01:21 -0400 | 
| commit | c7ceb00792bb0d22c02887021115f0f607bf07ec (patch) | |
| tree | 2e35149c11706732a8007abc9563b13beaa92d83 /lib/sqlalchemy/sql/functions.py | |
| parent | b0e0bbb816b578910d0e08f034a732fc5fc898fd (diff) | |
| download | sqlalchemy-c7ceb00792bb0d22c02887021115f0f607bf07ec.tar.gz | |
- add "identifier", can differentiate between "name" rendered and "identifier" in func.
Diffstat (limited to 'lib/sqlalchemy/sql/functions.py')
| -rw-r--r-- | lib/sqlalchemy/sql/functions.py | 22 | 
1 files changed, 20 insertions, 2 deletions
| diff --git a/lib/sqlalchemy/sql/functions.py b/lib/sqlalchemy/sql/functions.py index 24f7e81b4..b24f8cbec 100644 --- a/lib/sqlalchemy/sql/functions.py +++ b/lib/sqlalchemy/sql/functions.py @@ -17,12 +17,13 @@ _registry = util.defaultdict(dict)  class _GenericMeta(VisitableType):      def __init__(cls, clsname, bases, clsdict):          cls.name = name = clsdict.get('name', clsname) +        cls.identifier = identifier = clsdict.get('identifier', name)          package = clsdict.pop('package', '_default')          # legacy          if '__return_type__' in clsdict:              cls.type = clsdict['__return_type__']          reg = _registry[package] -        reg[name] = cls +        reg[identifier] = cls          super(_GenericMeta, cls).__init__(clsname, bases, clsdict)  class GenericFunction(Function): @@ -69,9 +70,26 @@ class GenericFunction(Function):          print select([func.time.as_utc()]) +    A final option is to allow the function to be accessed +    from one name in :data:`.func` but to render as a different name. +    The ``identifier`` attribute will override the name used to +    access the function as loaded from :data:`.func`, but will retain +    the usage of ``name`` as the rendered name:: + +        class GeoBuffer(GenericFunction): +            type = Geometry +            package = "geo" +            name = "ST_Buffer" +            identifier = "buffer" + +    The above function will render as follows:: + +        >>> print func.geo.buffer() +        ST_Buffer() +      .. versionadded:: 0.8 :class:`.GenericFunction` now supports         automatic registration of new functions as well as package -       support. +       and custom naming support.      .. versionchanged:: 0.8 The attribute name ``type`` is used         to specify the function's return type at the class level. | 
