Python Driver: Connection

The Connection class is a fundamental part of the Polypheny Python Driver, enabling users to establish connections to the Polypheny database and perform various database operations. This section provides a detailed reference for the Connection class, including its constructor, methods, and usage examples.

Constructor

Connection(address, port, username, password, transport)

Initializes a new instance of the Connection class, which represents a connection to a Polypheny database.

Parameters:

  • address (str): The hostname or IP address of the Polypheny database server.
  • port (int): The port number on which the Polypheny server is listening.
  • username (str): The username for authenticating with the Polypheny database.
  • password (str): The password for authenticating with the Polypheny database.
  • transport (str): The transport method used for communication with the Polypheny server (e.g., ‘plain’).

Example:

conn = Connection(address='localhost', port=20590, username='admin', password='secret', transport='http')

cursor()

Creates a new cursor object, which is used to execute database commands.

Returns:

  • Cursor object: A new cursor for the connection.

Example:

cursor = conn.cursor()

commit()

Commits the current transaction, making all changes made during the transaction permanent.

Example:

conn.commit()

rollback()

Rolls back the current transaction, reverting all changes made during the transaction.

Example:

conn.rollback()

close()

Closes the connection to the database. This method ensures that the connection is cleanly closed and all associated resources are freed.

Example:

conn.close()

Error Handling

The Connection class may raise various exceptions to indicate errors. See Error Handling for more details.

Thread Safety

The Connection class is not inherently thread-safe. If you need to use a Connection object in a multithreaded environment, ensure proper synchronization (e.g., using threading locks) or use separate Connection objects in each thread.

© Polypheny GmbH. All Rights Reserved.