]> git.jsancho.org Git - datasette-connectors.git/commitdiff
Instantiate connector inside cursors
authorJavier Sancho <jsf@jsancho.org>
Thu, 8 Oct 2020 07:52:25 +0000 (09:52 +0200)
committerJavier Sancho <jsf@jsancho.org>
Thu, 8 Oct 2020 07:52:25 +0000 (09:52 +0200)
datasette_connectors/__init__.py
datasette_connectors/connection.py
datasette_connectors/connectors.py
datasette_connectors/cursor.py
tests/fixtures.py

index 834e398f662cac1022aee137d479de7e8a10b098..78bb482898241fe9668c622130aa2726810ba8d1 100644 (file)
@@ -1,2 +1,3 @@
 from .connectors import Connector
+from .connection import Connection
 from .cursor import OperationalError
index 776150661b3a09101b68c08282edad9e5eff1f4f..b9081f4d0210d8729a4c07172cb98c4abff5242b 100644 (file)
@@ -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)
index bdba2158c3fb958c6b4aadbfb3c2aaa255ce16f5..0fa4b3d17eb60ae7a85061250c2d55eef725c840 100644 (file)
@@ -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):
         """
index 6facf548bd3460bef5c7393ced470b062093d9b6..166c84eb9e5f7a7c72e83166149ff89a2707df91 100644 (file)
@@ -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 = ()
 
index f6f695da316234e4e3113a3504cc1e049ff355a7..a93c2afcdd0d52aa99835444366bcdefb2a4b5c2 100644 (file)
@@ -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