Skip to content
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 query result named access #448

Merged
merged 1 commit into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions databases/backends/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ def __iter__(self) -> typing.Iterator:
def __len__(self) -> int:
return len(self._row)

def __getattr__(self, name: str) -> typing.Any:
return self._mapping.get(name)


class PostgresConnection(ConnectionBackend):
def __init__(self, database: PostgresBackend, dialect: Dialect):
Expand Down
16 changes: 16 additions & 0 deletions tests/test_databases.py
Original file line number Diff line number Diff line change
Expand Up @@ -1206,3 +1206,19 @@ async def test_postcompile_queries(database_url):
results = await database.fetch_all(query=query)

assert len(results) == 0


@pytest.mark.parametrize("database_url", DATABASE_URLS)
@mysql_versions
@async_adapter
async def test_result_named_access(database_url):
async with Database(database_url) as database:
query = notes.insert()
values = {"text": "example1", "completed": True}
await database.execute(query, values)

query = notes.select().where(notes.c.text == "example1")
result = await database.fetch_one(query=query)

assert result.text == "example1"
assert result.completed is True