Skip to content
This repository was archived by the owner on Aug 19, 2025. It is now read-only.
This repository was archived by the owner on Aug 19, 2025. It is now read-only.

why am i not getting results of raw sql query back??? #338

@encryptblockr

Description

@encryptblockr

I have the following but for some reason instead of getting results of my query, i am getting something else

here is the python package am using

https://pypi.org/project/databases/

and here is the documentation

https://www.encode.io/databases/database_queries/

from databases import Database
database=Database('postgres://redacted')
await database.connect()
...
...
...
query = "SELECT orders.id AS orders_id, orders.notification_method AS orders_notification_method WHERE shipped=True"
result = await database.fetch_all(query=query))

here is what am getting instead of getting results of my query

print(result)

[<databases.backends.postgres.Record object at 0x7fb3f415ac50>, <databases.backends.postgres.Record object at 0x7fb3f415ae30>, <databases.backends.postgres.Record object at 0x7fb3f415a470>, <databases.backends.postgres.Record object at 0x7fb3f415af50>, <databases.backends.postgres.Record object at 0x7fb3f415ad70>, <databases.backends.postgres.Record object at 0x7fb3f415ab30>, <databases.backends.postgres.Record object at 0x7fb3f415a7d0>, <databases.backends.postgres.Record object at 0x7fb3f415ae90>]

and type says it is a list

print(type(result))

<class 'list'>

how do i return the actual result of the sql query which is to return all rows from the query???

What i really want to do

what i pretty much want to achieve is to have similar result from sqlalchemy query like below and be able to iterate over the rows from the result of the query

...
...
...
class Orders:
    id: Optional[int]
    notification_method: str
    shipped: Optional[bool]

...
...
...
session = create_session()
result=session.query(Orders).filter(Orders.shipped == True)

print(result)

SELECT orders.id AS orders_id, orders.notification_method AS orders_notification_method FROM orders 
WHERE orders.shipped = true

print(type(result))

<class 'sqlalchemy.orm.query.Query'>

and then i want to be able to iterate over the rows

for r in result:
    print(r)

output

Orders(id=1, notification_method='call', shipped=True)
Orders(id=2, notification_method='sms', shipped=True)
Orders(id=3, notification_method='call', shipped=True)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions