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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file sqlalchemy-sugar-0.1.1.tar.gz.

File metadata

  • Download URL: sqlalchemy-sugar-0.1.1.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.23.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.5

File hashes

Hashes for sqlalchemy-sugar-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b28276b46324ff78e2702c96a8127080cb28746dfeab40be7cfa6f18ed5592af
MD5 5a06a8a7b44a035ef8bea09d5dfa8c01
BLAKE2b-256 80b10d6ad982d899b43046d20f790f1a1c3da434b7a36e125b7cdffae2af6f99

See more details on using hashes here.

File details

Details for the file sqlalchemy_sugar-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: sqlalchemy_sugar-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.23.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.5

File hashes

Hashes for sqlalchemy_sugar-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 24e1e3e3b21e0130fd2a54144eeb139ef0b99325c157b73a6354f3752c87e87a
MD5 2801eb84da7336a3ed39be03064f4f9e
BLAKE2b-256 b6b1377248f35c37a9f5395e44b6ef0cb40e536568572b2ef331b8b8e5f976a0

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