Db

The db package enables connecting to a Firebolt database for synchronous queries.

Db.connection

class firebolt.db.connection.Connection(*args: Any, **kwargs: Any)

Bases: firebolt.async_db.connection.BaseConnection

Firebolt database connection class. Implements PEP-249.

Parameters
  • engine_url – Firebolt database engine REST API url

  • database – Firebolt database name

  • username – Firebolt account username

  • password – Firebolt account password

  • api_endpoint – Optional. Firebolt API endpoint. Used for authentication.

Note

Firebolt currenly doesn’t support transactions so commit and rollback methods are not implemented.

api_endpoint
client_class: type
close() None

Close connection and all underlying cursors.

cursor() firebolt.db.cursor.Cursor
cursor_class

alias of firebolt.db.cursor.Cursor

database
engine_url

Db.cursor

class firebolt.db.cursor.Cursor(*args: Any, **kwargs: Any)

Bases: firebolt.async_db.cursor.BaseCursor

Class, responsible for executing queries to Firebolt Database. Should not be created directly, use connection.cursor

Parameters
  • description – Information about a single result row

  • rowcount – The number of rows produced by last query

  • closed – True if connection is closed, False otherwise

  • arraysize – Read/Write, specifies the number of rows to fetch at a time with the fetchmany() method

connection
execute(query: str, parameters: Optional[Sequence[Union[int, float, str, datetime.datetime, datetime.date, bool, decimal.Decimal, Sequence]]] = None, set_parameters: Optional[Dict] = None, skip_parsing: bool = False) int

Prepare and execute a database query.

Supported features:
Parameterized queries: placeholder characters (‘?’) are substituted

with values provided in parameters. Values are formatted to be properly recognized by database and to exclude SQL injection.

Multi-statement queries: multiple statements, provided in a single query

and separated by semicolon are executed separatelly and sequentially. To switch to next statement result, nextset method should be used.

SET statements: to provide additional query execution parameters, execute

SET param=value statement before it. All parameters are stored in cursor object until it’s closed. They can also be removed with flush_parameters method call.

Parameters
  • query (str) – SQL query to execute

  • parameters (Optional[Sequence[ParameterType]]) – A sequence of substitution parameters. Used to replace ‘?’ placeholders inside a query with actual values

  • set_parameters (Optional[Dict]) – List of set parameters to execute a query with. DEPRECATED: Use SET SQL statements instead

  • skip_parsing (bool) – Flag to disable query parsing. This will disable parameterized, multi-statement and SET queries, while improving performance

Returns

Query row count

Return type

int

executemany(query: str, parameters_seq: Sequence[Sequence[Union[int, float, str, datetime.datetime, datetime.date, bool, decimal.Decimal, Sequence]]]) int

Prepare and execute a database query.

Supports providing multiple substitution parameter sets, executing them as multiple statements sequentially.

Supported features:
Parameterized queries: placeholder characters (‘?’) are substituted

with values provided in parameters. Values are formatted to be properly recognized by database and to exclude SQL injection.

Multi-statement queries: multiple statements, provided in a single query

and separated by semicolon are executed separatelly and sequentially. To switch to next statement result, nextset method should be used.

SET statements: to provide additional query execution parameters, execute

SET param=value statement before it. All parameters are stored in cursor object until it’s closed. They can also be removed with flush_parameters method call.

Parameters
  • query (str) – SQL query to execute

  • parameters_seq (Sequence[Sequence[ParameterType]]) – A sequence of substitution parameter sets. Used to replace ‘?’ placeholders inside a query with actual values from each set in a sequence. Resulting queries for each subset are executed sequentially.

Returns

Query row count

Return type

int

fetchall() List[List[Optional[Union[int, float, str, datetime.datetime, datetime.date, bool, list, decimal.Decimal]]]]

Fetch all remaining rows of a query result.

fetchmany(size: Optional[int] = None) List[List[Optional[Union[int, float, str, datetime.datetime, datetime.date, bool, list, decimal.Decimal]]]]

Fetch the next set of rows of a query result, cursor.arraysize is default size.

fetchone() Optional[List[Optional[Union[int, float, str, datetime.datetime, datetime.date, bool, list, decimal.Decimal]]]]

Fetch the next row of a query result set.

nextset() Optional[bool]

Skip to the next available set, discarding any remaining rows from the current set. Returns True if operation was successful, None if there are no more sets to retrive