Skip to content

Commit 9bd6243

Browse files
committed
Migrate to class based dbapi
1 parent dd91359 commit 9bd6243

File tree

4 files changed

+26
-24
lines changed

4 files changed

+26
-24
lines changed

test_dbapi/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55

66
@pytest.fixture(scope="module")
77
def connection():
8-
conn = dbapi.connect(host="localhost", port="2136", database="/local")
8+
conn = dbapi.YdbDBApi().connect(host="localhost", port="2136", database="/local")
99
yield conn
1010
conn.close()

test_dbapi/test_dbapi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def test_cursor_raw_query(connection):
6969

7070
def test_errors(connection):
7171
with pytest.raises(dbapi.InterfaceError):
72-
dbapi.connect("localhost:2136", database="/local666")
72+
dbapi.YdbDBApi().connect("localhost:2136", database="/local666")
7373

7474
cur = connection.cursor()
7575

ydb_sqlalchemy/dbapi/__init__.py

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,27 @@
1313
NotSupportedError,
1414
)
1515

16-
apilevel = "1.0"
16+
class YdbDBApi:
17+
def __init__(self):
18+
self.paramstyle = "pyformat"
19+
self.threadsafety = 0
20+
self.apilevel = "1.0"
21+
self._init_dbapi_attributes()
22+
23+
def _init_dbapi_attributes(self):
24+
for name, value in {
25+
"Warning": Warning,
26+
"Error": Error,
27+
"InterfaceError": InterfaceError,
28+
"DatabaseError": DatabaseError,
29+
"DataError": DataError,
30+
"OperationalError": OperationalError,
31+
"IntegrityError": IntegrityError,
32+
"InternalError": InternalError,
33+
"ProgrammingError": ProgrammingError,
34+
"NotSupportedError": NotSupportedError,
35+
}.items():
36+
setattr(self, name, value)
1737

18-
threadsafety = 0
19-
20-
paramstyle = "pyformat"
21-
22-
errors = (
23-
Warning,
24-
Error,
25-
InterfaceError,
26-
DatabaseError,
27-
DataError,
28-
OperationalError,
29-
IntegrityError,
30-
InternalError,
31-
ProgrammingError,
32-
NotSupportedError,
33-
)
34-
35-
36-
def connect(*args, **kwargs):
37-
return Connection(*args, **kwargs)
38+
def connect(self, *args, **kwargs):
39+
return Connection(*args, **kwargs)

ydb_sqlalchemy/sqlalchemy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ class YqlDialect(StrCompileDialect):
542542

543543
@classmethod
544544
def import_dbapi(cls: Any):
545-
return dbapi
545+
return dbapi.YdbDBApi()
546546

547547
def _describe_table(self, connection, table_name, schema=None):
548548
if schema is not None:

0 commit comments

Comments
 (0)