python-glowplug 0.3.10__py3-none-any.whl → 0.3.12__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,7 +11,7 @@ from ..driver.sqlite import SqliteDriver
11
11
  class SqliteSettings(BaseModel):
12
12
  """Settings for connecting to SQLite."""
13
13
 
14
- engine: Literal["sqlite"]
14
+ engine: Literal["sqlite"] = "sqlite"
15
15
  path: str = ":memory:"
16
16
 
17
17
  @cached_property
@@ -19,27 +19,35 @@ class SqliteSettings(BaseModel):
19
19
  return SqliteDriver(self.path)
20
20
 
21
21
 
22
+ PgSslMode = Literal["disable", "allow", "prefer", "require", "verify-ca", "verify-full"]
23
+
24
+
22
25
  class PostgresSettings(BaseModel):
23
26
  """Settings for connecting to Postgres."""
24
27
 
25
- engine: Literal["postgres"]
28
+ engine: Literal["postgres"] = "postgres"
26
29
  host: str = "localhost"
27
30
  port: int = 5432
28
31
  user: str = "postgres"
29
32
  password: str
30
33
  database: str
31
34
  maintenance_db: str | None = None
35
+ sslmode: PgSslMode | None = None
32
36
 
33
37
  @cached_property
34
38
  def driver(self) -> PostgresDriver:
35
39
  url = f"{self.user}:{self.password}@{self.host}:{self.port}/{self.database}"
40
+
41
+ if self.sslmode:
42
+ url += f"?sslmode={self.sslmode}"
43
+
36
44
  return PostgresDriver(url, maintenance_db=self.maintenance_db)
37
45
 
38
46
 
39
47
  class MsSqlSettings(BaseModel):
40
48
  """Settings for connecting to Microsoft SQL Server."""
41
49
 
42
- engine: Literal["mssql"]
50
+ engine: Literal["mssql"] = "mssql"
43
51
  odbc_driver: Literal["ODBC Driver 17 for SQL Server"] = (
44
52
  "ODBC Driver 17 for SQL Server"
45
53
  )
glowplug/driver/pg.py CHANGED
@@ -23,13 +23,26 @@ class PostgresDriver(DbDriver):
23
23
  self.url = url
24
24
  self.maintenance_db = maintenance_db
25
25
 
26
+ @classmethod
27
+ def _fix_query_for_asyncpg(cls, query: str) -> str:
28
+ """Fix the query string for asyncpg.
29
+
30
+ asyncpg uses "ssl" instead of "sslmode" for the query param.
31
+
32
+ See: https://github.com/MagicStack/asyncpg/issues/737
33
+
34
+ Need to call this method in any async context, sadly.
35
+ """
36
+ return query.replace("sslmode", "ssl")
37
+
26
38
  async def exists(self) -> bool:
27
39
  """Check if the database exists."""
28
40
  # Split the url on the last / to get base url & db name
29
- base_url, db_name = self._split_url()
41
+ base_url, db_name, query = self._split_url()
30
42
  # If a maintenance db is provided, use that to check if the db exists
43
+ query = self._fix_query_for_asyncpg(query)
31
44
  if self.maintenance_db:
32
- base_url = f"{base_url}/{self.maintenance_db}"
45
+ base_url = f"{base_url}/{self.maintenance_db}?{query}"
33
46
  engine = create_async_engine(
34
47
  f"postgresql+asyncpg://{base_url}", echo=self.debug
35
48
  )
@@ -45,10 +58,11 @@ class PostgresDriver(DbDriver):
45
58
 
46
59
  async def create(self) -> None:
47
60
  """Create the database."""
48
- base_url, db_name = self._split_url()
61
+ base_url, db_name, query = self._split_url()
49
62
  # If a maintenance db is provided, use that to create the db
63
+ query = self._fix_query_for_asyncpg(query)
50
64
  if self.maintenance_db:
51
- base_url = f"{base_url}/{self.maintenance_db}"
65
+ base_url = f"{base_url}/{self.maintenance_db}?{query}"
52
66
  engine = create_async_engine(
53
67
  f"postgresql+asyncpg://{base_url}",
54
68
  echo=self.debug,
@@ -61,14 +75,17 @@ class PostgresDriver(DbDriver):
61
75
  @property
62
76
  def async_uri(self) -> str:
63
77
  """Async connection string."""
64
- return f"postgresql+asyncpg://{self.url}"
78
+ url, db, query = self._split_url()
79
+ query = self._fix_query_for_asyncpg(query)
80
+ return f"postgresql+asyncpg://{url}/{db}?{query}"
65
81
 
66
82
  @property
67
83
  def sync_uri(self) -> str:
68
- """Sync connection stringe."""
84
+ """Sync connection string."""
69
85
  return f"postgresql://{self.url}"
70
86
 
71
- def _split_url(self) -> tuple[str, str]:
87
+ def _split_url(self) -> tuple[str, str, str]:
72
88
  """Split the url on the last / to get base url & db name."""
73
- url, db = self.url.rsplit("/", 1)
74
- return url, db
89
+ url, db_and_query = self.url.rsplit("/", 1)
90
+ db, _, query = db_and_query.partition("?")
91
+ return url, db, query
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-glowplug
3
- Version: 0.3.10
3
+ Version: 0.3.12
4
4
  Summary: A collection of utilities for common DB maintenance operations in SQLAlchemy
5
5
  Home-page: https://github.com/jnu/python-glowplug
6
6
  License: MIT
@@ -0,0 +1,11 @@
1
+ glowplug/__init__.py,sha256=VKKI-9C6KSlXwvisxTQFhVUUtQdwiNeV_g8wB5TVjM4,378
2
+ glowplug/config/__init__.py,sha256=DlZhXRYKjMZjyJiBcw2nv70BDiWVMmCEN8qacB7GRow,1863
3
+ glowplug/driver/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ glowplug/driver/base.py,sha256=_6nB66LbJa2E_DHbrOueUfT7CHtKiRccOQBIx-Ii43k,4174
5
+ glowplug/driver/mssql.py,sha256=e_0XuDRYSd-MwEtdjc4CM2dcnQC7mLw1jK-6G7K6__I,2813
6
+ glowplug/driver/pg.py,sha256=0M15-ckuQCRVe26nRBw3gmM8FwpqlVkpYH8PgpgJr1E,3341
7
+ glowplug/driver/sqlite.py,sha256=SPhZXYMu_OcdN2r7dr5YJA-3Jsd-deH7peMWYEzX_sE,1070
8
+ python_glowplug-0.3.12.dist-info/LICENSE,sha256=HvAzro26TfbigQ3ppmyagEGHIr_UtyQDfU8muTAqWFU,1060
9
+ python_glowplug-0.3.12.dist-info/METADATA,sha256=Qq2PztyE1JI26GEJB2xXjzT2CSoxfwOh9SDwdtkErXo,1495
10
+ python_glowplug-0.3.12.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
11
+ python_glowplug-0.3.12.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 1.8.1
2
+ Generator: poetry-core 1.9.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,11 +0,0 @@
1
- glowplug/__init__.py,sha256=VKKI-9C6KSlXwvisxTQFhVUUtQdwiNeV_g8wB5TVjM4,378
2
- glowplug/config/__init__.py,sha256=0v2Tqk8mJ3v_wRuifXP1-V4x7--xupBxxtrSt2CFqXs,1628
3
- glowplug/driver/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- glowplug/driver/base.py,sha256=_6nB66LbJa2E_DHbrOueUfT7CHtKiRccOQBIx-Ii43k,4174
5
- glowplug/driver/mssql.py,sha256=e_0XuDRYSd-MwEtdjc4CM2dcnQC7mLw1jK-6G7K6__I,2813
6
- glowplug/driver/pg.py,sha256=nBjo4gjjIuGtkPGMSrdq4essX19pyQeIXs6SlADVNm8,2661
7
- glowplug/driver/sqlite.py,sha256=SPhZXYMu_OcdN2r7dr5YJA-3Jsd-deH7peMWYEzX_sE,1070
8
- python_glowplug-0.3.10.dist-info/LICENSE,sha256=HvAzro26TfbigQ3ppmyagEGHIr_UtyQDfU8muTAqWFU,1060
9
- python_glowplug-0.3.10.dist-info/METADATA,sha256=HcIs0n3AH2eXIqNmwm9evdXb0_G4wbDUjjLgC8l5Iwg,1495
10
- python_glowplug-0.3.10.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
11
- python_glowplug-0.3.10.dist-info/RECORD,,