Pony ORM extension for yhttp.
sudo apt`install python3-dev libpq-dev postgresql # Postgresql
pip install yhttp-ponyThis is how to use the extension.
from yhttp import Appliation, json
from yhttp.ext import pony as ponyext
from pony.orm import db_session as dbsession, PrimaryKey, Required
app = Application()
app.settings.merge('''
db:
url: postgres://postgres:postgres@localhost/foo
''')
db = ponyext.install(app)
class Foo(db.Entity):
id = PrimaryKey(int, auto=True)
title = Required(str)
@app.route()
@json
@dbsession
def get(req):
return {f.id:f.title for f in Foo.select()}
app.ready()There is some command line interfaces which will be automatically added to
your application when you call dbmanager.install(app, ...) and
ponyext.install(app, ...).
myapp db create
myapp db objects create
myapp db dropimport easycli
from yhttp.ext import dbmanager, ponyext
from mypackage import app # yhttp application
class InsertMockupCommand(easycli.SubCommand):
__command__ = 'insert-mockup'
def __call__(self, args):
ponyext.initialize(app.db, app.settings.db)
# Insert mockup data
ponyext.deinitialize(app.db)
class VerifyObjectsCommand(easycli.SubCommand):
__command__ = 'verify'
__aliases__ = ['v']
def __call__(self, args):
ponyext.initialize(app.db, app.settings.db)
# Verify database objects
ponyext.deinitialize(app.db)
...
dbmanager.install(app, cliarguments=[InsertMockupCommand])
db = ponyext.install(app, cliarguments=[VerifyObjectsCommand])Use it as:
myapp db create
myapp db insert-mockup
myapp db objects create
myapp db objects verify
myapp db dropInstall postgresql brefore use of this project.
apt install postgresqlCreate and grant the postgresql role with createdb permission to
authenticate the current unix user within postgresql using the peer
authentication.
echo "CREATE USER ${USER} WITH CREATEDB" | sudo -u postgres psql
# Or
echo "ALTER USER ${USER} CREATEDB" | sudo -u postgres psqlCreate virtual environment:
make venvDelete virtual environment:
make venv-deleteActivate the virtual environment:
source ./activate.shInstall this project as editable mode and all other development dependencies:
make envExecute all tests:
make testExecute specific test(s) using wildcard:
make test F=tests/test_db*
make test F=tests/test_form.py::test_querystringformrefer to pytest documentation for more info about invoking tests.
Execute tests and report coverage result:
make cover
make cover F=tests/test_static.py
make cover-htmlmake lintExecute these commands to create Python's standard distribution packages
at dist directory:
make sdist
make wheelOr
make distto create both sdidst and wheel packages.
Execute:
make cleanto clean-up previous dist/* and build/* directories.
WARNING: Do not do this if you'r not responsible as author and or maintainer of this project.
Execute
make clean
make pypito upload sdists and wheel packages on PyPI.