Skip to content

Commit 15f9b4c

Browse files
committed
added support for func by name for $lb
1 parent ba84f80 commit 15f9b4c

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

sqlalchemy_iris/types.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import datetime
22
from decimal import Decimal
3+
from sqlalchemy import func
34
from sqlalchemy.sql import sqltypes
45
from sqlalchemy.types import UserDefinedType
56
from uuid import UUID as _python_UUID
@@ -236,6 +237,15 @@ def process(value):
236237

237238
return process
238239

240+
class comparator_factory(UserDefinedType.Comparator):
241+
def func(self, funcname: str, other):
242+
if not isinstance(other, list) and not isinstance(other, tuple):
243+
raise ValueError("expected list or tuple, got '%s'" % type(other))
244+
irislist = IRISList()
245+
for item in other:
246+
irislist.add(item)
247+
return getattr(func, funcname)(self, irislist.getBuffer())
248+
239249

240250
class BIT(sqltypes.TypeEngine):
241251
__visit_name__ = "BIT"

tests/test_suite.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,19 @@ def test_listbuild(self):
321321
(None,),
322322
],
323323
)
324+
self._assert_result(
325+
select(self.tables.data).where(self.tables.data.c.val == [1.0] * 50),
326+
[
327+
([1.0] * 50,),
328+
],
329+
)
330+
331+
self._assert_result(
332+
select(
333+
self.tables.data,
334+
self.tables.data.c.val.func("$listsame", [1.0] * 50).label("same"),
335+
).limit(1),
336+
[
337+
([1.0] * 50, 1),
338+
],
339+
)

0 commit comments

Comments
 (0)