Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions registry/sql-registry/registry/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
import logging
import threading
import os

# Checks if the platform is Max (Darwin).
# If so, imports _scproxy that is necessary for pymssql to work on MacOS
import platform
if platform.system().lower().startswith('dar'):
import _scproxy

import pymssql


Expand Down Expand Up @@ -53,7 +60,7 @@ def __init__(self, params):
self.params = params
self.make_connection()
self.mutex = threading.Lock()

def make_connection(self):
self.conn = pymssql.connect(**self.params)

Expand Down Expand Up @@ -85,10 +92,10 @@ def transaction(self):
"""
Start a transaction so we can run multiple SQL in one batch.
User should use `with` with the returned value, look into db_registry.py for more real usage.

NOTE: `self.query` and `self.execute` will use a different MSSQL connection so any change made
in this transaction will *not* be visible in these calls.

The minimal implementation could look like this if the underlying engine doesn't support transaction.
```
@contextmanager
Expand Down Expand Up @@ -125,4 +132,4 @@ def connect(*args, **kargs):
ret = p.connect(*args, **kargs)
if ret is not None:
return ret
raise RuntimeError("Cannot connect to database")
raise RuntimeError("Cannot connect to database")