Skip to content

Bigbrotr

The Bigbrotr class manages connections and interactions with the Bigbrotr database.

NameTypeDescription
hoststrDatabase host
portintDatabase port
userstrDatabase user
passwordstrPassword for database access
dbnamestrDatabase name
connpsycopg2.connectionDatabase connection object
curpsycopg2.cursorCursor to execute queries on the database

Initialize a Bigbrotr object.

  • host (str): Database host
  • port (int): Database port
  • user (str): Database user
  • password (str): Password for database access
  • dbname (str): Database name
>>> bigbrotr = Bigbrotr("localhost", 5432, "admin", "admin", "bigbrotr")
  • TypeError: If any parameter is of incorrect type.

Establish connection to the database.

  • None
>>> bigbrotr.connect()
  • None

Close the database connection.

  • None
>>> bigbrotr.close()
  • None

Commit the current transaction.

  • None
>>> bigbrotr.commit()
  • None

Execute an SQL query with optional arguments.

  • query (str): SQL query string to execute
  • args (tuple, optional): Arguments for parameterized query (default is empty tuple)
>>> bigbrotr.execute("SELECT * FROM events WHERE kind = %s", (0,))
  • TypeError: If query is not a string or args is not a tuple.
  • None

Retrieve all results from the last executed query.

  • None
>>> results = bigbrotr.fetchall()
  • List[Tuple]: List of all query results.

Retrieve a single result from the last executed query.

  • None
>>> result = bigbrotr.fetchone()
  • Tuple or None: Single query result or None if no results.

Retrieve a specific number of results from the last executed query.

  • size (int): Number of rows to fetch
>>> results = bigbrotr.fetchmany(10)
  • TypeError: If size is not an integer.
  • List[Tuple]: List of query results.

Delete orphan events from the database.

  • None
>>> bigbrotr.delete_orphan_events()
  • None

Insert a single event into the database.

  • event (Event): Event object to insert
  • relay (Relay): Relay source of the event
  • seen_at (int, optional): Timestamp when the event was seen (default current time)
>>> bigbrotr.insert_event(event, relay, seen_at=1650000000)
  • TypeError: If event or relay are of incorrect type, or if seen_at is not an integer.
  • ValueError: If seen_at is negative.
  • None

Insert a single relay into the database.

  • relay (Relay): Relay object to insert
  • inserted_at (int, optional): Timestamp of insertion (default current time)
>>> bigbrotr.insert_relay(relay)
  • TypeError: If relay is not a Relay instance or inserted_at not an integer.
  • ValueError: If inserted_at is negative.
  • None

Insert relay metadata into the database.

  • relay_metadata (RelayMetadata): Relay metadata object
>>> bigbrotr.insert_relay_metadata(relay_metadata)
  • TypeError: If relay_metadata is not a RelayMetadata instance.
  • None

Insert a batch of events into the database.

  • events (List[Event]): List of Event objects to insert
  • relay (Relay): Relay source
  • seen_at (int, optional): Timestamp when events were seen (default current time)
>>> bigbrotr.insert_event_batch([event1, event2], relay)
  • TypeError: If parameters have incorrect types.
  • ValueError: If seen_at is negative.
  • None

Insert a batch of relays into the database.

  • relays (List[Relay]): List of Relay objects to insert
  • inserted_at (int, optional): Timestamp of insertion (default current time)
>>> bigbrotr.insert_relay_batch([relay1, relay2])
  • TypeError: If parameters have incorrect types.
  • ValueError: If inserted_at is negative.
  • None

Insert a batch of relay metadata entries into the database.

  • relay_metadata_list (List[RelayMetadata]): List of RelayMetadata objects
>>> bigbrotr.insert_relay_metadata_batch([metadata1, metadata2])
  • TypeError: If relay_metadata_list is not a list of RelayMetadata instances.
  • None