You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As far as I know, when creating a service that returns a list/collection of dictionaries (e.g. a query made through SQLAlchemy on the Customer entity/table resulting in multiple rows) there are two ways to specify that the service will return a list of dictionaries and not just a single dictionary.
When using SimpleIO:
# Channel GET /app/customers calls customer.get-customer
class GetCustomers(Service):
class SimpleIO:
input_required = ()
output_optional = ('id', 'name', 'surname', 'email', ...)
output_repeated = True
def handle(self):
conn = self.kvdb.conn.get('app:database:conn')
with closing(self.outgoing.sql.get(conn).session()) as session:
result = session.query(Customer).order_by(Customer.id)
output = []
for row in result:
output.append(row)
# I believe use of [:] next is optional as output_repeated = True was set before
self.response.payload[:] = output
When not using SimpleIO:
# Channel GET /app/customers calls customer.get-customer
class GetCustomers(Service):
def handle(self):
conn = self.kvdb.conn.get('app:database:conn')
with closing(self.outgoing.sql.get(conn).session()) as session:
result = session.query(Customer).order_by(Customer.id)
output = []
for row in result:
output.append(row)
# Use of [:] next is mandatory
self.response.payload[:] = output
I have updated the SIO documentation. In particular:
I have noticed that there was already a section about returning a list of elements (called "Returning a list of elements"). Do you think it answers your needs or would you recommend to change it?
I added information about features new in 3.0 throughout the chapter, they are also listed in the changelog at the bottom
It looks that this can be closed. Also, in the new SIO dictionaries are greatly enhanced, they not only can be recursive but individual keys can be specified on input or output too.
This is still work in progress in ticket #894 so for now the best way to observe it is consulting this module:
As far as I know, when creating a service that returns a list/collection of dictionaries (e.g. a query made through SQLAlchemy on the Customer entity/table resulting in multiple rows) there are two ways to specify that the service will return a list of dictionaries and not just a single dictionary.
When using SimpleIO:
When not using SimpleIO:
The only reference I have been able to find online is in the Python client document.
I think this requires further clarification and examples in the online documentation.
The text was updated successfully, but these errors were encountered: