Metadata-Version: 2.1
Name: SQLAlchemy-DLock
Version: 0.1.1
Summary: A distributed lock implementation based on SQLAlchemy
Home-page: https://github.com/tanbro/sqlalchemy-dlock
Author: liu xue yan
Author-email: liu_xue_yan@foxmail.com
License: UNKNOWN
Description: # SQLAlchemy-DLock
        
        Distributed lock based on Database and SQLAlchemy.
        
        It currently supports locks of:
        
        - MySQL: <https://dev.mysql.com/doc/refman/8.0/en/locking-functions.html>
        - PostgreSQL: <https://www.postgresql.org/docs/current/explicit-locking.html#ADVISORY-LOCKS>
        
        It's not stable and **DO NOT** use it in production.
        
        ## Usages
        
        Basic:
        
        ```python
        from sqlalchemy import create_engine
        from sqlalchemy_dlock import make_session_level_lock as sd_lock
        
        # ...
        
        lock_key = 'user/001'
        
        # ...
        
        engine = create_engine()
        
        # ...
        
        with engine.connect() as conn:
            with sd_lock(conn, lock_key):
                # do sth...
                pass
        # ...
        ```
        
        Made from SQLAlchemy's Session:
        
        ```python
        # ...
        
        lock_key = 'user/001'
        
        # ...
        
        with Session.bind.connect() as conn:
            with sd_lock(conn, lock_key):
                # ...
                user = Session.query(User).filter(id='001').one()
                user.password = new_pass
                Session.commit()
                # ...
        # ...
        ```
        
        Or, if the `session` has no `commit`, `rollback`, `close`:
        
        ```python
        # ...
        
        lock_key = 'user/001'
        
        # ...
        
        with sd_lock(Session.connection(), lock_key):
            # ...
            user = Session.query(User).filter(id='001').one()
            password = user.password
            # ...
        # ...
        ```
        
        # CHANGELOG
        
        ## v0.1.1
        
        - An early version, maybe not stable enough.
        - Replace black2b with crc64-iso in PostgreSQL key convert function
        
        # AUTHORS
        
        * Liu Xue Yan (<liu_xue_yan@foxmail.com>)
        
          [![liu_xue_yan@foxmail.com](https://www.gravatar.com/avatar/049d2fae1fd2df6439e87d1383d0276b)](mailto:liu_xue_yan@foxmail.com)
        
Platform: UNKNOWN
Description-Content-Type: text/markdown
