python-glowplug 0.2.4__tar.gz → 0.3.0__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-glowplug
3
- Version: 0.2.4
3
+ Version: 0.3.0
4
4
  Summary:
5
5
  Home-page: https://github.com/jnu/python-glowplug
6
6
  License: MIT
@@ -14,6 +14,8 @@ Classifier: Programming Language :: Python :: 3.10
14
14
  Classifier: Programming Language :: Python :: 3.11
15
15
  Classifier: Programming Language :: Python :: 3.12
16
16
  Requires-Dist: alembic (>=1.5,<2.0)
17
+ Requires-Dist: pydantic (>=2,<3)
18
+ Requires-Dist: pydantic-settings (>=2,<3)
17
19
  Requires-Dist: sqlalchemy (>=2,<3)
18
20
  Project-URL: Repository, https://github.com/jnu/python-glowplug
19
21
  Description-Content-Type: text/markdown
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "python-glowplug"
3
- version = "0.2.4"
3
+ version = "0.3.0"
4
4
  description = ""
5
5
  authors = ["Joe Nudell <jnudell@hks.harvard.edu>"]
6
6
  readme = "README.md"
@@ -14,6 +14,8 @@ packages = [
14
14
  python = "^3.9"
15
15
  sqlalchemy = "^2"
16
16
  alembic = "^1.5"
17
+ pydantic = "^2"
18
+ pydantic-settings = "^2"
17
19
 
18
20
 
19
21
  [tool.poetry.group.dev.dependencies]
@@ -0,0 +1,16 @@
1
+ from .driver.base import DbDriver
2
+ from .driver.pg import PostgresDriver
3
+ from .driver.sqlite import SqliteDriver
4
+ from .driver.mssql import MsSqlDriver
5
+
6
+ from .config import PostgresSettings, MsSqlSettings, SqliteSettings
7
+
8
+ __all__ = [
9
+ "DbDriver",
10
+ "PostgresDriver",
11
+ "SqliteDriver",
12
+ "MsSqlDriver",
13
+ "PostgresSettings",
14
+ "MsSqlSettings",
15
+ "SqliteSettings",
16
+ ]
@@ -0,0 +1,61 @@
1
+ from functools import cached_property
2
+ from typing import Literal
3
+
4
+ from pydantic import Field
5
+ from pydantic_settings import BaseSettings
6
+
7
+ from ..driver.mssql import MsSqlDriver
8
+ from ..driver.pg import PostgresDriver
9
+ from ..driver.sqlite import SqliteDriver
10
+
11
+
12
+ class SqliteSettings(BaseSettings):
13
+ """Settings for connecting to SQLite."""
14
+
15
+ engine: Literal["sqlite"]
16
+ path: str = Field(":memory:")
17
+
18
+ @cached_property
19
+ def driver(self) -> SqliteDriver:
20
+ return SqliteDriver(self.path)
21
+
22
+
23
+ class PostgresSettings(BaseSettings):
24
+ """Settings for connecting to Postgres."""
25
+
26
+ engine: Literal["postgres"]
27
+ host: str = Field("localhost")
28
+ port: int = Field(5432)
29
+ user: str = Field("postgres")
30
+ password: str
31
+ database: str
32
+ maintenance_db: str | None = Field(None)
33
+
34
+ @cached_property
35
+ def driver(self) -> PostgresDriver:
36
+ url = f"{self.user}:{self.password}@{self.host}:{self.port}/{self.database}"
37
+ return PostgresDriver(url, maintenance_db=self.maintenance_db)
38
+
39
+
40
+ class MsSqlSettings(BaseSettings):
41
+ """Settings for connecting to Microsoft SQL Server."""
42
+
43
+ engine: Literal["mssql"]
44
+ odbc_driver: Literal["ODBC Driver 17 for SQL Server"] = (
45
+ "ODBC Driver 17 for SQL Server"
46
+ )
47
+ host: str = Field("127.0.0.1")
48
+ port: int = Field(1433)
49
+ user: str = Field("sa")
50
+ password: str
51
+ database: str
52
+ maintenance_db: str = "master"
53
+
54
+ @cached_property
55
+ def driver(self):
56
+ odbc_driver = self.odbc_driver.replace(" ", "+")
57
+ path = (
58
+ f"{self.user}:{self.password}@{self.host}:{self.port}"
59
+ f"/{self.database}?driver={odbc_driver}"
60
+ )
61
+ return MsSqlDriver(path, maintenance_db=self.maintenance_db)
File without changes
@@ -45,9 +45,9 @@ class MsSqlDriver(DbDriver):
45
45
  # Need to run this with autocommit=True to avoid a transaction error
46
46
  # See: https://stackoverflow.com/a/42008664
47
47
  async with engine.connect() as conn:
48
- await conn.execute(
49
- text(f"CREATE DATABASE {database}").execution_options(autocommit=True)
50
- )
48
+ rc = await conn.get_raw_connection()
49
+ rc.driver_connection.autocommit = True
50
+ await conn.execute(text(f"CREATE DATABASE {database}"))
51
51
 
52
52
  @property
53
53
  def async_uri(self) -> str:
@@ -1,6 +0,0 @@
1
- from .base import DbDriver
2
- from .pg import PostgresDriver
3
- from .sqlite import SqliteDriver
4
- from .mssql import MsSqlDriver
5
-
6
- __all__ = ["DbDriver", "PostgresDriver", "SqliteDriver", "MsSqlDriver"]
File without changes