Package: privex-db
Privex's Python Database Library+===================================================+
|                 © 2019 Privex Inc.                |
|               https://www.privex.io               |
+===================================================+
|                                                   |
|        Privex's Python Database Library           |
|        License: X11 / MIT                         |
|                                                   |
|        Originally Developed by Privex Inc.        |
|        Core Developer(s):                         |
|                                                   |
|          (+)  Chris (@someguy123) [Privex]        |
|                                                   |
+===================================================+

Privex's Python Database Library - Database wrappers, query builders, and other useful DB-related classes/functions
Copyright (c) 2019     Privex Inc.   ( https://www.privex.io )README under construction.Install with pipWe recommend at least Python 3.6 - we cannot guarantee compatibility with older versions.pip3 install privex-dbBasic UsageBasic usage withSqliteWrapperandSqliteBuilder(db.builder())fromos.pathimportexpanduserfromprivex.dbimportSqliteWrapper# Open or create the database file ~/.my_app/my_app.dbdb=SqliteWrapper(expanduser("~/.my_app/my_app.db"))# Create the table 'items' and insert some itemsdb.action("CREATE TABLE items (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT);")db.action("INSERT INTO items (name) VALUES (?);",["Cardboard Box"])db.action("INSERT INTO items (name) VALUES (?);",["Orange"])db.action("INSERT INTO items (name) VALUES (?);",["Banana"])db.action("INSERT INTO items (name) VALUES (?);",["Stack of Paper"])item=db.fetchone("SELECT * FROM items WHERE name = ?",['Orange'])print(item.id,'-',item.name)# Output: 2 - Orangeq=db.builder('items')# Privex QueryBuilder's support chaining similar to Django's ORMq.select('id','name')\# SELECT id, name FROM items.where('name','Orange')\# WHERE name = 'Orange'.where_or('name','Banana')\# OR name = 'Banana'.order('name','id')# ORDER BY name, id DESC# You can either iterate directly over the query builder objectforrowinq:print(f"ID:{row.id}Name:{row.name}")# Output:# ID: 3   Name: Banana# ID: 2   Name: Orange# Or you can use .fetch / .all to grab a single row, or all rows as a listitem=db.builder('items').where('name','Orange').fetch()# {'id': 2, 'name': 'Orange'}items=db.builder('items').all()# [ {'id': 1, 'name': 'Cardboard Box'}, {'id': 2, 'name': 'Orange'}, ... ]DocumentationFull documentation for this project is available above (click the Read The Docs image), including:How to install the application and it's dependenciesHow to use the various functions and classesGeneral documentation of the modules and classes for contributorsTo build the documentation:pip3installpipenv
gitclonehttps://github.com/Privex/python-dbcdpython-db/docs
pipenvinstall-d# It's recommended to run make clean to ensure old HTML files are removed# `make html` generates the .html and static files in docs/build for productionmakeclean&&makehtml# After the files are built, you can live develop the docs using `make live`# then browse to http://127.0.0.1:8100/# If you have issues with content not showing up correctly, try make clean && make html# then run make live again.makeliveUnit TestsTo run the unit tests, clone the project and make a.envfile containing details for a PostgreSQL database
(for the Postgres wrapper + builder tests).DB_USER=yourname
DB_NAME=privex_py_db
DB_BACKEND=postgresql
LOG_LEVEL=DEBUGInstall all required dependencies:pip3 install pipenv
pipenv install -dNow run the tests (-v for more detailed testing output):pipenv run pytest -rxXs -v