diff options
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql')
-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): |