Skip to content

Commit

Permalink
refactor: rename interface classes
Browse files Browse the repository at this point in the history
  • Loading branch information
John2360 committed Aug 21, 2024
1 parent 4fa7751 commit 1ee613d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
24 changes: 10 additions & 14 deletions fortress_sdk_python/database.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand All @@ -35,22 +33,22 @@ 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

def commit(self) -> None:
raise NotImplementedError

def cursor(self) -> CursorInterface:
def cursor(self) -> Cursor:
raise NotImplementedError

def sync(self) -> None:
Expand All @@ -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:
Expand All @@ -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
6 changes: 3 additions & 3 deletions fortress_sdk_python/fortress.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Tenant,
Client,
)
from .database import ConnectionInterface
from .database import Connection
from .postgres import PostgresClient, PostgresConnection


Expand All @@ -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]
Expand Down Expand Up @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions fortress_sdk_python/postgres.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit 1ee613d

Please sign in to comment.