ManifoldDatabase#

class autofold.database.ManifoldDatabase(db_path)#

Bases: object

ManifoldDatabase class to manage SQLite3 database connections.

This class uses thread-local storage to ensure that each thread has its own SQLite3 database connection. It also ensures that the database and its parent directory exist before creating a connection.

Attributes:#

  • db_path: The path to the SQLite3 database file

  • local_storage: Thread-local storage for SQLite3 connections

param str db_path:

Reqauired. The path to the SQLite3 database file. Should be a .db file.

raises OSError:

If the specified directory cannot be created.

create_tables()#
get_conn()#
upsert_bets(bets: list[dict])#
upsert_binary_choice_markets(markets: list[dict])#
upsert_contract_metrics(contract_metrics: list[dict])#
upsert_multiple_choice_markets(markets: list[dict])#
upsert_users(users: list[dict])#
class autofold.database.ManifoldDatabaseReader(manifold_db)#

Bases: object

dict_factory(cursor, row)#

Row factory to produce dictionary results.

execute_query(query, params=None)#

Execute a read query and return the results.

Parameters:
  • query – The SQL query string.

  • params – Any parameters for the query (optional).

Returns:

The query results.

class autofold.database.ManifoldDatabaseWriter(manifold_db)#

Bases: object

is_alive()#

Checks if the worker_thread is running.

Returns:

True if worker_thread is running, False otherwise.

Return type:

bool

queue_write_operation(function, data)#

Queue a write operation to the database.

Parameters:
  • function – The function to execute (a write function from ManifoldDatabase class).

  • data – The data to write.

Returns:

Future object representing the execution of the operations.

shutdown()#
autofold.database.prepare_and_execute_multi_deletion(conn, query, ids)#
autofold.database.prepare_and_execute_multi_upsert(conn, query, fields, data)#
autofold.database.sanitize_value(value)#