python-glowplug 0.2.1__py3-none-any.whl → 0.2.3__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.
- glowplug/mssql.py +17 -7
- {python_glowplug-0.2.1.dist-info → python_glowplug-0.2.3.dist-info}/METADATA +1 -1
- {python_glowplug-0.2.1.dist-info → python_glowplug-0.2.3.dist-info}/RECORD +5 -5
- {python_glowplug-0.2.1.dist-info → python_glowplug-0.2.3.dist-info}/LICENSE +0 -0
- {python_glowplug-0.2.1.dist-info → python_glowplug-0.2.3.dist-info}/WHEEL +0 -0
glowplug/mssql.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from sqlalchemy import text
|
|
1
2
|
from sqlalchemy.ext.asyncio import create_async_engine
|
|
2
3
|
from .base import DbDriver
|
|
3
4
|
|
|
@@ -7,14 +8,18 @@ class MsSqlDriver(DbDriver):
|
|
|
7
8
|
|
|
8
9
|
path: str
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
maintenance_db: str
|
|
12
|
+
|
|
13
|
+
def __init__(self, path: str, maintenance_db: str = "master", **kwargs):
|
|
11
14
|
"""Initialize the driver.
|
|
12
15
|
|
|
13
16
|
Args:
|
|
14
17
|
path (str): The path to connect to the database.
|
|
18
|
+
maintenance_db (str, optional): The database to connect to for maintenance. Defaults to "master".
|
|
15
19
|
"""
|
|
16
20
|
super().__init__(**kwargs)
|
|
17
21
|
self.path = path
|
|
22
|
+
self.maintenance_db = maintenance_db
|
|
18
23
|
|
|
19
24
|
async def exists(self) -> bool:
|
|
20
25
|
"""Check if the database exists."""
|
|
@@ -25,7 +30,8 @@ class MsSqlDriver(DbDriver):
|
|
|
25
30
|
async with engine.connect() as conn:
|
|
26
31
|
# Check if the database exists
|
|
27
32
|
result = await conn.execute(
|
|
28
|
-
|
|
33
|
+
text("SELECT name FROM sys.databases WHERE name = :db"),
|
|
34
|
+
{"db": database},
|
|
29
35
|
)
|
|
30
36
|
row = await result.fetchone()
|
|
31
37
|
return row is not None
|
|
@@ -36,9 +42,12 @@ class MsSqlDriver(DbDriver):
|
|
|
36
42
|
path, database = self._split_path()
|
|
37
43
|
# Connect to the database-less path
|
|
38
44
|
engine = create_async_engine(f"mssql+aioodbc://{path}")
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
45
|
+
# Create a raw connection with autocommit on.
|
|
46
|
+
# See: https://stackoverflow.com/a/42008664
|
|
47
|
+
conn = await engine.raw_connection()
|
|
48
|
+
conn.driver_connection.autocommit = True
|
|
49
|
+
await conn.driver_connection.execute(f"CREATE DATABASE {database}")
|
|
50
|
+
conn.close()
|
|
42
51
|
|
|
43
52
|
@property
|
|
44
53
|
def async_uri(self) -> str:
|
|
@@ -56,6 +65,7 @@ class MsSqlDriver(DbDriver):
|
|
|
56
65
|
head, tail = self.path.split("/", 1)
|
|
57
66
|
# Extract the database name from the tail
|
|
58
67
|
database, query = tail.split("?", 1)
|
|
59
|
-
# Re-join the query to the beginning of the path
|
|
60
|
-
|
|
68
|
+
# Re-join the query to the beginning of the path, with the
|
|
69
|
+
# name of the maintenance database.
|
|
70
|
+
path = f"{head}/{self.maintenance_db}?{query}"
|
|
61
71
|
return path, database
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
glowplug/__init__.py,sha256=vOFfxzKjr7djsdQcWi3x4IKMgcNHYSZgwyld5Xzezws,195
|
|
2
2
|
glowplug/base.py,sha256=LTBSCkYLO_xJZwDDjKA8ro9KSbMHdKNtWBAoNecJmGE,2845
|
|
3
|
-
glowplug/mssql.py,sha256=
|
|
3
|
+
glowplug/mssql.py,sha256=71yT-u0kp3RdZB2LzFBRcjT6nBWFBND7SIVlNgALXAU,2596
|
|
4
4
|
glowplug/pg.py,sha256=4Hw2WG33UzgYyJtWLv8QWZzHhzzsM34TyDuObtxvNmI,2600
|
|
5
5
|
glowplug/sqlite.py,sha256=DEJ8lYP8ZPemeGezTovs8WISGaVyUfwTIqiwMz3FPdU,1020
|
|
6
|
-
python_glowplug-0.2.
|
|
7
|
-
python_glowplug-0.2.
|
|
8
|
-
python_glowplug-0.2.
|
|
9
|
-
python_glowplug-0.2.
|
|
6
|
+
python_glowplug-0.2.3.dist-info/LICENSE,sha256=HvAzro26TfbigQ3ppmyagEGHIr_UtyQDfU8muTAqWFU,1060
|
|
7
|
+
python_glowplug-0.2.3.dist-info/METADATA,sha256=kd96CJnjwRu3auGYaAIngxZUdRmFw7WbVYK3pFU0Uq0,1257
|
|
8
|
+
python_glowplug-0.2.3.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
|
9
|
+
python_glowplug-0.2.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|