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

Better documenting of services returning a list of dictionaries #876

Closed
jsabater opened this issue Aug 30, 2018 · 2 comments
Closed

Better documenting of services returning a list of dictionaries #876

jsabater opened this issue Aug 30, 2018 · 2 comments
Milestone

Comments

@jsabater
Copy link
Contributor

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

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.

@dsuch
Copy link
Collaborator

dsuch commented Sep 26, 2018

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

https://zato.io/docs/progguide/sio.html

@dsuch
Copy link
Collaborator

dsuch commented Jan 24, 2019

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:

https://github.com/zatosource/zato/blob/dsuch-f-gh894-sio-refactor/code/zato-cy/test/zato/cy/test_simpleio.py

@dsuch dsuch closed this as completed Jan 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants