1212
1313from sqlalchemy import util
1414from sqlalchemy .orm import Mapper as _Mapper
15- from sqlalchemy .orm import Query as _Query
1615from sqlalchemy .orm import Session as _Session
17- from sqlalchemy .sql .base import Executable as _Executable
1816from sqlalchemy .sql .selectable import ForUpdateArg as _ForUpdateArg
1917from sqlmodel .sql .expression import Select , SelectOfScalar
2018
@@ -81,56 +79,6 @@ def exec(
8179 return results .scalars () # type: ignore
8280 return results # type: ignore
8381
84- def execute (
85- self ,
86- statement : _Executable ,
87- params : Optional [Union [Mapping [str , Any ], Sequence [Mapping [str , Any ]]]] = None ,
88- execution_options : Mapping [str , Any ] = util .EMPTY_DICT ,
89- bind_arguments : Optional [Dict [str , Any ]] = None ,
90- _parent_execute_state : Optional [Any ] = None ,
91- _add_event : Optional [Any ] = None ,
92- ** kw : Any ,
93- ) -> Result [Any ]:
94- """
95- 🚨 You probably want to use `session.exec()` instead of `session.execute()`.
96-
97- This is the original SQLAlchemy `session.execute()` method that returns objects
98- of type `Row`, and that you have to call `scalars()` to get the model objects.
99-
100- For example:
101-
102- ```Python
103- heroes = session.execute(select(Hero)).scalars().all()
104- ```
105-
106- instead you could use `exec()`:
107-
108- ```Python
109- heroes = session.exec(select(Hero)).all()
110- ```
111- """
112- return super ().execute ( # type: ignore
113- statement ,
114- params = params ,
115- execution_options = execution_options ,
116- bind_arguments = bind_arguments ,
117- _parent_execute_state = _parent_execute_state ,
118- _add_event = _add_event ,
119- ** kw ,
120- )
121-
122- def query (self , * entities : Any , ** kwargs : Any ) -> "_Query[Any]" :
123- """
124- 🚨 You probably want to use `session.exec()` instead of `session.query()`.
125-
126- `session.exec()` is SQLModel's own short version with increased type
127- annotations.
128-
129- Or otherwise you might want to use `session.execute()` instead of
130- `session.query()`.
131- """
132- return super ().query (* entities , ** kwargs ) # type: ignore
133-
13482 def get (
13583 self ,
13684 entity : Union [Type [_TSelectParam ], "_Mapper[_TSelectParam]" ],
@@ -152,3 +100,34 @@ def get(
152100 execution_options = execution_options ,
153101 bind_arguments = bind_arguments ,
154102 )
103+
104+
105+ Session .query .__doc__ = """
106+ 🚨 You probably want to use `session.exec()` instead of `session.query()`.
107+
108+ `session.exec()` is SQLModel's own short version with increased type
109+ annotations.
110+
111+ Or otherwise you might want to use `session.execute()` instead of
112+ `session.query()`.
113+ """
114+
115+
116+ Session .execute .__doc__ = """
117+ 🚨 You probably want to use `session.exec()` instead of `session.execute()`.
118+
119+ This is the original SQLAlchemy `session.execute()` method that returns objects
120+ of type `Row`, and that you have to call `scalars()` to get the model objects.
121+
122+ For example:
123+
124+ ```Python
125+ heroes = session.execute(select(Hero)).scalars().all()
126+ ```
127+
128+ instead you could use `exec()`:
129+
130+ ```Python
131+ heroes = session.exec(select(Hero)).all()
132+ ```
133+ """
0 commit comments