Coverage for sqlmodel / sql / _expression_select_cls.py: 93%

15 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2026-06-10 09:40 +0000

1from typing import ( 1abcdefgh

2 TypeVar, 

3) 

4 

5from sqlalchemy.sql._typing import ( 1abcdefgh

6 _ColumnExpressionArgument, 

7) 

8from sqlalchemy.sql.expression import Select as _Select 1abcdefgh

9from typing_extensions import Self 1abcdefgh

10 

11_T = TypeVar("_T") 1abcdefgh

12 

13 

14# Separate this class in SelectBase, Select, and SelectOfScalar so that they can share 

15# where and having without having type overlap incompatibility in session.exec(). 

16class SelectBase(_Select[tuple[_T]]): 1abcdefgh

17 inherit_cache = True 1abcdefgh

18 

19 def where(self, *whereclause: _ColumnExpressionArgument[bool] | bool) -> Self: 1abcdefgh

20 """Return a new `Select` construct with the given expression added to 

21 its `WHERE` clause, joined to the existing clause via `AND`, if any. 

22 """ 

23 return super().where(*whereclause) # ty: ignore[invalid-argument-type] 2i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsbtbubvbwbxbybzbAbBbCbDbEbFbGbHbIbJbKbLbMbNbObPbQbRbSbTbUbVbWbXbYbZb0b1b2b3b4b5b6b7b8b9b!b#b$b%b'b(b)b*b+b,b-b.b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcccdcecfcgchcicjckclcmcncocpcqcrcsctcucvcwcxcyczcAcBcCcDcEcFcGcHcIcJcKcLcMcNcOcPcQcRcScTcUcVcWcXcYcZc0c1c2c3c4c5c6c7c8c9c!c#c$c%c'c(c)c*c+c,c-c.c/c:c;c=c?c@c[c]c^c_c`c{c|c}c~cadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$d%d'd(d)d*d+d,d-d.d/d:d;d=d?d@d[d]d^d_d`d

24 

25 def having(self, *having: _ColumnExpressionArgument[bool] | bool) -> Self: 1abcdefgh

26 """Return a new `Select` construct with the given expression added to 

27 its `HAVING` clause, joined to the existing clause via `AND`, if any. 

28 """ 

29 return super().having(*having) # ty: ignore[invalid-argument-type] 

30 

31 

32class Select(SelectBase[_T]): 1abcdefgh

33 inherit_cache = True 1abcdefgh

34 

35 

36# This is not comparable to sqlalchemy.sql.selectable.ScalarSelect, that has a different 

37# purpose. This is the same as a normal SQLAlchemy Select class where there's only one 

38# entity, so the result will be converted to a scalar by default. This way writing 

39# for loops on the results will feel natural. 

40class SelectOfScalar(SelectBase[_T]): 1abcdefgh

41 inherit_cache = True 1abcdefgh