A framework-independent wrapper for SQLAlchemy that makes it really easy to use.
Project description
A friendly wrapper for SQLAlchemy.
from sqla_wrapper import SQLAlchemy
db = SQLAlchemy('sqlite:///:memory:')
class ToDo(db.Model):
id = db.Column(db.Integer, primary_key=True)
...
db.create_all()
db.add(Todo(...))
db.commit()
# Sorry, we don't support the `Model.query` syntax
todos = db.query(ToDo).all()
Read the complete documentation here: https://jpscaletti.com/sqla-wrapper
Since 2.0, only Python 3.6 or later are supported. Please use the 1.9.1 version if your project runs on a previous Python version.
SQLAlchemy
The things you need to know compared to plain SQLAlchemy are:
The SQLAlchemy gives you access to the following things:
All the functions and classes from sqlalchemy and sqlalchemy.orm
All the functions from a preconfigured scoped session (called _session).
The ~SQLAlchemy.metadata and ~SQLAlchemy.engine
The methods SQLAlchemy.create_all and SQLAlchemy.drop_all to create and drop tables according to the models.
a Model baseclass that is a configured declarative base.
All the functions from the session are available directly in the class, so you can do db.add, db.commit, db.remove, etc.
The Model declarative base class behaves like a regular Python class but has a query attribute attached that can be used to query the model.
The Model class also auto generates _tablename__ attributes, if you don’t define one, based on the underscored and pluralized name of your classes.
You have to commit the session and configure your app to remove it at the end of the request.
Run the tests
You’ll need poetry to install de development dependencies.
poetry install
This command will automnatically create a virtual environment to run the project in. Read more in the Poetry site
To run the tests in your current Python version do:
pytest tests
To run them in every supported Python version do:
tox
It’s also neccesary to run the coverage report to make sure all lines of code are touch by the tests:
make coverage
Our test suite runs continuously on Travis CI with every update.
- copyright:
2013-2019 by Juan-Pablo Scaletti.
- license:
MIT, see LICENSE for more details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for sqla_wrapper-2.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 214b4fd63ae1ecff60db9d61a5bd8d0de8f61e785be2eab6ceca93abb5aaa918 |
|
MD5 | 40eb7b431de9e7a2dc7abdf246cb58ef |
|
BLAKE2b-256 | 5e0b8a56a8e87e529f48df188d223fb91f142460bddd49479fbb1ced665140bf |