Skip to main content

Connector

Connector Objects

class Connector(object)

Class to facilitate connections with an instance of ApertureDB

It lets the client execute any JSON query based on the ApertureDB query language specification It manages the TCP connection to the database.

note
  • The connection is established only when a query is run.
  • A new connection is established for each instance that runs a query, and gets closed only at destruction.

Arguments:

  • str host - Address of the host to connect to.
  • int port - Port to connect to.
  • str user - Username to specify while establishing a connection.
  • str password - Password to specify while connecting to ApertureDB.
  • str token - Token to use while connecting to the database.
  • bool use_ssl - Use SSL to encrypt communication with the database.
  • bool use_keepalive - Set keepalive on the connection with the database. This has two benefits: It reduces the chance of disconnection for a long-running query, and it means that disconnections are detected sooner. Turn this off to reduce traffic on high-cost network connections.
  • Configuration config - Configuration object to use for connection.

__init__

def __init__(host="localhost",
port=55555,
user="",
password="",
token="",
use_ssl=True,
shared_data=None,
authenticate=True,
use_keepalive=True,
retry_interval_seconds=1,
retry_max_attempts=3,
config: Optional[Configuration] = None)

Constructor for the Connector class.

authenticate

def authenticate(shared_data, user, password, token)

Authenticate with the database. This will be called automatically from query. This is separate from session refresh mechanism, and is set to be called only once per session. If a Refresh token also fails, this will be called again.

query

def query(q, blobs=[])

Query the database with a query string or a json object. First it checks if the session is valid, if not, it refreshes the token. Then it sends the query to the server and returns the response.

Arguments:

  • q json - native query to be sent
  • blobs list, optional - Blobs if needed with the query. Defaults to [].

Raises:

  • ConnectionError - Fatal error, connection to server lost

Returns:

  • _type_ - description

clone

def clone() -> Connector

Create a new Connector object with the same parameters as the current one. This is important in multi-threaded applications, where each thread should have its own Connector object. Be cautious when using this method, as it will create a new connection to the database, which will consume resources. Ideally, this method should be called once for each thread.

Returns:

  • Connector - Clone of original Connector

check_status

def check_status(json_res: CommandResponses) -> int

Returns the status of the first command response from the server. Can traverse a JSON recursively to find the first status.

Arguments:

  • json_res CommandResponses - The actual response from the server.

Returns:

  • int - The value recieved from the server, or -2 if not found.