Skip to content

Enabling Non-Legacy SQLite Transactional Modes #24

@hyperknot

Description

@hyperknot

Hi, SQLAlchemy has this topic on the subject:

Enabling Non-Legacy SQLite Transactional Modes with the sqlite3 or aiosqlite driver

Can you explain how can this be integrated with FastSQLA?

In the current version I found the only way to pass anything DB related is via the os.environ trick. This is a bit weird, as I export a string I prepared into an env var, just so that FastSQLA can read it again.

This is good for the basic URL, but how can I pass connect_args={"autocommit": False} into it?

This is how my code looks.

from fastsqla import lifespan

sqlalchemy_url_async = f'sqlite+aiosqlite:///{sqlite_path}?check_same_thread=false'

os.environ['SQLALCHEMY_URL'] = sqlalchemy_url_async

app = FastAPI(
    lifespan=lifespan,
)

Also, I believe check_same_thread is not required anymore, as it's the default:
https://docs.sqlalchemy.org/en/20/dialects/sqlite.html#threading-pooling-behavior

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions