SQLA-wrapper

A friendly wrapper for SQLAlchemy.
Why?
SQLAlchemy is great, but can be difficult to set up. With SQLA-Wrapper you can quickly start like:
from sqla_wrapper import SQLAlchemy
db = SQLAlchemy('sqlite:///:memory:')
class User(db.Model):
__tablename__ "users"
id = db.Column(db.Integer, primary_key=True)
...
db.create_all()
todos = db.query(User.id, User.title).all()
instead of having to write something like:
# Who's going to remember all of this?
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker, Column, Integer
engine = create_engine('sqlite:///:memory:')
Session = sessionmaker(bind=engine)
session = Session()
Model = declarative_base()
class User(Model):
__tablename__ "users"
id = Column(Integer, primary_key=True)
...
Model.metadata.create_all(engine)
session = Session()
todos = session.query(User).all()
Installation
Install the package using Pypi:
python -m pip install sqla-wrapper
Basic usage
from sqla_wrapper import SQLAlchemy
db = SQLAlchemy('sqlite:///:memory:')
class User(db.Model):
__tablename__ "users"
id = db.Column(db.Integer, primary_key=True)
...
db.create_all()
db.add(User(...))
db.commit()
todos = db.query(User).all()
Compared to SQLAlchemy
Compared to plain SQLAlchemy, you need to know that:
The SQLAlchemy gives you access to the following things:
- All the functions and classes from
sqlalchemyandsqlalchemy.orm - All the functions from a preconfigured scoped session (called
_session). - The
~SQLAlchemy.metadataand~SQLAlchemy.engine - The methods
SQLAlchemy.create_allandSQLAlchemy.drop_allto create and drop tables according to the models. - A
Modelbaseclass that is a configured declarative base. This model has a few utility methods:
class Model(Object):
@classmethod
def exists(cls, **attrs):
"""Returns whether an object with these attributes exists."""
@classmethod
def create(cls, **attrs):
"""Create and persist a new record for the model."""
@classmethod
def create_or_first(cls, **attrs):
"""Tries to create a new record, and if it fails
because already exists, return the first it founds."""
@classmethod
def first(cls, **attrs):
"""Returns the first object found with these attributes."""
def save(self):
"""Saves the updated model to the current entity db and commits."""
def delete(self):
"""Removes the model from the current session and commits."""
This model class also generates a default repr for your models, based on their class names an primary keys.
Metadata
Release files for sqla-wrapper 4.200628
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sqla-wrapper-4.200628.tar.gz | 12.5 kB | Without provenance | Details for sqla-wrapper-4.200628.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sqla_wrapper-4.200628-py3-none-any.whl | Python 3 | none | any | Details for sqla_wrapper-4.200628-py3-none-any.whl |
Total release size: 25.2 kB
Release files / sqla-wrapper-4.200628.tar.gz
| Download URL | sqla-wrapper-4.200628.tar.gz |
|---|---|
| Size | 12.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e908fcfcefc79ccebb67972baa0b1069dcb67e34db0eca2f7d354ad605667f54
|
|
BLAKE2b-256 checksum How to use checksums |
dc4397b948717b89df0a6452265108d48898084aa6b85cfedef7f2e5f9d72d81
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.0
|
Release files / sqla_wrapper-4.200628-py3-none-any.whl
| Download URL | sqla_wrapper-4.200628-py3-none-any.whl |
|---|---|
| Size | 12.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
053a61c6abdd22446913ff28ed7edabe5ce18f88a38cb6f1b19e6c91a96e42f6
|
|
BLAKE2b-256 checksum How to use checksums |
488b61aff284b49308355fb9ddd1651e4173146b496a3f7a0bd1ebc65e43fb79
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.0
|
Security for sqla-wrapper 4.200628
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.