Permalink
Browse files

Merge branch 'tsvector' of https://bitbucket.org/nibrahim/sqlalchemy/…

…branch/tsvector into tsvector
  • Loading branch information...
zzzeek committed Dec 10, 2013
2 parents 111c615 + d3b65cd commit d5a86d8f86c0eef8968c8915be19b94ad4682151
@@ -17,7 +17,7 @@ they originate from :mod:`sqlalchemy.types` or from the local dialect::
DOUBLE_PRECISION, ENUM, FLOAT, HSTORE, INET, INTEGER, \
INTERVAL, MACADDR, NUMERIC, REAL, SMALLINT, TEXT, TIME, \
TIMESTAMP, UUID, VARCHAR, INT4RANGE, INT8RANGE, NUMRANGE, \
- DATERANGE, TSRANGE, TSTZRANGE
+ DATERANGE, TSRANGE, TSTZRANGE, TSVECTOR
Types which are specific to PostgreSQL, or have PostgreSQL-specific
construction arguments, are as follows:
@@ -77,6 +77,8 @@ construction arguments, are as follows:
.. autoclass:: REAL
:members: __init__
+.. autoclass:: TSVECTOR
+ :members: __init__
.. autoclass:: UUID
:members: __init__
@@ -11,7 +11,8 @@
from .base import \
INTEGER, BIGINT, SMALLINT, VARCHAR, CHAR, TEXT, NUMERIC, FLOAT, REAL, \
INET, CIDR, UUID, BIT, MACADDR, DOUBLE_PRECISION, TIMESTAMP, TIME, \
- DATE, BYTEA, BOOLEAN, INTERVAL, ARRAY, ENUM, dialect, array, Any, All
+ DATE, BYTEA, BOOLEAN, INTERVAL, ARRAY, ENUM, dialect, array, Any, All, \
+ TSVECTOR
from .constraints import ExcludeConstraint
from .hstore import HSTORE, hstore
from .ranges import INT4RANGE, INT8RANGE, NUMRANGE, DATERANGE, TSRANGE, \
@@ -23,5 +24,5 @@
'DOUBLE_PRECISION', 'TIMESTAMP', 'TIME', 'DATE', 'BYTEA', 'BOOLEAN',
'INTERVAL', 'ARRAY', 'ENUM', 'dialect', 'Any', 'All', 'array', 'HSTORE',
'hstore', 'INT4RANGE', 'INT8RANGE', 'NUMRANGE', 'DATERANGE',
- 'TSRANGE', 'TSTZRANGE'
+ 'TSRANGE', 'TSTZRANGE', 'TSVECTOR'
)
@@ -368,6 +368,35 @@ def process(value):
PGUuid = UUID
+class TSVECTOR(sqltypes.TypeEngine):
+ """The TSVECTOR type implements the Postgresql text search type
+ TSVECTOR.
+
+ It can be used to do full text queries on natural language
+ *documents*.
+
+ Search queries are performed using the ``@@`` operator in
+ postgresql. This is made available with the ``match`` method
+ available on the column.
+
+ This means that if you have a table ``Example`` with a column
+ ``text`` of type ``TSVECTOR``, you can create a search clause like
+ so
+
+ ::
+
+ Example.text.match("search string")
+
+ which will be compiled to
+
+ ::
+
+ text @@ to_tsquery('search string')
+
+ """
+ __visit_name__ = 'TSVECTOR'
+
+
class _Slice(expression.ColumnElement):
__visit_name__ = 'slice'
@@ -913,6 +942,7 @@ def _on_metadata_drop(self, target, bind, checkfirst, **kw):
'interval': INTERVAL,
'interval year to month': INTERVAL,
'interval day to second': INTERVAL,
+ 'tsvector' : TSVECTOR
}
@@ -1163,6 +1193,9 @@ def visit_exclude_constraint(self, constraint):
class PGTypeCompiler(compiler.GenericTypeCompiler):
+ def visit_TSVECTOR(self, type):
+ return "TSVECTOR"
+
def visit_INET(self, type_):
return "INET"
@@ -836,7 +836,8 @@ def get_col_spec(self):
Column('plain_interval', postgresql.INTERVAL),
Column('year_interval', y2m()),
Column('month_interval', d2s()),
- Column('precision_interval', postgresql.INTERVAL(precision=3))
+ Column('precision_interval', postgresql.INTERVAL(precision=3)),
+ Column('tsvector_document', postgresql.TSVECTOR)
)
metadata.create_all()

0 comments on commit d5a86d8

Please sign in to comment.