Add LtreeType example

This commit is contained in:
Konsta Vesterinen
2016-04-25 21:18:28 +03:00
parent 376407bc8e
commit 3a44582616
2 changed files with 19 additions and 1 deletions

View File

@@ -81,7 +81,7 @@ class Ltree(object):
assert Ltree('1.2.3.4.5').lca('1.2', '1.2.3') == '1'
Ltree objects can be concatenated.1
Ltree objects can be concatenated.
::

View File

@@ -19,6 +19,24 @@ class LtreeType(types.Concatenable, types.UserDefinedType, ScalarCoercible):
in hierarchial tree-like structure. For more detailed information please
refer to http://www.postgresql.org/docs/current/static/ltree.html
::
from sqlalchemy_utils import LtreeType
class DocumentSection(Base):
__tablename__ = 'document_section'
id = sa.Column(sa.Integer, autoincrement=True)
path = sa.Column(LtreeType)
section = DocumentSection(name='Countries.Finland')
session.add(section)
session.commit()
section.path # Ltree('Countries.Finland')
.. note::
Using :class:`LtreeType`, :class:`LQUERY` and :class:`LTXTQUERY` types
may require installation of Postgresql ltree extension on the server