PostgresOSM.connect_database

PostgresOSM.connect_database(database_name=None, verbose=False)

Establish a connection to a database of the PostgreSQL server being connected.

Parameters
  • database_name (str or None) – name of a database; if None (default), the database name is input manually

  • verbose (bool or int) – whether to print relevant information in console as the function runs, defaults to False

Example:

>>> from pyhelpers.sql import PostgreSQL

>>> testdb = PostgreSQL('localhost', 5432, username='postgres', database_name='testdb')
Password (postgres@localhost:5432): ***
Connecting postgres:***@localhost:5432/testdb ... Successfully.

>>> testdb.connect_database()
>>> print(testdb.database_name)
testdb

>>> testdb.connect_database('postgres', verbose=True)
Connecting postgres:***@localhost:5432/postgres ... Successfully.

>>> print(testdb.database_name)
postgres