kszucs / aiopeewee

Asyncio interface for Peewee ORM
MIT License
46 stars 6 forks source link

WIP: Adding SQLIte support. #8

Open vlad0337187 opened 6 years ago

vlad0337187 commented 6 years ago

Added sqlite.py. But I receive error sqlite3.ProgrammingError: Cannot operate on a closed database.

It's because other files wait, that returned from 'db' instance by 'get_conn' connection will be usable after exiting 'with' block. But for SQLite it's not so. So I need or to create global per\database connection (with large code changes, or to do something other.

vlad0337187 commented 6 years ago

A little bit help needed =)

I receive such error and cannot figure out why )

Traceback (most recent call last): File "/home/vlad/my_projects/web/times_new_novel_asyncio/venv/lib/python3.6/site-packages/aiosqlite/core.py", line 143, in run result = fn() sqlite3.ProgrammingError: Cannot operate on a closed database. Traceback (most recent call last): File "/home/vlad/my_projects/web/times_new_novel_asyncio/test_database.py", line 46, in ioloop.run_until_complete(mainy()) File "/usr/lib/python3.6/asyncio/base_events.py", line 467, in run_until_complete return future.result() File "/home/vlad/my_projects/web/times_new_novel_asyncio/test_database.py", line 38, in mainy async for user in User.select(): File "/home/vlad/my_projects/web/times_new_novel_asyncio/packages/aiopeewee/result.py", line 21, in anext obj = await self.qrw.iterate() File "/home/vlad/my_projects/web/times_new_novel_asyncio/packages/aiopeewee/result.py", line 52, in iterate row = await self.cursor.fetchone() File "/home/vlad/my_projects/web/times_new_novel_asyncio/venv/lib/python3.6/site-packages/aiosqlite/core.py", line 74, in fetchone return await self._execute(self._cursor.fetchone) File "/home/vlad/my_projects/web/times_new_novel_asyncio/venv/lib/python3.6/site-packages/aiosqlite/core.py", line 44, in _execute return await self._conn._execute(fn, *args, **kwargs) File "/home/vlad/my_projects/web/times_new_novel_asyncio/venv/lib/python3.6/site-packages/aiosqlite/core.py", line 169, in _execute raise result File "/home/vlad/my_projects/web/times_new_novel_asyncio/venv/lib/python3.6/site-packages/aiosqlite/core.py", line 143, in run result = fn() sqlite3.ProgrammingError: Cannot operate on a closed database.

Seems, connections of MySql can be executed after exiting of 'with' block, but connections of SQlite - can't.

kszucs commented 6 years ago

Hey @vlad1777d ! Thanks for the PR! Hopefully I'll have time to checkout the issue in the next couple of days. Merry Xmas until that!

vlad0337187 commented 6 years ago

@kszucs, of course, when you'll have free time.

I'm not very familiar with MySQL, so I can't inspect how it's working. But seems, in query.py, result.py, etc. cursor is used with 'with' block. And seems, that after exiting from that 'with' block, MySQL connections (or cursors), can make .fetchrow().

But SQLite's can't. If so - seems, it's needed some architectural changes, not as I did - make checks for classname to SQLite every now and then.

Yeah, Merry Christmas for you to )

kszucs commented 6 years ago

@vlad1777d Still couldn't find time, but I work on it.

vlad0337187 commented 6 years ago

@kszucs , yeah, I have little time now too. It doesn't burn, so it can be done whenever =)