Skip to content

Commit eebfcc4

Browse files
Improvements to merge_db()
1 parent 3b62cdc commit eebfcc4

File tree

4 files changed

+363
-115
lines changed

4 files changed

+363
-115
lines changed

cardinal_pythonlib/sqlalchemy/core_query.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,31 @@
2424
2525
**Query helper functions using the SQLAlchemy Core.**
2626
27+
Example of result types in SQLAlchemy 1.4+ and higher:
28+
29+
.. code-block:: python
30+
31+
from typing import List
32+
from sqlalchemy.engine.cursor import CursorResult
33+
from sqlalchemy.engine.result import MappingResult, Result
34+
from sqlalchemy.engine.row import Row, RowMapping
35+
36+
query = (
37+
select(text("*"))
38+
.select_from(table(some_tablename))
39+
)
40+
41+
# As tuples:
42+
result_1: CursorResult = session.execute(query)
43+
# ... or, more generically, of type Result
44+
like_unnamed_tuples: List[Row] = result_1.fetchall()
45+
46+
# Or:
47+
result_2: Result = session.execute(query)
48+
mapping_result: Mapping_Result = result_2.mappings()
49+
like_dicts: List[RowMapping] = list(mapping_result) # implicit fetchall()
50+
# ... or could have done: like_dicts = result_2.mappings().fetchall()
51+
2752
"""
2853

2954
from typing import Any, List, Optional, Tuple, Union

0 commit comments

Comments
 (0)