Added match operator for TSVectorType

This commit is contained in:
Konsta Vesterinen
2013-10-04 09:18:34 +03:00
parent da5cb7c386
commit 0a71df2c81
5 changed files with 20 additions and 2 deletions

View File

@@ -4,6 +4,12 @@ Changelog
Here you can see the full list of changes between each SQLAlchemy-Utils release.
0.16.23 (2013-10-04)
^^^^^^^^^^^^^^^^^^^^
- Added match operator for TSVectorType
0.16.22 (2013-10-03)
^^^^^^^^^^^^^^^^^^^^

View File

@@ -56,7 +56,7 @@ for name, requirements in extras_require.items():
setup(
name='SQLAlchemy-Utils',
version='0.16.22',
version='0.16.23',
url='https://github.com/kvesteri/sqlalchemy-utils',
license='BSD',
author='Konsta Vesterinen, Ryan Leckey, Janne Vanhala, Vesa Uimonen',

View File

@@ -38,7 +38,7 @@ from .types import (
)
__version__ = '0.16.22'
__version__ = '0.16.23'
__all__ = (

View File

@@ -3,6 +3,12 @@ from sqlalchemy.dialects.postgresql.base import ischema_names
class TSVectorType(sa.types.UserDefinedType):
class comparator_factory(sa.types.TypeEngine.Comparator):
def match(self, other):
from sqlalchemy_utils.expressions import tsvector_match
return tsvector_match(self.expr, other)
def __init__(self, *args, **kwargs):
"""
Initializes new TSVectorType

View File

@@ -1,3 +1,4 @@
import six
import sqlalchemy as sa
from sqlalchemy_utils import TSVectorType
from tests import TestCase
@@ -35,3 +36,8 @@ class TestTSVector(TestCase):
type_ = TSVectorType('name', 'age', catalog='pg_catalog.simple')
assert type_.columns == ('name', 'age')
assert type_.options['catalog'] == 'pg_catalog.simple'
def test_match(self):
assert six.text_type(self.User.search_index.match(u'something')) == (
'("user".search_index) @@ :tsvector_match_1'
)