Skip to main content

select/delete wrapper for SQLAlchemy Asyncio

Project description

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Description: SQLAlchemy Sugar: sugar syntax of select/delete functions of SQLAlchemy, especially asyncio.

In SQLAlchemy document , the original Asyncio API of SQLAlchemy is like below:

engine = create_async_engine("sqlite:///:memory:")

async with AsyncSession(engine) as session:
    stmt = select(A).options(selectinload(A.bs))
    result = await session.execute(stmt)
    for a1 in result.scalars():
        print(a1)

    result = await session.execute(select(A).order_by(A.id))
    a1 = result.scalars().first()
    a1.data = "new data"
    await session.commit()

but with this wrapper:

from sqlalchemy_sugar import select

engine = create_async_engine("sqlite:///:memory:")

async with AsyncSession(engine) as session:
    for a1 in await select(A).options(selectinload(A.bs)).scalar(session):
        print(a1)

    a1 = await select(A).order_by(A.id).first(session)
    a1.data = "new data"
    await session.commit()

And also, deleting row is like below:

async with AsyncSession(engine) as session:
    stmt = delete(A).filter_by(data="a2")
    await session.execute(stmt)

but with this wrapper:

from sqlalchemy_sugar import delete

async with AsyncSession(engine) as session:
    await delete(A).filter_by(data="a2").execute(session)

SQLAlchemy document: https://docs.sqlalchemy.org/en/14/orm/extensions/asyncio.html#sqlalchemy.ext.asyncio.AsyncScalarResult

Platform: UNKNOWN Classifier: Development Status :: 3 - Alpha Classifier: Intended Audience :: Developers Classifier: Topic :: Software Development :: Build Tools Classifier: License :: OSI Approved :: MIT License Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.8 Classifier: Programming Language :: Python :: 3.9 Classifier: Programming Language :: Python :: 3.10

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

sqlalchemy-sugar-0.1.1.tar.gz (3.4 kB view hashes)

Uploaded Source

Built Distribution

sqlalchemy_sugar-0.1.1-py3-none-any.whl (5.0 kB view hashes)

Uploaded Python 3

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