Skip to main content

SQLAlchemy provider for init-provider

Project description

init-provider-sqlalchemy

Database provider implemented using init-provider.

PyPI - Version PyPI - Python Version PyPI - Status PyPI - License

Table of Contents

Quick start

Below is a full runnable example that uses everything in this library.

import asyncio
import os
from init_provider import setup, dispose
from init_provider_sqlalchemy import Database
from sqlalchemy import text


@setup
def configure() -> None:
    os.environ["DATABASE_ENGINE_URL"] = "sqlite:///example.db"
    os.environ["DATABASE_ENGINE_ASYNC_URL"] = "sqlite+aiosqlite:///example.db"
    os.environ["DATABASE_ENGINE_ECHO"] = "False"
    os.environ["DATABASE_SESSION_EXPIRE_ON_COMMIT"] = "False"


@dispose
def cleanup() -> None:
    os.unlink("example.db")


def sync_test() -> None:
    with Database.session() as session:
        result = session.execute(text("SELECT 1"))
        print(result.scalar())


async def async_test() -> None:
    async with Database.async_session() as session:
        result = await session.execute(text("SELECT 1"))
        print(result.scalar())


async def main() -> None:
    sync_test()
    await async_test()


if __name__ == "__main__":
    asyncio.run(main())

Installation

Using pip:

pip install init-provider-sqlalchemy

Using uv:

uv add init-provider-sqlalchemy

License

Licensed under the Apache-2.0 License.

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

init_provider_sqlalchemy-0.1.1.tar.gz (62.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

init_provider_sqlalchemy-0.1.1-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file init_provider_sqlalchemy-0.1.1.tar.gz.

File metadata

File hashes

Hashes for init_provider_sqlalchemy-0.1.1.tar.gz
Algorithm Hash digest
SHA256 039224fd7aa3cedb3ae6476ee56358538e7609e581757c1acd27e81bf384e0e5
MD5 5c7c2692cc8336ca37623295fdecb59c
BLAKE2b-256 decf372585c9c0609a2d73232bd5b759d22c3ade816a7fe170e29791b20c0632

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for init_provider_sqlalchemy-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d7d653125942b65b3ff8d628b9d6d8227e3858191126da16a02581ebfd410434
MD5 8ca9e5b858e189aeb5e6d0a8e8dd3f46
BLAKE2b-256 e3860b40077a82d1af15d1b0f5b69ec92e3bc040d1befbdd45fbe0efec2a691f

See more details on using hashes here.

Supported by

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