Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE | "With-as" statement #55

Open
v1a0 opened this issue Nov 25, 2021 · 1 comment
Open

FEATURE | "With-as" statement #55

v1a0 opened this issue Nov 25, 2021 · 1 comment

Comments

@v1a0
Copy link
Owner

v1a0 commented Nov 25, 2021

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 added a commit that referenced this issue Jan 20, 2022
- Added feature to set optional sqlite3 connection parameters #57
- Added option to desable connetion with Database object init #56
- [IN PROGRESS] "With-as" statement #55
- Fixed BUG | Typing mistakes #51
- Docs update

Co-Authored-By: Phizilion <[email protected]>
@v1a0
Copy link
Owner Author

v1a0 commented Jan 22, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant