sqllex icon indicating copy to clipboard operation
sqllex copied to clipboard

FEATURE | "With-as" statement

Open v1a0 opened this issue 4 years ago • 1 comments

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"

v1a0 avatar Nov 25 '21 09:11 v1a0

After a few tries I'm just not sure is this really so necessary and what is the bes way to code it 😅.

v1a0 avatar Jan 22 '22 08:01 v1a0