Skip to content

Commit

Permalink
Make sdssdb.use_psycopg3 a boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Sep 3, 2024
1 parent 906ab62 commit 7148123
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,8 @@ sdss = ["sdsstools"]
sqla = ["sqlalchemy"]
peewee = ["peewee", "playhouse"]

[tool.ruff.format]
preview = true

[tool.coverage.run]
branch = true
2 changes: 1 addition & 1 deletion python/sdssdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
config = get_config(NAME)

autoconnect = True
use_psycopg3 = os.environ.get("SDSSDB_PSYCOPG3", "false")
use_psycopg3 = os.environ.get("SDSSDB_PSYCOPG3", "false").lower() in ["true", "1"]


from .connection import PeeweeDatabaseConnection # noqa
Expand Down
4 changes: 2 additions & 2 deletions python/sdssdb/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
__all__ = ["DatabaseConnection", "PeeweeDatabaseConnection", "SQLADatabaseConnection"]


if use_psycopg3.lower() in ["true", "1"]:
if use_psycopg3 is True:
try:
import psycopg # noqa
from playhouse.psycopg3_ext import Psycopg3Database as PostgresqlDatabase
Expand Down Expand Up @@ -75,7 +75,7 @@ def get_database_uri(
else:
auth: str = f"{user}:{password}@"

host_port: str = f"{host or ''}" if port is None else f"{host or ''}:{port}"
host_port: str = f"{host or ""}" if port is None else f"{host or ""}:{port}"

if auth == "" and host_port == "":
return f"postgresql://{dbname}"
Expand Down

0 comments on commit 7148123

Please sign in to comment.