platypush/plugins/db/__init__.py
def select(self, query=None, table=None, filter=None, engine=None, *args, **kwargs):
        """
        Returns rows (as a list of hashes) given a query.

        :param query: SQL to be executed
        :type query: str
        :param filter: Query WHERE filter expressed as a dictionary. This approach is preferred over specifying raw SQL
            in ``query`` as the latter approach may be prone to SQL injection, unless you need to build some complex
            SQL logic.
        :type filter: dict
        :param table: If you specified a filter instead of a raw query, you'll have to specify the target table
        :type table: str
        :param engine: Engine to be used (default: default class engine)
        :type engine: str
        :param args: Extra arguments that will be passed to ``sqlalchemy.create_engine``
            (see https://docs.sqlalchemy.org/en/latest/core/engines.html)
        :param kwargs: Extra kwargs that will be passed to ``sqlalchemy.create_engine``
            (seehttps:///docs.sqlalchemy.org/en/latest/core/engines.html)
        :returns: List of hashes representing the result rows.

        Examples:

            Request::

                {
                    "type": "request",
                    "target": "your_host",
                    "action": "db.select",
                    "args": {
                        "engine": "sqlite:///:memory:",
                        "query": "SELECT id, name FROM table"
                    }
                }

            or::

                {
                    "type": "request",
                    "target": "your_host",
                    "action": "db.select",
                    "args": {
                        "engine": "sqlite:///:memory:",
                        "table": "table",
                        "filter": {"id": 1}
                    }
                }

            Response::

                [
                    {
                        "id": 1,
                        "name": foo
                    }
                ]
        """

        engine = self._get_engine(engine, *args, **kwargs)

        if table:
            table, engine = self._get_table(table, engine=engine, *args, **kwargs)
            query = table.select()

            if filter:
                for (k,v) in filter.items():
                    query = query.where(self._build_condition(table, k, v))

        if query is None:
            raise RuntimeError('You need to specify either "query", or "table" and "filter"')

        with engine.connect() as connection:
            result = connection.execute(query)

            columns = result.keys()
            rows = [
                { columns[i]: row[i] for i in range(0, len(columns)) }
                for row in result.fetchall()
            ]

        return rows

        Returns rows (as a list of hashes) given a query.

        :param query: SQL to be executed
        :type query: str
        :param filter: Query WHERE filter expressed as a dictionary. This approach is preferred over specifying raw SQL
            in ``query`` as the latter approach may be prone to SQL injection, unless you need to build some complex
            SQL logic.
        :type filter: dict
        :param table: If you specified a filter instead of a raw query, you'll have to specify the target table
        :type table: str
        :param engine: Engine to be used (default: default class engine)
        :type engine: str
        :param args: Extra arguments that will be passed to ``sqlalchemy.create_engine``
            (see https://docs.sqlalchemy.org/en/latest/core/engines.html)
        :param kwargs: Extra kwargs that will be passed to ``sqlalchemy.create_engine``
            (seehttps:///docs.sqlalchemy.org/en/latest/core/engines.html)
        :returns: List of hashes representing the result rows.

        Examples:

            Request::

                {
                    "type": "request",
                    "target": "your_host",
                    "action": "db.select",
                    "args": {
                        "engine": "sqlite:///:memory:",
                        "query": "SELECT id, name FROM table"
                    }
                }

            or::

                {
                    "type": "request",
                    "target": "your_host",
                    "action": "db.select",
                    "args": {
                        "engine": "sqlite:///:memory:",
                        "table": "table",
                        "filter": {"id": 1}
                    }
                }

            Response::

                [
                    {
                        "id": 1,
                        "name": foo
                    }
                ]
        
Returns rows (as a list of hashes) given a query.
Returns rows ( as a list of hashes ) given a query .
def select(self, query=None, table=None, filter=None, engine=None, *args, **kwargs):
        engine = self._get_engine(engine, *args, **kwargs)
        if table:
            table, engine = self._get_table(table, engine=engine, *args, **kwargs)
            query = table.select()
            if filter:
                for (k,v) in filter.items():
                    query = query.where(self._build_condition(table, k, v))
        if query is None:
            raise RuntimeError('You need to specify either "query", or "table" and "filter"')
        with engine.connect() as connection:
            result = connection.execute(query)
            columns = result.keys()
            rows = [
                { columns[i]: row[i] for i in range(0, len(columns)) }
                for row in result.fetchall()
            ]
        return rows
def select ( self , query = None , table = None , filter = None , engine = None , * args , ** kwargs ) : engine = self . _get_engine ( engine , * args , ** kwargs ) if table : table , engine = self . _get_table ( table , engine = engine , * args , ** kwargs ) query = table . select ( ) if filter : for ( k , v ) in filter . items ( ) : query = query . where ( self . _build_condition ( table , k , v ) ) if query is None : raise RuntimeError ( 'You need to specify either "query", or "table" and "filter"' ) with engine . connect ( ) as connection : result = connection . execute ( query ) columns = result . keys ( ) rows = [ { columns [ i ] : row [ i ] for i in range ( 0 , len ( columns ) ) } for row in result . fetchall ( ) ] return rows
Returns rows (as a list of hashes) given a query.
Returns rows ( as a list of hashes ) given a query .
"""
        Returns rows (as a list of hashes) given a query.

        :param query: SQL to be executed
        :type query: str
        :param filter: Query WHERE filter expressed as a dictionary. This approach is preferred over specifying raw SQL
            in ``query`` as the latter approach may be prone to SQL injection, unless you need to build some complex
            SQL logic.
        :type filter: dict
        :param table: If you specified a filter instead of a raw query, you'll have to specify the target table
        :type table: str
        :param engine: Engine to be used (default: default class engine)
        :type engine: str
        :param args: Extra arguments that will be passed to ``sqlalchemy.create_engine``
            (see https://docs.sqlalchemy.org/en/latest/core/engines.html)
        :param kwargs: Extra kwargs that will be passed to ``sqlalchemy.create_engine``
            (seehttps:///docs.sqlalchemy.org/en/latest/core/engines.html)
        :returns: List of hashes representing the result rows.

        Examples:

            Request::

                {
                    "type": "request",
                    "target": "your_host",
                    "action": "db.select",
                    "args": {
                        "engine": "sqlite:///:memory:",
                        "query": "SELECT id, name FROM table"
                    }
                }

            or::

                {
                    "type": "request",
                    "target": "your_host",
                    "action": "db.select",
                    "args": {
                        "engine": "sqlite:///:memory:",
                        "table": "table",
                        "filter": {"id": 1}
                    }
                }

            Response::

                [
                    {
                        "id": 1,
                        "name": foo
                    }
                ]
        """
List of hashes representing the result rows.
Examples.



{
"type": "request",
"target": "your_host",
"action": "db.select",
"args": {
"engine": "sqlite:///:memory:",
"query": "SELECT id, name FROM table"
}
}








List of hashes representing the result rows . Examples . { " type " : " request " " target " : " your_host " " action " : " db . select " " args " : { " engine " : " sqlite : /// : memory : " " query " : " SELECT id name FROM table " } }
self
query
SQL to be executed
SQL to be executed
table
If you specified a filter instead of a raw query, you'll have to specify the target table
If you specified a filter instead of a raw query you ' ll have to specify the target table
filter
Query WHERE filter expressed as a dictionary. This approach is preferred over specifying raw SQL
in ``query`` as the latter approach may be prone to SQL injection, unless you need to build some complex
SQL logic.
Query WHERE filter expressed as a dictionary . This approach is preferred over specifying raw SQL in ` ` query ` ` as the latter approach may be prone to SQL injection unless you need to build some complex SQL logic .
engine
Engine to be used (default: default class engine)
Engine to be used ( default : default class engine )
args
Extra arguments that will be passed to ``sqlalchemy.create_engine``
Extra arguments that will be passed to ` ` sqlalchemy . create_engine ` `
kwargs
Extra kwargs that will be passed to ``sqlalchemy.create_engine``
Extra kwargs that will be passed to ` ` sqlalchemy . create_engine ` `