python-glowplug 0.2.2__tar.gz → 0.2.4__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.2
3
+ Version: 0.2.4
4
4
  Summary:
5
5
  Home-page: https://github.com/jnu/python-glowplug
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "python-glowplug"
3
- version = "0.2.2"
3
+ version = "0.2.4"
4
4
  description = ""
5
5
  authors = ["Joe Nudell <jnudell@hks.harvard.edu>"]
6
6
  readme = "README.md"
@@ -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
 
@@ -29,9 +30,10 @@ class MsSqlDriver(DbDriver):
29
30
  async with engine.connect() as conn:
30
31
  # Check if the database exists
31
32
  result = await conn.execute(
32
- f"SELECT name FROM sys.databases WHERE name = '{database}'"
33
+ text("SELECT name FROM sys.databases WHERE name = :db"),
34
+ {"db": database},
33
35
  )
34
- row = await result.fetchone()
36
+ row = result.fetchone()
35
37
  return row is not None
36
38
 
37
39
  async def create(self) -> None:
@@ -40,9 +42,12 @@ class MsSqlDriver(DbDriver):
40
42
  path, database = self._split_path()
41
43
  # Connect to the database-less path
42
44
  engine = create_async_engine(f"mssql+aioodbc://{path}")
45
+ # Need to run this with autocommit=True to avoid a transaction error
46
+ # See: https://stackoverflow.com/a/42008664
43
47
  async with engine.connect() as conn:
44
- # Create the database
45
- await conn.execute(f"CREATE DATABASE {database}")
48
+ await conn.execute(
49
+ text(f"CREATE DATABASE {database}").execution_options(autocommit=True)
50
+ )
46
51
 
47
52
  @property
48
53
  def async_uri(self) -> str:
File without changes