This file contains 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
import psycopg2 | |
def connect_postgres(): | |
#get configparser | |
config = get_configParser() | |
#import configuration information to connect to remote postrgre database | |
postgresServer = config['database_postgres']['postgres_server'] | |
postgrestPort = config['database_postgres']['postgres_port'] | |
postgresDatabase = config['database_postgres']['postgres_database'] |
This file contains 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
import psycopg2 | |
def create_table(): | |
#Referece: Constructing #Postgresql connection obect | |
sql_create_asset_table = ('''CREATE TABLE IF NOT EXISTS ASSETS ( | |
ID SERIAL PRIMARY KEY, | |
NAME TEXT NOT NULL, | |
LICENSE TEXT NOT NULL, |
This file contains 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
import psycopg2 | |
def insert_object(): | |
#Referece: Constructing #Postgresql connection obect | |
cursor.execute("""INSERT INTO TABLENAME(COLUMNS)\ | |
VALUES (%s)""",(OBJECT)) | |
conn.commit() |
This file contains 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
''' | |
Generator functions allow you to declare a function that behaves like an iterator, i.e. it can be used in a for loop. | |
Objects are not stored in memory. | |
''' | |
def generator_function(): | |
counter = 0 | |
x = 10 | |
while counter < x: |