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:
If no arguments are provided, it establishes a connection to the default session.
If a
catalogname is provided, it connects to a specific catalog.If a
urlis provided, it establishes a connection to an OLTP database, optionally using additional connection options.If
hostandportare provided, it connects to a remote database, optionally usinguserandpasswdfor 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 toNone. option (Config, optional): Additional options for the connection. Defaults toNone. host (str, optional): The hostname of the remote database. Defaults toNone. port (int, optional): The port number of the remote database. Defaults toNone. 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")