From ea21d83d3f321902deb01dd56208c35baceab0d8 Mon Sep 17 00:00:00 2001 From: tanuki tanuki Date: Mon, 10 Nov 2025 10:31:36 -0500 Subject: [PATCH] first commit --- README.md | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..8b707b3 --- /dev/null +++ b/README.md @@ -0,0 +1,51 @@ +# PostgresManager + +A simple Python wrapper for psycopg logic, to streamline DB interaction in the MAGNET solution. + + +## Getting started + +To develop +```bash +virtualenv venv +source venv/bin/bash +pip install -r requirements.txt +``` + +To run unit tests +```bash +pytest tests/tests.py +``` + +## How to use + +```python +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')] +``` \ No newline at end of file