From 15f9b4c79a1f1ecf7e6f872f2151a9a25592b01a Mon Sep 17 00:00:00 2001 From: Dmitry Maslennikov Date: Tue, 26 Dec 2023 12:29:28 +0400 Subject: [PATCH] added support for func by name for $lb --- sqlalchemy_iris/types.py | 10 ++++++++++ tests/test_suite.py | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/sqlalchemy_iris/types.py b/sqlalchemy_iris/types.py index 36ac6c2..6b4a122 100644 --- a/sqlalchemy_iris/types.py +++ b/sqlalchemy_iris/types.py @@ -1,5 +1,6 @@ import datetime from decimal import Decimal +from sqlalchemy import func from sqlalchemy.sql import sqltypes from sqlalchemy.types import UserDefinedType from uuid import UUID as _python_UUID @@ -236,6 +237,15 @@ def process(value): return process + class comparator_factory(UserDefinedType.Comparator): + def func(self, funcname: str, other): + if not isinstance(other, list) and not isinstance(other, tuple): + raise ValueError("expected list or tuple, got '%s'" % type(other)) + irislist = IRISList() + for item in other: + irislist.add(item) + return getattr(func, funcname)(self, irislist.getBuffer()) + class BIT(sqltypes.TypeEngine): __visit_name__ = "BIT" diff --git a/tests/test_suite.py b/tests/test_suite.py index b48ff8e..0c7e116 100644 --- a/tests/test_suite.py +++ b/tests/test_suite.py @@ -321,3 +321,19 @@ def test_listbuild(self): (None,), ], ) + self._assert_result( + select(self.tables.data).where(self.tables.data.c.val == [1.0] * 50), + [ + ([1.0] * 50,), + ], + ) + + self._assert_result( + select( + self.tables.data, + self.tables.data.c.val.func("$listsame", [1.0] * 50).label("same"), + ).limit(1), + [ + ([1.0] * 50, 1), + ], + )