connect#

swordfish.connect() DefaultSessionConnection#
swordfish.connect(catalog: str) CatalogConnection
swordfish.connect(*, url: str, option: OLTPOption | dict | None = None) OLTPConnection
swordfish.connect(*, host: str, port: int, user: str = '', passwd: str = '') RemoteConnection

Establishes a connection to different types of databases or sessions based on the provided parameters.

This function supports multiple connection methods depending on the given arguments:

  1. If no arguments are provided, it establishes a connection to the default session.

  2. If a catalog name is provided, it connects to a specific catalog.

  3. If a url is provided, it establishes a connection to an OLTP database, optionally using additional connection options.

  4. If host and port are provided, it connects to a remote database, optionally using user and passwd for authentication.

Args:

catalog (Optional[str], optional): The name of the catalog to connect to. Defaults to None. url (Optional[str], optional): The URL of the OLTP database. Defaults to None. option (Config, optional): Additional options for the connection. Defaults to None. host (str, optional): The hostname of the remote database. Defaults to None. port (int, optional): The port number of the remote database. Defaults to None. user (str, optional): The username for authentication. Defaults to an empty string. passwd (str, optional): The password for authentication. Defaults to an empty string.

Returns:
Connection: An established connection based on the provided arguments.
  • The first method returns a DefaultSessionConnection object.

  • The second method returns a CatalogConnection object.

  • The third method returns a OLTPConnection object.

  • The fourth method returns a RemoteConnection object.

Examples:

Connect to the default session:

>>> conn = sf.connect()

Connect to a specific catalog:

>>> conn = sf.connect(catalog="catalog_name")

Connect to an OLTP database:

>>> conn = sf.connect(url="url_name", option={'readOnly': True})

Connect to a remote database:

>>> conn = sf.connect(host="192.168.1.2", port=8848, user="admin", passwd="123456")