Last active
September 26, 2020 20:36
-
-
Save exy02/331f52795211edd2b0ea3979a05fc4e2 to your computer and use it in GitHub Desktop.
Simplified PostgreSQL querying (with or without SSH) - Class Initialization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
p_host = '0.0.0.0' | |
p_port = 5432 | |
db = 'database_name' | |
ssh = True | |
ssh_user = 'ssh_user' | |
ssh_host = 'ip address or web address' | |
ssh_pkey = '/path/to/user_authentication.pem' | |
pgres = Postgresql_connect(pgres_host=p_host, pgres_port=p_port, db=db, ssh=ssh, ssh_user=ssh_user, ssh_host=ssh_host, ssh_pkey=ssh_pkey) | |
#initiates a connection to the PostgreSQL database. In this instance we use ssh and must specify our ssh credentials. | |
#You'll need to define psql_user and psql_pass using input() and getpass() to temporarily store your credentials. | |
#Alternatively, best practice you may be to store your credentials as environment variables. | |
psql_user = input("Please enter your database username:") | |
psql_pass = getpass.getpass(f"Welcome {psql_user}! || Password:") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment