Skip to content

Commit

Permalink
Fix query result named access (#448)
Browse files Browse the repository at this point in the history
  • Loading branch information
aminalaee committed Jan 20, 2022
1 parent c2417cd commit e28a8d9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
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

0 comments on commit e28a8d9

Please sign in to comment.