Base with a `model_id` property for SQLAlchemy models
Project description
SQLAlchemy-ModelID provides a base for SQLAlchemy models with a model_id
property. This conveniently distinguishes between models with the same primary key but from different tables.
Installation
$ pip install sqlalchemy-modelid
Quickstart
from sqlalchemy_modelid import ModelIdBase # standard session creation from sqlalchemy import create_engine, Column, Integer from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker, scoped_session engine = create_engine('sqlite:///:memory:') session_factory = sessionmaker(bind=engine) Session = scoped_session(session_factory) session = Session() Base = declarative_base() # subclass `ModelIdBase` to add a `model_id` property to any model class Model(ModelIdBase, Base): __tablename__ = 'model' id = Column(Integer, primary_key=True) # create the database Base.metadata.create_all(engine) # example my_model = Model() session.add(my_model) session.commit() my_model.model_id
Out:
model-1
Citation
@software{bowen2020sqlalchemy-modelid,
author = {Dillon Bowen},
title = {SQLAlchemy-ModelID},
url = {https://dsbowen.github.io/sqlalchemy-modelid/},
date = {2020-06-05},
}
License
Users must cite this package in any publications which use it.
It is licensed with the MIT License.
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.
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size sqlalchemy_modelid-0.0.3-py3-none-any.whl (3.3 kB) | File type Wheel | Python version py3 | Upload date | Hashes View |
Filename, size sqlalchemy-modelid-0.0.3.tar.gz (2.1 kB) | File type Source | Python version None | Upload date | Hashes View |
Close
Hashes for sqlalchemy_modelid-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc21a9e5d8e716ace24c883775e2061f74ce900c6a8201de1ce4b2094028532f |
|
MD5 | 3e2d18fce29744592d8ab7fdfda455bf |
|
BLAKE2-256 | 8b4cfb2da475c1c8954fecb1675d1f67658e8485567808a1f99df2a71fb16795 |