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/dialects/postgresql/base.py | |
parent | b68c9ac93eea62a1f4ae2c0701e5af7c432e9432 (diff) | |
download | sqlalchemy-pr/187.tar.gz |
Add basic LTREE support; missing testspr/187
Diffstat (limited to 'lib/sqlalchemy/dialects/postgresql/base.py')
-rw-r--r-- | lib/sqlalchemy/dialects/postgresql/base.py | 59 |
1 files changed, 58 insertions, 1 deletions
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): |