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 | Add option to desable connetion with Database object init #56

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

FEATURE | Add option to desable connetion with Database object init #56

v1a0 opened this issue Nov 25, 2021 · 1 comment

Comments

@v1a0
Copy link
Owner

v1a0 commented Nov 25, 2021

Add new parameter into init of Database classes, something like auto_conn or just connect or init_conn, which means "connect immediately" with object initialization. After adding "with-as" statement support it might be reasonable to creating object without creation connection. This parameter have to be True by default.

from sqllex import SQLite3x

# might look like this
db = SQLite3x(path='/path/database.db', init_conn=False)

# or this
db = SQLite3x(path='/path/database.db', auto_conn=False)

# or maybe even
db = SQLite3x(path='/path/database.db', without_conn=True)

In code:

class SQLite3x(ABDatabase):

    def __init__(self,
                 path: PathType = "sql3x.db",
                 init_conn: bool = True,
                 template: DBTemplateType = None):


        ... # another routine

        self.__connection = None  # init connection
        
        if init_conn:       # <== HERE
            self.connect()  # creating connection with db
        
        ... # yet another routine

Welcome you to join this discussion! How should we name this parameter?

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

Added since v0.2.0.4

db = SQLite3x(
    path='database.db',
    init_connection=False    #  Disable connection initialization within database class object
)

db.connect(check_same_thread=False)    # example

print(db.tables_names)

db.disconnect()

@v1a0 v1a0 closed this as completed Jan 22, 2022
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