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
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 the db.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: 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 called only once. Failure leads to exception.
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 sentblobs
list, optional - Blobs if needed with the query. Defaults to [].
Raises:
ConnectionError
- Fatal error, connection to server lost
Returns:
_type_
- description
create_new_connection
def create_new_connection() -> Connector
Create a new connection object with the same parameters as the current one. This is important in multi-threaded applications, where each thread should have its own connection object. Because the connection object is not thread-safe, it is not safe to share it between threads. 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:
connection
- Clone of original connection