From 1ee613dff6056bf26d67d47b5d509e53495b7fc3 Mon Sep 17 00:00:00 2001 From: John Finberg Date: Tue, 20 Aug 2024 22:48:18 -0700 Subject: [PATCH] refactor: rename interface classes --- fortress_sdk_python/database.py | 24 ++++++++++-------------- fortress_sdk_python/fortress.py | 6 +++--- fortress_sdk_python/postgres.py | 8 ++++---- pyproject.toml | 2 +- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/fortress_sdk_python/database.py b/fortress_sdk_python/database.py index a65d51d..6459158 100644 --- a/fortress_sdk_python/database.py +++ b/fortress_sdk_python/database.py @@ -1,9 +1,9 @@ from typing import Any -class CursorInterface: +class Cursor: def __init__(self, cursor): - self.__cursor: "CursorInterface" = NotImplementedError + self.__cursor: "Cursor" = NotImplementedError self.arraysize: int = NotImplementedError @property @@ -18,12 +18,10 @@ def rowcount(self) -> int: def lastrowid(self) -> int | None: raise NotImplementedError - def execute(self, sql: str, parameters: tuple[Any] = ...) -> "CursorInterface": + def execute(self, sql: str, parameters: tuple[Any] = ...) -> "Cursor": raise NotImplementedError - def executemany( - self, sql: str, parameters: list[tuple[Any]] = ... - ) -> "CursorInterface": + def executemany(self, sql: str, parameters: list[tuple[Any]] = ...) -> "Cursor": raise NotImplementedError def fetchone(self) -> tuple[Any] | None: @@ -35,14 +33,14 @@ def fetchmany(self, size: int = ...) -> list[tuple[Any, ...]]: def fetchall(self) -> list[tuple[Any]]: raise NotImplementedError - def __enter__(self) -> "CursorInterface": + def __enter__(self) -> "Cursor": raise NotImplementedError def __exit__(self, exc_type, exc_value, traceback): raise NotImplementedError -class ConnectionInterface: +class Connection: def __init__(self, connection): self.in_transaction: bool = NotImplementedError self.isolation_level: str = NotImplementedError @@ -50,7 +48,7 @@ def __init__(self, connection): def commit(self) -> None: raise NotImplementedError - def cursor(self) -> CursorInterface: + def cursor(self) -> Cursor: raise NotImplementedError def sync(self) -> None: @@ -59,12 +57,10 @@ def sync(self) -> None: def rollback(self) -> None: raise NotImplementedError - def execute(self, sql: str, parameters: tuple[Any] = ...) -> CursorInterface: + def execute(self, sql: str, parameters: tuple[Any] = ...) -> Cursor: raise NotImplementedError - def executemany( - self, sql: str, parameters: list[tuple[Any]] = ... - ) -> CursorInterface: + def executemany(self, sql: str, parameters: list[tuple[Any]] = ...) -> Cursor: raise NotImplementedError def executescript(self, script: str) -> None: @@ -76,6 +72,6 @@ def __init__(self) -> None: """Initialize the Database client""" raise NotImplementedError - def connect(self) -> ConnectionInterface: + def connect(self) -> Connection: """Connect return an active connection to the database""" raise NotImplementedError diff --git a/fortress_sdk_python/fortress.py b/fortress_sdk_python/fortress.py index f0f0924..4a1c55f 100644 --- a/fortress_sdk_python/fortress.py +++ b/fortress_sdk_python/fortress.py @@ -3,7 +3,7 @@ Tenant, Client, ) -from .database import ConnectionInterface +from .database import Connection from .postgres import PostgresClient, PostgresConnection @@ -19,7 +19,7 @@ def __init__(self, org_id: str, api_key: str) -> None: self.__connection_cache = {} self.__tenant_to_database = {} - def connect_database(self, database_id: str) -> ConnectionInterface: + def connect_database(self, database_id: str) -> Connection: """Connect to a database on the Fortress platform""" if database_id in self.__connection_cache: return self.__connection_cache[database_id] @@ -51,7 +51,7 @@ def list_databases(self) -> list[Database]: """List all databases on the Fortress platform""" return self.__fortress.list_databases() - def connect_tenant(self, tenant_name: str) -> ConnectionInterface: + def connect_tenant(self, tenant_name: str) -> Connection: """Connect to a tenant's database on the Fortress platform""" if tenant_name in self.__tenant_to_database: return self.connect_database( diff --git a/fortress_sdk_python/postgres.py b/fortress_sdk_python/postgres.py index bba88c6..96114d3 100644 --- a/fortress_sdk_python/postgres.py +++ b/fortress_sdk_python/postgres.py @@ -1,13 +1,13 @@ from .database import ( DatabaseClient, - ConnectionInterface, - CursorInterface, + Connection, + Cursor, ) import psycopg2 from typing import Any -class PostgresCursor(CursorInterface): +class PostgresCursor(Cursor): def __init__(self, cursor): self.__cursor = cursor @@ -49,7 +49,7 @@ def __exit__(self, exc_type, exc_value, traceback): self.__cursor.__exit__(exc_type, exc_value, traceback) -class PostgresConnection(ConnectionInterface): +class PostgresConnection(Connection): def __init__(self, connection: psycopg2.extensions.connection): self.__connection = connection self.isolation_level: str = self.__connection.isolation_level diff --git a/pyproject.toml b/pyproject.toml index d108cba..ce75a89 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "fortress-sdk-python" -version = "0.1.6" +version = "0.1.8" description = "Fortress Platform Python API SDK" authors = ["Fortress "] readme = "README.md"