Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Allow creating database connection wrapper without a singleton #1120

Merged
merged 2 commits into from
Feb 20, 2025

Conversation

JAORMX
Copy link
Contributor

@JAORMX JAORMX commented Feb 20, 2025

The idea is that one would be able to pass the _no_singleton boolean
flag to the class and if so, the class would be returned without
creating a singleton.

This is handy for testing, since it would allow for several connections
to be open in parallel to different database paths, which indeed is a
testing scenario.

>>> from codegate.db.connection import DbCodeGate
>>> dbc = DbCodeGate(_no_singleton=True)
>>> print(dbc)
<codegate.db.connection.DbCodeGate object at 0x7f9a0f067650>
>>> dbc2 = DbCodeGate(_no_singleton=True)
>>> print(dbc2)
<codegate.db.connection.DbCodeGate object at 0x7f9a0daad1f0>
>>> dbc3 = DbCodeGate()
>>> print(dbc3)
<codegate.db.connection.DbCodeGate object at 0x7f9a0f065190>
>>> dbc4 = DbCodeGate()
>>> print(dbc4)
<codegate.db.connection.DbCodeGate object at 0x7f9a0f065190>

Signed-off-by: Juan Antonio Osorio ozz@stacklok.com

The idea is that one would be able to pass the `_no_singleton` boolean
flag to the class and if so, the class would be returned without
creating a singleton.

This is handy for testing, since it would allow for several connections
to be open in parallel to different database paths, which indeed is a
testing scenario.

```
>>> from codegate.db.connection import DbCodeGate
>>> dbc = DbCodeGate(_no_singleton=True)
>>> print(dbc)
<codegate.db.connection.DbCodeGate object at 0x7f9a0f067650>
>>> dbc2 = DbCodeGate(_no_singleton=True)
>>> print(dbc2)
<codegate.db.connection.DbCodeGate object at 0x7f9a0daad1f0>
>>> dbc3 = DbCodeGate()
>>> print(dbc3)
<codegate.db.connection.DbCodeGate object at 0x7f9a0f065190>
>>> dbc4 = DbCodeGate()
>>> print(dbc4)
<codegate.db.connection.DbCodeGate object at 0x7f9a0f065190>
```

Signed-off-by: Juan Antonio Osorio <ozz@stacklok.com>
Signed-off-by: Juan Antonio Osorio <ozz@stacklok.com>
@JAORMX JAORMX merged commit c1ca9e0 into main Feb 20, 2025
11 checks passed
@JAORMX JAORMX deleted the db-no-singleton branch February 20, 2025 09:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants