class_docstr: A database manager class that handles the creation and interaction with an SQLite database.
class_docstr_tok: ["A","database","manager","class","that","handles","the","creation","and","interaction","with","an","SQLite","database","."]
docstr: Executes a given SQL query and returns the results.
  
  Args:
      query (str): The SQL query to execute.
      args (Tuple): The arguments to pass to the SQL query.
      return_json (bool): If True, the results will be returned as a list of dictionaries.
  
  Returns:
      List[Dict[str, Any]]: The result of the SQL query.
docstr_tok: ["Executes","a","given","SQL","query","and","returns","the","results",".","Args",":","query","(","str",")",":","The","SQL","query","to","execute",".","args","(","Tuple",")",":","The","arguments","to","pass","to","the","SQL","query",".","return_json","(","bool",")",":","If","True",",","the","results","will","be","returned","as","a","list","of","dictionaries",".","Returns",":","List","[","Dict","[","str",",","Any","]","]",":","The","result","of","the","SQL","query","."]
code: def query(
      self, query: str, args: Tuple = (), return_json: bool = False
  ) -> List[Dict[str, Any]]:
      """
      Executes a given SQL query and returns the results.
  
      Args:
          query (str): The SQL query to execute.
          args (Tuple): The arguments to pass to the SQL query.
          return_json (bool): If True, the results will be returned as a list of dictionaries.
  
      Returns:
          List[Dict[str, Any]]: The result of the SQL query.
      """
      try:
          with lock:
              self.cursor.execute(query, args)
              result = self.cursor.fetchall()
              self.commit()
              if return_json:
                  result = [
                      dict(
                          zip(
                              [
                                  key[0]
                                  for key in self.cursor.description
                              ],
                              row,
                          )
                      )
                      for row in result
                  ]
              return result
      except Exception as e:
          logger.error(
              "Error running query with query %s and args %s: %s",
              query,
              args,
              e,
          )
          raise e
  
imports: import json
  import logging
  import sqlite3
  import threading
  import os
  from typing import Any, List, Dict, Optional, Tuple
  from ..datamodel import AgentFlowSpec, AgentWorkFlowConfig, Gallery, Message, Session, Skill
label_desc: Use image node_id 4 for calling the DBManager obj's underlying member method code with example usage: obj.query(query, args, return_json) and returns: result