aio-libs / aio-libs/aiomysql

sqlalchemy example doesn't save rows

Đang mở
#247 3 bình luận 1 reaction 0 người được giao Xem trên GitHub
docs sqlalchemy
Ngôn ngữ chính
Python
Star
1.9k
Fork
272
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

I was following https://github.com/aio-libs/aiomysql/blob/master/docs/sa.rst and I noticed that running the example multiple times did not work as expected.

The example:
```
import asyncio
import sqlalchemy as sa

from aiomysql.sa import create_engine

metadata = sa.MetaData()

tbl = sa.Table('tbl', metadata,
sa.Column('id', sa.Integer, primary_key=True),
sa.Column('val', sa.String(255)))

@asyncio.coroutine
def go():
engine = yield from create_engine(user='root',
db='dabbot',
host='db',
password='dabbot')

with (yield from engine) as conn:
yield from conn.execute(tbl.insert().values(val='abc'))

res = yield from conn.execute(tbl.select())
for row in res:
print(row.id, row.val)

asyncio.get_event_loop().run_until_complete(go())

```

```
bash-4.4$ python /app/simple.py
1 abc
bash-4.4$ python /app/simple.py
2 abc
bash-4.4$ python /app/simple.py
3 abc
bash-4.4$ python /app/simple.py
4 abc
bash-4.4$ python /app/simple.py
5 abc
```

Then I opened up adminer and added `6 def`

```
bash-4.4$ python /app/simple.py
6 def
7 abc
bash-4.4$ python /app/simple.py
6 def
8 abc
```

I think the example is missing `conn.execute('commit')`.

The example at https://github.com/aio-libs/aiomysql/blob/master/examples/example_simple_sa.py has the same issue. I removed the "drop" statement and it doesn't persist rows like I expect.
```
bash-4.4$ python /app/simple.py
1 abc
2 xyz
bash-4.4$ python /app/simple.py
3 abc
4 xyz
bash-4.4$ python /app/simple.py
5 abc
6 xyz
```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.