fetch

GenericDBWrapper.fetch(sql: str, *params, fetch='all', **kwparams) → Union[dict, tuple, List[dict], List[tuple], None][source]

Similar to query() but only returns the fetch results, not the execution object nor cursor.

Example Usage (default query mode)::
>>> s = GenericDBWrapper()
>>> user = s.fetch("SELECT * FROM users WHERE id = ?;", [123], fetch='one')
>>> user
(123, 'john', 'doe',)

Example Usage (dict query mode):

>>> s.query_mode = 'dict'    # Or s = SqliteWrapper(query_mode='dict')
>>> res = s.fetch("SELECT * FROM users WHERE id = ?;", [123], fetch='one')
>>> res
{'id': 123, 'first_name': 'john', 'last_name': 'doe'}
Parameters
  • fetch (str) – Either 'all' or 'one' - controls whether the result is fetched with GenericCursor.fetchall() or GenericCursor.fetchone()

  • sql (str) – An SQL query to execute on the current DB, as a string.

  • params – Extra arguments will be passed through to cursor.execute(sql, *params, **kwparams)

  • kwparams – Extra arguments will be passed through to cursor.execute(sql, *params, **kwparams)

Returns