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
And here is the documentation
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
here is
sqlalchemy
version that works but usingdatabases
package not working as mentioned above
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)
Just want to get similar result as this sqlalchmey one but using databases
as mentioned at beginning of this question