PostgresManager
A simple Python wrapper for psycopg logic, to streamline DB interaction in the MAGNET solution.
Getting started
To develop
virtualenv venv
source venv/bin/bash
pip install -r requirements.txt
To run unit tests
pytest tests/tests.py
How to use
import postgresmanager
def main():
pm = postgresmanager(host='hostname',port=5432,database='dbname',user='username',password='password')
# Assume there exists a database connection and within the database, a table called Names
# let's insert a new person named John Doe into the table name
# Build the data object representing the columns and values to be inserted into desired table
table = "names"
data = {"name": "John Doe"}
# INSERT INTO names(name) VALUES('John Doe')
pm.insert(table,data)
# Retrieve the name
# This returns a list of all names under the name column.
columns = ['name']
## SELECT name FROM names;
r = pm.select(table,columns)
# [('John Doe'),...]
# OR, using a WHERE clause
where_cond = {"name":"John Doe"}
## SELECT name FROM names WHERE name = 'John Doe';
r = pm.select(table,columns,where_cond)
# [('John Doe')]
Description
Languages
Python
100%