-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix error for cursor.connection(return not async connection) #296
base: main
Are you sure you want to change the base?
fix error for cursor.connection(return not async connection) #296
Conversation
my usecase, where was error. from contextlib import asynccontextmanager
import aiosqlite
from aiosqlite import Cursor
from settings import conf
@asynccontextmanager
async def get_db() -> Cursor:
async with aiosqlite.connect(conf.DATABASE_URL) as conn:
conn.row_factory = aiosqlite.Row
if conf.SQLITE3_ECHO:
await conn.set_trace_callback(print)
async with conn.cursor() as cur:
yield cur import asyncio
from sql_app.database import get_db
async def main():
async with get_db() as cur:
with open("sql_app/sql_files/create_table_cities.sql") as f:
data = f.read()
await cur.executescript(data)
await cur.connection.commit()
if __name__ == "__main__":
asyncio.run(main()) result:
|
@@ -106,3 +106,4 @@ ENV/ | |||
|
|||
# Editors | |||
.vscode/ | |||
.idea/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.idea/
@@ -108,8 +108,8 @@ def row_factory(self, factory: Optional[Type]) -> None: | |||
self._cursor.row_factory = factory | |||
|
|||
@property | |||
def connection(self) -> sqlite3.Connection: | |||
return self._cursor.connection |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_cursor.connection
@@ -108,8 +108,8 @@ def row_factory(self, factory: Optional[Type]) -> None: | |||
self._cursor.row_factory = factory | |||
|
|||
@property | |||
def connection(self) -> sqlite3.Connection: | |||
return self._cursor.connection | |||
def connection(self) -> "Connection": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
" "
def connection(self) -> sqlite3.Connection: | ||
return self._cursor.connection | ||
def connection(self) -> "Connection": | ||
return self._conn |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_conn
@@ -108,8 +108,8 @@ def row_factory(self, factory: Optional[Type]) -> None: | |||
self._cursor.row_factory = factory | |||
|
|||
@property | |||
def connection(self) -> sqlite3.Connection: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sqlite3.
Description
method connection for cursor return not async connection
Fixes: # replace on async connection
self._conn