Coverage for sqlmodel / orm / session.py: 100%
28 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-06-10 09:40 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2026-06-10 09:40 +0000
1from collections.abc import Mapping, Sequence 1abfcgdeh
2from typing import ( 1abfcgdeh
3 Any,
4 TypeVar,
5 overload,
6)
8from sqlalchemy import util 1abfcgdeh
9from sqlalchemy.engine.cursor import CursorResult 1abfcgdeh
10from sqlalchemy.engine.interfaces import _CoreAnyExecuteParams 1abfcgdeh
11from sqlalchemy.engine.result import Result, ScalarResult, TupleResult 1abfcgdeh
12from sqlalchemy.orm import Query as _Query 1abfcgdeh
13from sqlalchemy.orm import Session as _Session 1abfcgdeh
14from sqlalchemy.orm._typing import OrmExecuteOptionsParameter 1abfcgdeh
15from sqlalchemy.sql._typing import _ColumnsClauseArgument 1abfcgdeh
16from sqlalchemy.sql.base import Executable as _Executable 1abfcgdeh
17from sqlalchemy.sql.dml import UpdateBase 1abfcgdeh
18from sqlmodel.sql.base import Executable 1abfcgdeh
19from sqlmodel.sql.expression import Select, SelectOfScalar 1abfcgdeh
20from typing_extensions import deprecated 1abfcgdeh
22_TSelectParam = TypeVar("_TSelectParam", bound=Any) 1abfcgdeh
25class Session(_Session): 1abfcgdeh
26 @overload 1abfcgdeh
27 def exec( 1abfcgdeh
28 self,
29 statement: Select[_TSelectParam], 1abcde
30 *,
31 params: Mapping[str, Any] | Sequence[Mapping[str, Any]] | None = None, 1abfcgdeh
32 execution_options: Mapping[str, Any] = util.EMPTY_DICT, 1abfcgdeh
33 bind_arguments: dict[str, Any] | None = None, 1abfcgdeh
34 _parent_execute_state: Any | None = None, 1abfcgdeh
35 _add_event: Any | None = None, 1abfcgdeh
36 ) -> TupleResult[_TSelectParam]: ... 1abcde
38 @overload 1abfcgdeh
39 def exec( 1abfcgdeh
40 self,
41 statement: SelectOfScalar[_TSelectParam], 1abcde
42 *,
43 params: Mapping[str, Any] | Sequence[Mapping[str, Any]] | None = None, 1abfcgdeh
44 execution_options: Mapping[str, Any] = util.EMPTY_DICT, 1abfcgdeh
45 bind_arguments: dict[str, Any] | None = None, 1abfcgdeh
46 _parent_execute_state: Any | None = None, 1abfcgdeh
47 _add_event: Any | None = None, 1abfcgdeh
48 ) -> ScalarResult[_TSelectParam]: ... 1abcde
50 @overload 1abfcgdeh
51 def exec( 1abfcgdeh
52 self,
53 statement: UpdateBase, 1abcde
54 *,
55 params: Mapping[str, Any] | Sequence[Mapping[str, Any]] | None = None, 1abfcgdeh
56 execution_options: Mapping[str, Any] = util.EMPTY_DICT, 1abfcgdeh
57 bind_arguments: dict[str, Any] | None = None, 1abfcgdeh
58 _parent_execute_state: Any | None = None, 1abfcgdeh
59 _add_event: Any | None = None, 1abfcgdeh
60 ) -> CursorResult[Any]: ... 1abcde
62 def exec( 1abfcgdeh
63 self,
64 statement: Select[_TSelectParam]
65 | SelectOfScalar[_TSelectParam]
66 | Executable[_TSelectParam]
67 | UpdateBase,
68 *,
69 params: Mapping[str, Any] | Sequence[Mapping[str, Any]] | None = None,
70 execution_options: Mapping[str, Any] = util.EMPTY_DICT,
71 bind_arguments: dict[str, Any] | None = None,
72 _parent_execute_state: Any | None = None,
73 _add_event: Any | None = None,
74 ) -> TupleResult[_TSelectParam] | ScalarResult[_TSelectParam] | CursorResult[Any]:
75 results = super().execute( 29d!di #dj $dk l %d'dm n o p q r s t u v w x y z A B C D E (d)d*d+d,d-d.d/d:dF G ;d=d?dH I @d[dJ K L M N O P Q R ]d^d_d`dS T U V {d|d}d~daebecedeeefegeheieW jeX keY Z leme0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + neoepeqereseteueve, - wexeye. / zeAe: ; = ? @ [ ] ^ _ BeCeDeEe` { | } FeGeHeIeJeKeLeMeNeOePeQeRe~ SeabTebbcbUeVedbebfbgbhbibjbkblbmbnbobpbqbrbsbtbubvbWeXeYeZe0e1e2e3e4ewbxb5e6e7eybzb8e9eAbBbCbDbEbFbGbHbIb!e#e$e%eJbKbLbMb'e(e)e*e+e,e-e.e/e:e;e=e?eNb@eOb[ePbQb]e^eRbSbTbUbVbWbXbYbZb0b1b2b3b4b5b6b7b8b9b_e`e{e|e}e~eafbfcf!b#bdfefff$b%bgfhf'b(b)b*b+b,b-b.b/bifjfkflf:b;b=b?bmfnfofpfqfrfsftfufvfwfxfyf@bzf[bAf]b^bBfCf_b`b{b|b}b~bacbcccdcecfcgchcicjckclcmcDfEfFfGfHfIfJfKfLfncocMfNfOfpcqcPfQfrcsctcucvcwcxcyczcRfSfTfUfAcBcCcDcVfWfXfYfZf0f1f2f3f4f5f6f7fEc8fFc9fGcHc!f#fIcJcKcLcMcNcOcPcQcRcScTcUcVcWcXcYcZc0c$f%f'f(f)f*f+f,f-f1c2c.f/f:f3c4c;f=f5c6c7c8c9c!c#c$c%c?f@f[f]f'c(c)c*c^f_f`f{f|f}f~fagbgcgdgegfg+cgg,chg-c.cigjg/c:c;c=c?c@c[c]c^c_c`c{c|c}c~cadbdcdddkglgmgngogpgqgrgsgedfdtgugvggdhdwgxgidjdkdldmdndodpdqdygzgAgBgrdsdtdudCgDgEgFgGgHgIgJgKgLgMgNgOgvdPgwdQgxdydRgSgzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdTgUgVgWgXgYgZg0g1gSdTd2g3g4gUdVd5g6gWdXdYdZd0d1d2d3d4d7g8g9g!g5d6d7d8d#g$g%g'g(g)g*g+g,g-g.g
76 statement,
77 params=params,
78 execution_options=execution_options,
79 bind_arguments=bind_arguments,
80 _parent_execute_state=_parent_execute_state,
81 _add_event=_add_event,
82 )
83 if isinstance(statement, SelectOfScalar): 29d!di #dj $dk l %d'dm n o p q r s t u v w x y z A B C D E (d)d*d+d,d-d.d/d:dF G ;d=d?dH I @d[dJ K L M N O P Q R ]d^d_d`dS T U V {d|d}d~daebecedeeefegeheieW jeX keY Z leme0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + neoepeqereseteueve, - wexeye. / zeAe: ; = ? @ [ ] ^ _ BeCeDeEe` { | } FeGeHeIeJeKeLeMeNeOePeQeRe~ SeabTebbcbUeVedbebfbgbhbibjbkblbmbnbobpbqbrbsbtbubvbWeXeYeZe0e1e2e3e4ewbxb5e6e7eybzb8e9eAbBbCbDbEbFbGbHbIb!e#e$e%eJbKbLbMb'e(e)e*e+e,e-e.e/e:e;e=e?eNb@eOb[ePbQb]e^eRbSbTbUbVbWbXbYbZb0b1b2b3b4b5b6b7b8b9b_e`e{e|e}e~eafbfcf!b#bdfefff$b%bgfhf'b(b)b*b+b,b-b.b/bifjfkflf:b;b=b?bmfnfofpfqfrfsftfufvfwfxfyf@bzf[bAf]b^bBfCf_b`b{b|b}b~bacbcccdcecfcgchcicjckclcmcDfEfFfGfHfIfJfKfLfncocMfNfOfpcqcPfQfrcsctcucvcwcxcyczcRfSfTfUfAcBcCcDcVfWfXfYfZf0f1f2f3f4f5f6f7fEc8fFc9fGcHc!f#fIcJcKcLcMcNcOcPcQcRcScTcUcVcWcXcYcZc0c$f%f'f(f)f*f+f,f-f1c2c.f/f:f3c4c;f=f5c6c7c8c9c!c#c$c%c?f@f[f]f'c(c)c*c^f_f`f{f|f}f~fagbgcgdgegfg+cgg,chg-c.cigjg/c:c;c=c?c@c[c]c^c_c`c{c|c}c~cadbdcdddkglgmgngogpgqgrgsgedfdtgugvggdhdwgxgidjdkdldmdndodpdqdygzgAgBgrdsdtdudCgDgEgFgGgHgIgJgKgLgMgNgOgvdPgwdQgxdydRgSgzdAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdTgUgVgWgXgYgZg0g1gSdTd2g3g4gUdVd5g6gWdXdYdZd0d1d2d3d4d7g8g9g!g5d6d7d8d#g$g%g'g(g)g*g+g,g-g.g
84 return results.scalars() 29d!di #dj $dk l 'dp r s t u v w x y z A B C D E (d)d*d+d,d-d.d/d:dF G ;d=d?dH I @d[dJ K L M N O P Q R ]d^d_d`dS T U V {d|d}d~daebecedeeefegeheieW jeX keY Z me3 5 6 7 8 9 ! # $ % ' ( ) * + neoepeqereseteueve, - wexeye. / zeAe: ; = ? @ [ ] ^ _ BeCeDeEe` { | } FeGeHeIeJeKeLeMeNeOePeQeRe~ SeabTebbcbVegbibjbkblbmbnbobpbqbrbsbtbubvbWeXeYeZe0e1e2e3e4ewbxb5e6e7eybzb8e9eAbBbCbDbEbFbGbHbIb!e#e$e%eJbKbLbMb'e(e)e*e+e,e-e.e/e:e;e=e?eNb@eOb[ePbQb^eUbWbXbYbZb0b1b2b3b4b5b6b7b8b9b_e`e{e|e}e~eafbfcf!b#bdfefff$b%bgfhf'b(b)b*b+b,b-b.b/bifjfkflf:b;b=b?bmfnfofpfqfrfsftfufvfwfxfyf@bzf[bAf]b^bCf|b~bacbcccdcecfcgchcicjckclcmcDfEfFfGfHfIfJfKfLfncocMfNfOfpcqcPfQfrcsctcucvcwcxcyczcRfSfTfUfAcBcCcDcVfWfXfYfZf0f1f2f3f4f5f6f7fEc8fFc9fGcHc#fLcNcOcPcQcRcScTcUcVcWcXcYcZc0c$f%f'f(f)f*f+f,f-f1c2c.f/f:f3c4c;f=f5c6c7c8c9c!c#c$c%c?f@f[f]f'c(c)c*c^f_f`f{f|f}f~fagbgcgdgegfg+cgg,chg-c.cjg=c@c[c]c^c_c`c{c|c}c~cadbdcdddkglgmgngogpgqgrgsgedfdtgugvggdhdwgxgidjdkdldmdndodpdqdygzgAgBgrdsdtdudCgDgEgFgGgHgIgJgKgLgMgNgOgvdPgwdQgxdydSgCdEdFdGdHdIdJdKdLdMdNdOdPdQdRdTgUgVgWgXgYgZg0g1gSdTd2g3g4gUdVd5g6gWdXdYdZd0d1d2d3d4d7g8g9g!g5d6d7d8d#g$g%g'g(g)g*g+g,g-g.g
85 return results # type: ignore 2%dm n o q H I le0 1 2 4 . / Uedbebfbhbybzb]eRbSbTbVb$b%bBf_b`b{b}bpcqc!fIcJcKcMc3c4cig/c:c;c?cgdhdRgzdAdBdDdUdVd
87 @deprecated( 1abfcgdeh
88 """
89 🚨 You probably want to use `session.exec()` instead of `session.execute()`.
91 This is the original SQLAlchemy `session.execute()` method that returns objects
92 of type `Row`, and that you have to call `scalars()` to get the model objects.
94 For example:
96 ```Python
97 heroes = session.execute(select(Hero)).scalars().all()
98 ```
100 instead you could use `exec()`:
102 ```Python
103 heroes = session.exec(select(Hero)).all()
104 ```
105 """,
106 category=None,
107 )
108 def execute( 1abfcgdeh
109 self,
110 statement: _Executable,
111 params: _CoreAnyExecuteParams | None = None,
112 *,
113 execution_options: OrmExecuteOptionsParameter = util.EMPTY_DICT,
114 bind_arguments: dict[str, Any] | None = None,
115 _parent_execute_state: Any | None = None,
116 _add_event: Any | None = None,
117 ) -> Result[Any]:
118 """
119 🚨 You probably want to use `session.exec()` instead of `session.execute()`.
121 This is the original SQLAlchemy `session.execute()` method that returns objects
122 of type `Row`, and that you have to call `scalars()` to get the model objects.
124 For example:
126 ```Python
127 heroes = session.execute(select(Hero)).scalars().all()
128 ```
130 instead you could use `exec()`:
132 ```Python
133 heroes = session.exec(select(Hero)).all()
134 ```
135 """
136 return super().execute( 2^g_g`g{g|g}g~gahbhchdhehfhi ghj hhihk l jh/gkhlhmhnhohm n o p q phr s qhrhshthuhvht u v w x y z A B C D E whF G xhyhJ K zhAhL M N O P Q R S T U V BhChDhEhFhGhHhIhJhKhLhMhNhW OhX PhQhY Z Rh:gShThUhVhWh0 1 2 3 4 Xh5 6 YhZh0h1h2h3h7 8 9 ! # $ % ' ( ) * + 4h, - 5h6h: ; 7h8h= ? @ [ ] ^ _ ` { | } 9h!h#h$h%h'h(h)h*h+h,h-h.h~ /hab:h;hbbcb=h;g?h@h[h]h^hdbebfbgbhb_hibjb`h{h|h}h~haikblbmbnbobpbqbrbsbtbubvbbiwbxbcidiAbBbeifiCbDbEbFbGbHbIbJbKbLbMbgihiiijikiliminioipiqirisiNbtiObuiviPbQbwi=gxiyiziAiBiRbSbTbUbVbCiWbXbDiEiFiGiHiIiYbZb0b1b2b3b4b5b6b7b8b9bJi!b#bKiLi'b(bMiNi)b*b+b,b-b.b/b:b;b=b?bOiPiQiRiSiTiUiViWiXiYiZi0i@b1i[b2i3i]b^b4i?g5i6i7i8i9i_b`b{b|b}b!i~bac#i$i%i'i(i)ibcccdcecfcgchcicjckclcmc*incoc+i,ircsc-i.itcucvcwcxcyczcAcBcCcDc/i:i;i=i?i@i[i]i^i_i`i{i|iEc}iFc~iajGcHcbj@gcjdjejfjgjIcJcKcLcMchjNcOcijjjkjljmjnjPcQcRcScTcUcVcWcXcYcZc0coj1c2cpjqj5c6crjsj7c8c9c!c#c$c%c'c(c)c*ctjujvjwjxjyjzjAjBjCjDjEjFj+cGj,cHjIj-c.cJj[gKjLjMjNjOj/c:c;c=c?cPj@c[cQjRjSjTjUjVj]c^c_c`c{c|c}c~cadbdcdddWjedfdXjYjidjdZj0jkdldmdndodpdqdrdsdtdud1j2j3j4j5j6j7j8j9j!j#j$j%jvd'jwd(j)jxdyd*j]g+j,j-j.j/jzdAdBdCdDd:jEdFd;j=j?j@j[j]jGdHdIdJdKdLdMdNdOdPdQdRd^jSdTd_j`jWdXd{j|jYdZd0d1d2d3d4d5d6d7d8d
137 statement,
138 params=params,
139 execution_options=execution_options,
140 bind_arguments=bind_arguments,
141 _parent_execute_state=_parent_execute_state,
142 _add_event=_add_event,
143 )
145 @deprecated( 1abfcgdeh
146 """
147 🚨 You probably want to use `session.exec()` instead of `session.query()`.
149 `session.exec()` is SQLModel's own short version with increased type
150 annotations.
152 Or otherwise you might want to use `session.execute()` instead of
153 `session.query()`.
154 """
155 )
156 def query( # type: ignore 1abfcgdeh
157 self, *entities: _ColumnsClauseArgument[Any], **kwargs: Any
158 ) -> _Query[Any]:
159 """
160 🚨 You probably want to use `session.exec()` instead of `session.query()`.
162 `session.exec()` is SQLModel's own short version with increased type
163 annotations.
165 Or otherwise you might want to use `session.execute()` instead of
166 `session.query()`.
167 """
168 return super().query(*entities, **kwargs) 2/g:g;g=g?g@g[g]g