SQLAlchemy-OrderingItem provides an OrderingItem base for children of orderinglist relationships. Children of orderinglist relationships will exhibit more intuitive behavior when setting their parent attribute.
Installation
$ pip install sqlalchemy-orderingitem
Quickstart
from sqlalchemy_orderingitem import OrderingItem
from sqlalchemy import Column, ForeignKey, Integer, create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.ext.orderinglist import ordering_list
from sqlalchemy.orm import sessionmaker, relationship
# standard session creation
engine = create_engine('sqlite:///:memory:')
Session = sessionmaker(bind=engine)
session = Session()
Base = declarative_base()
class Parent(Base):
__tablename__ = 'parent'
id = Column(Integer, primary_key=True)
# declare orderinglist relationships
children = relationship(
'Child',
backref='parent',
order_by='Child.index',
collection_class=ordering_list('index')
)
# subclass OrderingItem for children of orderinglist relationships
class Child(OrderingItem, Base):
__tablename__ = 'child'
id = Column(Integer, primary_key=True)
parent_id = Column(Integer, ForeignKey('parent.id'))
index = Column(Integer)
# create database tables and instantiate parent and child
Base.metadata.create_all(engine)
parent = Parent()
child = Child()
session.add_all([parent, child])
session.commit()
# example 1: setting a child's parent attribute to Parent object
# we expect the child's index to be 0
child.parent = parent
print(child.index)
# example 2: setting a child's parent attribute to None
# we expect the child's index to be None
parent.children = [c]
child.parent = None
print(child.index)
Out:
0
None
If Child did not subclass OrderingItem, we would observe the following unintuitive output:
None
0
Citation
@software{bowen2020sqlalchemy-orderingitem,
author = {Dillon Bowen},
title = {SQLAlchemy-OrderingItem},
url = {https://dsbowen.github.io/sqlalchemy-orderingitem/},
date = {2020-06-05},
}
License
Users must cite this package in any publications which use it.
It is licensed with the MIT License.
Metadata
Release files for sqlalchemy-orderingitem 0.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sqlalchemy-orderingitem-0.0.5.tar.gz | 3.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sqlalchemy_orderingitem-0.0.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.3 kB
Release files / sqlalchemy-orderingitem-0.0.5.tar.gz
| Download URL | sqlalchemy-orderingitem-0.0.5.tar.gz |
|---|---|
| Size | 3.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
77de49484d3161fcf5905b3ad1213d4d34032def97725a3434f26776e20bfc82
|
|
BLAKE2b-256 checksum How to use checksums |
6b2a894c8a08de38a0619d5b7f95cdd81671f8824e9826927c345ce8f285539e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.3.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.8
|
Release files / sqlalchemy_orderingitem-0.0.5-py3-none-any.whl
| Download URL | sqlalchemy_orderingitem-0.0.5-py3-none-any.whl |
|---|---|
| Size | 4.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
da2f441b1179f75cc7c042c647c0f7d2527232fdfd700abb3afd1d52ac2e5fe0
|
|
BLAKE2b-256 checksum How to use checksums |
d6183bbbcdbf5fa0afb6ae304f2b784911cead05da8dc4c595ae24f2a438239e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.3.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.8
|