diff options
| author | Renato Massaro <renato@hackerexperience.com> | 2015-07-14 15:42:46 -0300 |
|---|---|---|
| committer | Renato Massaro <renato@hackerexperience.com> | 2015-07-14 15:42:46 -0300 |
| commit | f272a4d92295d69446aea712e2927c1c731d0e6c (patch) | |
| tree | 7d3866744f4333eca78f35db6c197f20f38061c1 /lib/sqlalchemy | |
| parent | b68c9ac93eea62a1f4ae2c0701e5af7c432e9432 (diff) | |
| download | sqlalchemy-pr/187.tar.gz | |
Add basic LTREE support; missing testspr/187
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/dialects/postgresql/__init__.py | 4 | ||||
| -rw-r--r-- | lib/sqlalchemy/dialects/postgresql/base.py | 59 |
2 files changed, 60 insertions, 3 deletions
diff --git a/lib/sqlalchemy/dialects/postgresql/__init__.py b/lib/sqlalchemy/dialects/postgresql/__init__.py index 98fe6f085..a5ddbd575 100644 --- a/lib/sqlalchemy/dialects/postgresql/__init__.py +++ b/lib/sqlalchemy/dialects/postgresql/__init__.py @@ -13,7 +13,7 @@ from .base import \ INTEGER, BIGINT, SMALLINT, VARCHAR, CHAR, TEXT, NUMERIC, FLOAT, REAL, \ INET, CIDR, UUID, BIT, MACADDR, OID, DOUBLE_PRECISION, TIMESTAMP, TIME, \ DATE, BYTEA, BOOLEAN, INTERVAL, ARRAY, ENUM, dialect, array, Any, All, \ - TSVECTOR, DropEnumType + TSVECTOR, DropEnumType, LTREE, LQUERY, LTXTQUERY from .constraints import ExcludeConstraint from .hstore import HSTORE, hstore from .json import JSON, JSONElement, JSONB @@ -27,5 +27,5 @@ __all__ = ( 'INTERVAL', 'ARRAY', 'ENUM', 'dialect', 'Any', 'All', 'array', 'HSTORE', 'hstore', 'INT4RANGE', 'INT8RANGE', 'NUMRANGE', 'DATERANGE', 'TSRANGE', 'TSTZRANGE', 'json', 'JSON', 'JSONB', 'JSONElement', - 'DropEnumType' + 'DropEnumType', 'LTREE', 'LQUERY', 'LTXTQUERY' ) diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 22c66dbbb..0793ca3ab 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -598,6 +598,51 @@ class OID(sqltypes.TypeEngine): __visit_name__ = "OID" +class LTREE(sqltypes.TypeEngine): + + """Postgresql LTREE type. + """ + + class Comparator(sqltypes.Concatenable.Comparator): + + def ancestor_of(self, other): + if isinstance(other, list): + return self.expr.op('@>')(expression.cast(other, ARRAY(LTREE))) + else: + return self.expr.op('@>')(other) + + def descendant_of(self, other): + if isinstance(other, list): + return self.expr.op('<@')(expression.cast(other, ARRAY(LTREE))) + else: + return self.expr.op('<@')(other) + + def lquery(self, other): + if isinstance(other, list): + return self.expr.op('?')(expression.cast(other, ARRAY(LQUERY))) + else: + return self.expr.op('~')(other) + + def ltxtquery(self, other): + return self.expr.op('@')(other) + + comparator_factory = Comparator + + __visit_name__ = 'LTREE' + +PGLTree = LTREE + + +class LQUERY(sqltypes.TypeEngine): + __visit_name__ = 'LQUERY' +PGLQuery = LQUERY + + +class LTXTQUERY(sqltypes.TypeEngine): + __visit_name__ = 'LTXTQUERY' +PGLTxtQuery = LTXTQUERY + + class TIMESTAMP(sqltypes.TIMESTAMP): def __init__(self, timezone=False, precision=None): @@ -1360,7 +1405,10 @@ ischema_names = { 'interval': INTERVAL, 'interval year to month': INTERVAL, 'interval day to second': INTERVAL, - 'tsvector': TSVECTOR + 'tsvector': TSVECTOR, + 'ltree': LTREE, + 'lquery': LQUERY, + 'ltxtquery': LTXTQUERY } @@ -1782,6 +1830,15 @@ class PGTypeCompiler(compiler.GenericTypeCompiler): if type_.dimensions is not None else 1)) + def visit_LTREE(self, type_, **kw): + return 'LTREE' + + def visit_LQUERY(self, type_, **kw): + return 'LQUERY' + + def visit_LTXTQUERY(self, type_, **kw): + return 'LTXTQUERY' + class PGIdentifierPreparer(compiler.IdentifierPreparer): |
