From 716ff0016ebb03dbef77fd4a9c6b2f8f9781cb58 Mon Sep 17 00:00:00 2001 From: Javier Sancho Date: Thu, 8 Oct 2020 09:52:25 +0200 Subject: [PATCH] Instantiate connector inside cursors --- datasette_connectors/__init__.py | 1 + datasette_connectors/connection.py | 4 ++-- datasette_connectors/connectors.py | 8 ++++++-- datasette_connectors/cursor.py | 2 +- tests/fixtures.py | 2 +- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/datasette_connectors/__init__.py b/datasette_connectors/__init__.py index 834e398..78bb482 100644 --- a/datasette_connectors/__init__.py +++ b/datasette_connectors/__init__.py @@ -1,2 +1,3 @@ from .connectors import Connector +from .connection import Connection from .cursor import OperationalError diff --git a/datasette_connectors/connection.py b/datasette_connectors/connection.py index 7761506..b9081f4 100644 --- a/datasette_connectors/connection.py +++ b/datasette_connectors/connection.py @@ -2,9 +2,9 @@ from .cursor import Cursor class Connection: - def __init__(self, path, connector): + def __init__(self, path, connector_class): self.path = path - self.connector = connector + self.connector_class = connector_class def execute(self, *args, **kwargs): cursor = Cursor(self) diff --git a/datasette_connectors/connectors.py b/datasette_connectors/connectors.py index bdba215..0fa4b3d 100644 --- a/datasette_connectors/connectors.py +++ b/datasette_connectors/connectors.py @@ -32,8 +32,12 @@ class Connector: connector_type = None connection_class = Connection - def connect(self, path): - return self.connection_class(path, self) + @classmethod + def connect(cls, path): + return cls.connection_class(path, cls) + + def __init__(self, conn): + self.conn = conn def table_names(self): """ diff --git a/datasette_connectors/cursor.py b/datasette_connectors/cursor.py index 6facf54..166c84e 100644 --- a/datasette_connectors/cursor.py +++ b/datasette_connectors/cursor.py @@ -14,7 +14,7 @@ class Cursor: def __init__(self, conn): self.conn = conn - self.connector = conn.connector + self.connector = conn.connector_class(conn) self.rows = [] self.description = () diff --git a/tests/fixtures.py b/tests/fixtures.py index f6f695d..a93c2af 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -1,7 +1,7 @@ from datasette_connectors import monkey; monkey.patch_datasette() from datasette_connectors.connectors import ConnectorList from .dummy import DummyConnector -ConnectorList.add_connector('dummy', DummyConnector()) +ConnectorList.add_connector('dummy', DummyConnector) from datasette.app import Datasette from datasette.utils.testing import TestClient -- 2.39.5