Skip to content

Commit ae573fb

Browse files
Update lab2.md
1 parent b0dd6de commit ae573fb

File tree

1 file changed

+17
-1
lines changed
  • Advanced databases 2022/Lab 2 (Introduction to SqlAlchemy)

1 file changed

+17
-1
lines changed

Advanced databases 2022/Lab 2 (Introduction to SqlAlchemy)/lab2.md

+17-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ In this sript *table_name* is the string with table name in database.
7777

7878
## SQLAlchemy query
7979

80-
The basic select in SQLAlchemy has form:
80+
The basic select in SQLAlchemy <2.0 has form :
8181

8282
```python
8383
stmt = 'select * from table'
@@ -88,6 +88,22 @@ results = db.execute(stmt).fetchall()
8888
# Print results
8989
print(results)
9090
```
91+
and in SQLAlchemy >2.0 has form:
92+
93+
```python
94+
from sqlalchemy.sql import text
95+
96+
stmt = 'select * from table'
97+
98+
con = db.connect()
99+
100+
# Execute the statement and fetch the results
101+
results = con.execute(text('select * from actor'))
102+
# Print results
103+
print(results)
104+
```
105+
106+
91107
Function *execute* make a request to a database and *fetchall* method get our results from an executed query. But in this case we don't use ORM propertis. More correctly is use structur:
92108

93109
```python

0 commit comments

Comments
 (0)