Skip to content

FEATURE | "With-as" statement  #55

@v1a0

Description

@v1a0

Add __enter__ and __exit__ methods for db, table and column classes to make possible nice temporary connection.

from sqllex import SQLite3x

with SQLite3x('/path/database.db') as db:
    # creting connection
    db.insert(...)
    ...
    # commit and disconnection

with SQLite3x('/path/database.db').connection as conn:
    # creting connection
    # doing things (idk)
    ...
    # commit and disconnection

with SQLite3x('/path/database.db')['table'] as table:
    # creting connection
    table.insert(...)
    table.select(...)
    # commit and disconnection

with SQLite3x('/path/database.db')['table']['column'] as column:
    # creting connection
    column.find(...)
    # commit and disconnection (if necessary)

P.S.: For developers, stackoverflow "Implementing use of 'with object as o' in custom class in python"

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