first commit
This commit is contained in:
51
README.md
Normal file
51
README.md
Normal file
@@ -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')]
|
||||
```
|
||||
Reference in New Issue
Block a user