Skip to main content

This fork has been updated to work with SQLAlchemy 3.

Brings transparent soft delete to SQLAlchemy ORM. This branch has been modified to add the with_deleted() and restore() methods for interacting with soft-deleted resources.

Build Status

Installation

pip install sqla-paranoid3

Usage

from paranoid.models import (
    Model,
    Query,
    Session,
)

class User(Model):
    __tablename__ = 'user'
    __softdelete__ = True

    id = Column(Integer, primary_key=True)
    name = Column(String)


engine = create_engine('sqlite://')
session = sessionmaker(engine, class_=Session, query_cls=Query)()

session.query(User)

# retrieve a user that has not been deleted (assuming ID is 1)
user = User.query.get(1)

# soft delete the user
user.delete()

# query for a soft deleted user
user = User.query.with_deleted().get(1)
# or
user = User.query.with_deleted().filter_by(id=1).first()

# restore the user (undo soft delete)
user.restore()

# save the changes
session.add(user)
session.commit()

# hard delete the user
session.delete(user, hard=True)
session.commit()

Flask

Paranoid3 comes with a ready to use Flask extension built on top of Flask-SQLAlchemy:

from paranoid.flask import SQLAlchemy


db = SQLAlchemy(app)
# or you can use the factory style of initialisation
db = SQLAlchemy()
db.init_app(app)

Model = db.Model


class User(Model):
    __softdelete__ = True

    id = Column(Integer, primary_key=True)
    name = Column(String)

User.query

Metadata

Release files for sqla-paranoid3 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sqla-paranoid3 0.1.4
File Size Uploaded
sqla_paranoid3-0.1.4.tar.gz 5.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sqla-paranoid3 0.1.4
File Interpreter ABI Platform
sqla_paranoid3-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 10.8 kB

Release files / sqla_paranoid3-0.1.4.tar.gz

Download URL sqla_paranoid3-0.1.4.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
354bc6a3d9c4af60b091c783e986784bd870c1f64c5dcc0679a661304e72ccce
BLAKE2b-256 checksum
How to use checksums
aba7b4e5eab424d6fc1e75466a7c6a03689c4a9cc0b87910444b039aa69fed8b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release files / sqla_paranoid3-0.1.4-py3-none-any.whl

Download URL sqla_paranoid3-0.1.4-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
14b979fdcf5d6e683df4148cca59da377a8b13e28785c069fef2e755cf93ef05
BLAKE2b-256 checksum
How to use checksums
f487d6eae9dce00dd9517e9aa2c1b3fbc606ee8016f319a6c84ca71bdcc0037b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page