Skip to content

Commit

Permalink
added support for func by name for $lb
Browse files Browse the repository at this point in the history
  • Loading branch information
daimor committed Dec 26, 2023
1 parent ba84f80 commit 15f9b4c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions sqlalchemy_iris/types.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"
Expand Down
16 changes: 16 additions & 0 deletions tests/test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
],
)

0 comments on commit 15f9b4c

Please sign in to comment.