SQL databases are accessed through
SQLAlchemy
sessions and any feature SQLAlchemy supports is available to Zato services.

Regardless of how a database is accessed and what sort of queries are issued,
it’s always required to close a session object when a service is done using it.
It’s easiest to use the Python’s built-in
contextlib.closing
manager for doing it.

# stdlibfromcontextlibimportclosing# Zatofromzato.server.serviceimportServiceclassMyService(Service):defhandle(self):# Always use templates and bind variablestemplate='SELECT name FROM http_soap WHERE data_format=:data_format'parameters={'data_format':'json'}withclosing(self.outgoing.sql.get('my-conn').session())assession:result=session.execute(template,parameters)foriteminresult:self.logger.info(item)