Skip to main content

SQLAlchemy soft delete

Project description

sqla-softdelete

Simple soft delete for SQLAlchemy ORM

How to install

  pip install -r sqla-softdelete

How to use

To make your SQLAlchemy model (entity) support just inherit it from SoftDeleteMixin. For instance:

from sqla_softdelete import SoftDeleteMixin


class Account(SoftDeleteMixin, Base):
    __tablename__ = 'account'

    id = sa.Column(sa.Integer, primary_key=True, autoincrement=True)
    name = sa.Column(sa.Text, nullable=False)
    email = sa.Column(sa.String(128), nullable=False, index=True)

    def __init__(self, name: str = '', email: str = '', phone: str = ''):
        self.name = name
        self.email = email
        self.phone = phone

    def __repr__(self):
        return f'Account(id={self.id}, name={self.name}, email={self.email})'

    def __str__(self):
        return f'{self.name}: {self.email})'

All set now.

    account = Account(name='account')
    
    Session.add(account)
    Session.flush()
    
    account.delete()
    Session.expire(account)

    actual_accounts = dbsession.query(Account).all() 
    print(f'Actual accounts: {actual_accounts}')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sqla_softdelete-1.2.tar.gz (2.5 kB view details)

Uploaded Source

File details

Details for the file sqla_softdelete-1.2.tar.gz.

File metadata

  • Download URL: sqla_softdelete-1.2.tar.gz
  • Upload date:
  • Size: 2.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.0

File hashes

Hashes for sqla_softdelete-1.2.tar.gz
Algorithm Hash digest
SHA256 e43ee9b1fed1870ed303bdbf819289d440f5439d75caa08d8d6f3669c7ea9cce
MD5 dfb37a25313e87555bd6d0ce63a06c5a
BLAKE2b-256 d113d591ac1b4339614687641b45fdeb83171b550881059f29f5ab13d5b42ae9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page