Coverage for sqlmodel/orm/session.py: 100%

25 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-09-09 00:02 +0000

1from typing import ( 1fabcde

2 Any, 

3 Dict, 

4 Mapping, 

5 Optional, 

6 Sequence, 

7 TypeVar, 

8 Union, 

9 overload, 

10) 

11 

12from sqlalchemy import util 1fabcde

13from sqlalchemy.engine.interfaces import _CoreAnyExecuteParams 1fabcde

14from sqlalchemy.engine.result import Result, ScalarResult, TupleResult 1fabcde

15from sqlalchemy.orm import Query as _Query 1fabcde

16from sqlalchemy.orm import Session as _Session 1fabcde

17from sqlalchemy.orm._typing import OrmExecuteOptionsParameter 1fabcde

18from sqlalchemy.sql._typing import _ColumnsClauseArgument 1fabcde

19from sqlalchemy.sql.base import Executable as _Executable 1fabcde

20from sqlmodel.sql.base import Executable 1fabcde

21from sqlmodel.sql.expression import Select, SelectOfScalar 1fabcde

22from typing_extensions import deprecated 1fabcde

23 

24_TSelectParam = TypeVar("_TSelectParam", bound=Any) 1fabcde

25 

26 

27class Session(_Session): 1fabcde

28 @overload 1fabcde

29 def exec( 1abcde

30 self, 

31 statement: Select[_TSelectParam], 1abcde

32 *, 

33 params: Optional[Union[Mapping[str, Any], Sequence[Mapping[str, Any]]]] = None, 1fabcde

34 execution_options: Mapping[str, Any] = util.EMPTY_DICT, 1fabcde

35 bind_arguments: Optional[Dict[str, Any]] = None, 1fabcde

36 _parent_execute_state: Optional[Any] = None, 1fabcde

37 _add_event: Optional[Any] = None, 1fabcde

38 ) -> TupleResult[_TSelectParam]: ... 1fabcde

39 

40 @overload 1fabcde

41 def exec( 1abcde

42 self, 

43 statement: SelectOfScalar[_TSelectParam], 1abcde

44 *, 

45 params: Optional[Union[Mapping[str, Any], Sequence[Mapping[str, Any]]]] = None, 1fabcde

46 execution_options: Mapping[str, Any] = util.EMPTY_DICT, 1fabcde

47 bind_arguments: Optional[Dict[str, Any]] = None, 1fabcde

48 _parent_execute_state: Optional[Any] = None, 1fabcde

49 _add_event: Optional[Any] = None, 1fabcde

50 ) -> ScalarResult[_TSelectParam]: ... 1fabcde

51 

52 def exec( 1abcde

53 self, 

54 statement: Union[ 

55 Select[_TSelectParam], 

56 SelectOfScalar[_TSelectParam], 

57 Executable[_TSelectParam], 

58 ], 

59 *, 

60 params: Optional[Union[Mapping[str, Any], Sequence[Mapping[str, Any]]]] = None, 

61 execution_options: Mapping[str, Any] = util.EMPTY_DICT, 

62 bind_arguments: Optional[Dict[str, Any]] = None, 

63 _parent_execute_state: Optional[Any] = None, 

64 _add_event: Optional[Any] = None, 

65 ) -> Union[TupleResult[_TSelectParam], ScalarResult[_TSelectParam]]: 

66 results = super().execute( 2_e`eg {e|eh i j k l m n o p q r s t u v w x y z A B }e~eafbfcfdfefffgfC D hfifjfE F kflfG H I J K L M N O mfnfofpfP Q R S qfrfsftfufvfwfxfyfzfAfBfCfT DfEfU V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' FfGfHfIfJfKfLfMfNf( ) OfPfQf* + RfSf, - . / : ; = ? @ TfUfVfWf[ ] ^ _ XfYfZf0f1f2f3f4f5f6f7f8f9f!f` #f$f{ | } ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsbtbubvbwbxbybzbAbBb%f'f(f)f*f+f,f-f.fCbDbEbFb/f:f;fGbHb=f?fIbJbKbLbMbNbObPbQbRbSbTbUbVbWbXbYbZb@f[f]f^f0b1b2b3b_f`f{f|f}f~fagbgcgdgegfggghgigjg4b5bkglg6b7b8b9b!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~bacbcccdcecfcgchcicjckclcmcncocpcqcrcsctcmgngogpgqgrgsgtgugvgwgxgygzgAgBgCgDgucvcwcxcyczcEgFgGgHgIgJgAcBcCcDcKgLgMgNgEcFcGcHcIcJcKcLcMcNcOcPcQcRcScTcUcVcWcXcYcZc0c1c2c3c4cOgPgQgRgSgTgUgVg5c6c7c8c9c!c#c$cWgXgYgZg0g1g2g3g4g5g6g7g8g9g!g#g$g%g'g(g)g*g+g,g-g.g/g%c'c:g;g(c)c*c+c,c-c.c/c:c;c=c?c@c[c]c^c_c`c{c|c}c~cadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzdAdBdCd=g?g@g[g]g^g_g`g{g|g}g~gahbhchdhehfhDdEdFdGdHdIdghhhihjhkhlhJdKdLdMdmhnhohphNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$d%dqhrhshthuhvhwhxh'd(d)d*d+d,d-d.dyhzhAhBhChDhEhFhGhHhIhJhKhLhMhNhOhPhQhRhShThUhVhWhXhYh/d:dZh0h;d=d?d@d[d]d^d_d`d{d|d}d~daebecedeeefegeheiejekelemeneoepeqereseteuevewexeyezeAeBeCeDeEeFeGeHeIeJeKeLe1h2h3h4h5h6h7h8h9h!h#h$h%h'h(h)h*h+hMeNeOePeQeRe,h-h.h/h:h;hSeTeUeVe=h?h@h[hWeXeYeZe0e1e2e3e4e5e6e7e8e9e!e#e$e%e'e(e)e*e+e,e-e.e/e]h^h_h`h{h|h}h~h:e;e=e?e@e[e]e^eaibicidieifigihiiijikiliminioipiqirisitiuivi

67 statement, 

68 params=params, 

69 execution_options=execution_options, 

70 bind_arguments=bind_arguments, 

71 _parent_execute_state=_parent_execute_state, 

72 _add_event=_add_event, 

73 ) 

74 if isinstance(statement, SelectOfScalar): 2_e`eg {e|eh i j k l m n o p q r s t u v w x y z A B }e~eafbfcfdfefffgfC D hfifjfE F kflfG H I J K L M N O mfnfofpfP Q R S qfrfsftfufvfwfxfyfzfAfBfCfT DfEfU V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' FfGfHfIfJfKfLfMfNf( ) OfPfQf* + RfSf, - . / : ; = ? @ TfUfVfWf[ ] ^ _ XfYfZf0f1f2f3f4f5f6f7f8f9f!f` #f$f{ | } ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqbrbsbtbubvbwbxbybzbAbBb%f'f(f)f*f+f,f-f.fCbDbEbFb/f:f;fGbHb=f?fIbJbKbLbMbNbObPbQbRbSbTbUbVbWbXbYbZb@f[f]f^f0b1b2b3b_f`f{f|f}f~fagbgcgdgegfggghgigjg4b5bkglg6b7b8b9b!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~bacbcccdcecfcgchcicjckclcmcncocpcqcrcsctcmgngogpgqgrgsgtgugvgwgxgygzgAgBgCgDgucvcwcxcyczcEgFgGgHgIgJgAcBcCcDcKgLgMgNgEcFcGcHcIcJcKcLcMcNcOcPcQcRcScTcUcVcWcXcYcZc0c1c2c3c4cOgPgQgRgSgTgUgVg5c6c7c8c9c!c#c$cWgXgYgZg0g1g2g3g4g5g6g7g8g9g!g#g$g%g'g(g)g*g+g,g-g.g/g%c'c:g;g(c)c*c+c,c-c.c/c:c;c=c?c@c[c]c^c_c`c{c|c}c~cadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzdAdBdCd=g?g@g[g]g^g_g`g{g|g}g~gahbhchdhehfhDdEdFdGdHdIdghhhihjhkhlhJdKdLdMdmhnhohphNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$d%dqhrhshthuhvhwhxh'd(d)d*d+d,d-d.dyhzhAhBhChDhEhFhGhHhIhJhKhLhMhNhOhPhQhRhShThUhVhWhXhYh/d:dZh0h;d=d?d@d[d]d^d_d`d{d|d}d~daebecedeeefegeheiejekelemeneoepeqereseteuevewexeyezeAeBeCeDeEeFeGeHeIeJeKeLe1h2h3h4h5h6h7h8h9h!h#h$h%h'h(h)h*h+hMeNeOePeQeRe,h-h.h/h:h;hSeTeUeVe=h?h@h[hWeXeYeZe0e1e2e3e4e5e6e7e8e9e!e#e$e%e'e(e)e*e+e,e-e.e/e]h^h_h`h{h|h}h~h:e;e=e?e@e[e]e^eaibicidieifigihiiijikiliminioipiqirisitiuivi

75 return results.scalars() 2_e`eg {e|eh i m o p q r s t u v w x y z A B }e~eafbfcfdfefffgfC D hfifjfE F kflfG H I J K L M N O mfnfofpfP Q R S qfrfsftfufvfwfxfyfzfAfBfCfT DfEfU V Z 1 2 3 4 5 6 7 8 9 ! # $ % ' FfGfHfIfJfKfLfMfNf( ) OfPfQf* + RfSf, - . / : ; = ? @ TfUfVfWf[ ] ^ _ XfYfZf0f1f2f3f4f5f6f7f8f9f!f` #f$f{ | bbdbebfbgbhbibjbkblbmbnbobpbqbrbsbtbubvbwbxbybzbAbBb%f'f(f)f*f+f,f-f.fCbDbEbFb/f:f;fGbHb=f?fIbJbKbLbMbNbObPbQbRbSbTbUbVbWbXbYbZb@f[f]f^f0b1b2b3b_f`f{f|f}f~fagbgcgdgegfggghgigjg4b5bkglg6b7b'b(b+b,b-b.b/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcccdcecfcgchcicjckclcmcncocpcqcrcsctcmgngogpgqgrgsgtgugvgwgxgygzgAgBgCgDgucvcwcxcyczcEgFgGgHgIgJgAcBcCcDcKgLgMgNgEcFcGcHcIcJcKcLcMcNcOcPcQcRcScTcUcVcWcXcYcZc0c1c2c3c4cOgPgQgRgSgTgUgVg5c6c7c8c9c!c#c$cWgXgYgZg0g1g2g3g4g5g6g7g8g9g!g#g$g%g'g(g)g*g+g,g-g.g/g%c'c:g;g(c)c:c;c@c[c]c^c_c`c{c|c}c~cadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzdAdBdCd=g?g@g[g]g^g_g`g{g|g}g~gahbhchdhehfhDdEdFdGdHdIdghhhihjhkhlhJdKdLdMdmhnhohphNdOdPdQdRdSdTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$d%dqhrhshthuhvhwhxh'd(d)d*d+d,d-d.dyhzhAhBhChDhEhFhGhHhIhJhKhLhMhNhOhPhQhRhShThUhVhWhXhYh/d:dZh0h;d=d`d{d~daebecedeeefegeheiejekelemeneoepeqereseteuevewexeyezeAeBeCeDeEeFeGeHeIeJeKeLe1h2h3h4h5h6h7h8h9h!h#h$h%h'h(h)h*h+hMeNeOePeQeRe,h-h.h/h:h;hSeTeUeVe=h?h@h[hWeXeYeZe0e1e2e3e4e5e6e7e8e9e!e#e$e%e'e(e)e*e+e,e-e.e/e]h^h_h`h{h|h}h~h:e;e=e?e@e[e]e^eaibicidieifigihiiijikiliminioipiqirisitiuivi

76 return results # type: ignore 2j k l n E F W X Y 0 * + } ~ abcbGbHb8b9b!b#b$b%b)b*bAcBcCcDc*c+c,c-c.c/c=c?cJdKdLdMd?d@d[d]d^d_d|d}dSeTeUeVe

77 

78 @deprecated( 1fabcde

79 """ 

80 🚨 You probably want to use `session.exec()` instead of `session.execute()`. 

81 

82 This is the original SQLAlchemy `session.execute()` method that returns objects 

83 of type `Row`, and that you have to call `scalars()` to get the model objects. 

84 

85 For example: 

86 

87 ```Python 

88 heroes = session.execute(select(Hero)).scalars().all() 

89 ``` 

90 

91 instead you could use `exec()`: 

92 

93 ```Python 

94 heroes = session.exec(select(Hero)).all() 

95 ``` 

96 """, 

97 category=None, 

98 ) 

99 def execute( # type: ignore 1abcde

100 self, 

101 statement: _Executable, 

102 params: Optional[_CoreAnyExecuteParams] = None, 

103 *, 

104 execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT, 

105 bind_arguments: Optional[Dict[str, Any]] = None, 

106 _parent_execute_state: Optional[Any] = None, 

107 _add_event: Optional[Any] = None, 

108 ) -> Result[Any]: 

109 """ 

110 🚨 You probably want to use `session.exec()` instead of `session.execute()`. 

111 

112 This is the original SQLAlchemy `session.execute()` method that returns objects 

113 of type `Row`, and that you have to call `scalars()` to get the model objects. 

114 

115 For example: 

116 

117 ```Python 

118 heroes = session.execute(select(Hero)).scalars().all() 

119 ``` 

120 

121 instead you could use `exec()`: 

122 

123 ```Python 

124 heroes = session.exec(select(Hero)).all() 

125 ``` 

126 """ 

127 return super().execute( 2CiDiEiFiGiHiIiJiKiLiMiNiOig PiQih i RiwiSiTiUiViWiXij k l m n Yio p Zi0i1i2i3i4iq r s t u v w x y z A B 5iC D 6i7iG H 8i9iI J K L M N O P Q R S !i#i$i%i'i(i)i*i+i,i-i.i/iT :i;iU V =ixi?i@i[i]i^i_iW X Y Z 0 `i1 2 {i|i}i~iajbj3 4 5 6 7 8 9 ! # $ % ' cj( ) djej, - fjgj. / : ; = ? @ [ ] ^ _ hjijjjkjljmjnjojpjqjrjsjtjujvjwjxjyjzjAjBjCjDjEjFjGj` HjIj{ | JjyiKjLjMjNjOjPjQjRj} ~ abbbcbSjdbebTjUjVjWjXjYjfbgbhbibjbkblbmbnbobpbqbrbsbtbubvbwbxbybzbAbBbZj0jCbDbEbFb1j2jIbJbKbLb3j4j5j6jMbNbObPbQbRbSbTbUbVbWbXbYbZb0b1b2b3b7j8j9j!j#j$j%j'j(j)j*j+j,j-j.j/j:j;j=j?j@j[j]j^j_j`j{j|j}j~jakbkckdkekfkgkhkik4b5bjkkklk6b7bmkzinkokpkqkrksktkukvkwkxkykzkAk8b9b!b#b$b%b'b(b)b*bBkCk+b,b-b.bDkEkFkGkHkIk/b:b;b=b?b@b[b]b^b_b`b{b|b}b~bacbcccdcecfcgchcicjckclcmcncocpcqcrcsctcJkKkLkucvcwcxcyczcMkNkOkPkEcFcGcHcIcJcQkRkSkTkUkVkKcLcMcNcOcPcQcRcScTcUcVcWcXcYcZc0c1c2c3c4c5c6c7c8c9c!c#c$cWkXkYkZk0k1k2k3k4k5k6k7k8k9k!k#k$k%k'k(k)k*k+k,k-k.k/k:k;k=k?k@k[k]k^k_k`k{k|k%c'c}k~kal(c)cblAicldlelflglhliljlklllmlnlolpl*c+c,c-c.c/c:c;c=c?cqlrl@c[c]c^csltlulvlwlxl_c`c{c|c}c~cadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzdAdBdCdylzlAlDdEdFdGdHdIdBlClDlElNdOdPdQdRdSdFlGlHlIlJlKlTdUdVdWdXdYdZd0d1d2d3d4d5d6d7d8d9d!d#d$d%d'd(d)d*d+d,d-d.dLlMlNlOlPlQlRlSlTlUlVlWlXlYlZl0l1l2l3l4l5l6l7l8l9l!l#l$l%l'l(l)l*l+l,l-l.l/l:l/d:d;l=l?l;d=d@lBi[l]l^l_l`l{l|l}l~lambmcmdmem?d@d[d]d^d_d`d{d|d}dfmgm~daebecehmimjmkmlmmmdeeefegeheiejekelemeneoepeqereseteuevewexeyezeAeBeCeDeEeFeGeHeIeJeKeLenmompmMeNeOePeQeReqmrmsmtmWeXeYeZe0e1eumvmwmxmymzm2e3e4e5e6e7e8e9e!e#e$e%e'e(e)e*e+e,e-e.e/e:e;e=e?e@e[e]e^e

128 statement, 

129 params=params, 

130 execution_options=execution_options, 

131 bind_arguments=bind_arguments, 

132 _parent_execute_state=_parent_execute_state, 

133 _add_event=_add_event, 

134 ) 

135 

136 @deprecated( 1fabcde

137 """ 

138 🚨 You probably want to use `session.exec()` instead of `session.query()`. 

139 

140 `session.exec()` is SQLModel's own short version with increased type 

141 annotations. 

142 

143 Or otherwise you might want to use `session.execute()` instead of 

144 `session.query()`. 

145 """ 

146 ) 

147 def query( # type: ignore 1abcde

148 self, *entities: _ColumnsClauseArgument[Any], **kwargs: Any 

149 ) -> _Query[Any]: 

150 """ 

151 🚨 You probably want to use `session.exec()` instead of `session.query()`. 

152 

153 `session.exec()` is SQLModel's own short version with increased type 

154 annotations. 

155 

156 Or otherwise you might want to use `session.execute()` instead of 

157 `session.query()`. 

158 """ 

159 return super().query(*entities, **kwargs) 2wixiyiziAiBi