Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
push:
branches:
- main
- feat/tortoise

permissions:
id-token: write # This is required for requesting the JWT
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11"]
poetry-version: ["1.8.2"]

steps:
Expand Down
5 changes: 5 additions & 0 deletions aws_advanced_python_wrapper/driver_dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
if TYPE_CHECKING:
from aws_advanced_python_wrapper.hostinfo import HostInfo
from aws_advanced_python_wrapper.pep249 import Connection, Cursor
from types import ModuleType

from abc import ABC
from concurrent.futures import Executor, ThreadPoolExecutor, TimeoutError
Expand Down Expand Up @@ -164,3 +165,7 @@ def ping(self, conn: Connection) -> bool:
return True
except Exception:
return False

def get_driver_module(self) -> ModuleType:
raise UnsupportedOperationError(
Messages.get_formatted("DriverDialect.UnsupportedOperationError", self._driver_name, "get_driver_module"))
3 changes: 2 additions & 1 deletion aws_advanced_python_wrapper/driver_dialect_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class DriverDialectManager(DriverDialectProvider):
}

pool_connection_driver_dialect: Dict[str, str] = {
"SqlAlchemyPooledConnectionProvider": "aws_advanced_python_wrapper.sqlalchemy_driver_dialect.SqlAlchemyDriverDialect"
"SqlAlchemyPooledConnectionProvider": "aws_advanced_python_wrapper.sqlalchemy_driver_dialect.SqlAlchemyDriverDialect",
"SqlAlchemyTortoisePooledConnectionProvider": "aws_advanced_python_wrapper.sqlalchemy_driver_dialect.SqlAlchemyDriverDialect",
}

@staticmethod
Expand Down
7 changes: 6 additions & 1 deletion aws_advanced_python_wrapper/mysql_driver_dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

from typing import TYPE_CHECKING, Any, Callable, ClassVar, Set

import mysql.connector

if TYPE_CHECKING:
from aws_advanced_python_wrapper.hostinfo import HostInfo
from aws_advanced_python_wrapper.pep249 import Connection
from types import ModuleType

from concurrent.futures import Executor, ThreadPoolExecutor, TimeoutError
from inspect import signature
Expand Down Expand Up @@ -201,3 +203,6 @@ def prepare_connect_info(self, host_info: HostInfo, original_props: Properties)

def supports_connect_timeout(self) -> bool:
return True

def get_driver_module(self) -> ModuleType:
return mysql.connector
7 changes: 5 additions & 2 deletions aws_advanced_python_wrapper/pg_driver_dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@

from __future__ import annotations

from inspect import signature
from typing import TYPE_CHECKING, Any, Callable, Set

import psycopg

if TYPE_CHECKING:
from aws_advanced_python_wrapper.hostinfo import HostInfo
from aws_advanced_python_wrapper.pep249 import Connection

from inspect import signature
from types import ModuleType

from aws_advanced_python_wrapper.driver_dialect import DriverDialect
from aws_advanced_python_wrapper.driver_dialect_codes import DriverDialectCodes
Expand Down Expand Up @@ -175,3 +175,6 @@ def supports_tcp_keepalive(self) -> bool:

def supports_abort_connection(self) -> bool:
return True

def get_driver_module(self) -> ModuleType:
return psycopg
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ WeightedRandomHostSelector.WeightedRandomInvalidDefaultWeight=[WeightedRandomHos
SqlAlchemyPooledConnectionProvider.PoolNone=[SqlAlchemyPooledConnectionProvider] Attempted to find or create a pool for '{}' but the result of the attempt evaluated to None.
SqlAlchemyPooledConnectionProvider.UnableToCreateDefaultKey=[SqlAlchemyPooledConnectionProvider] Unable to create a default key for internal connection pools. By default, the user parameter is used, but the given user evaluated to None or the empty string (""). Please ensure you have passed a valid user in the connection properties.

SqlAlchemyTortoiseConnectionProvider.UnableToDetermineDialect=[SqlAlchemyTortoiseConnectionProvider] Unable to resolve sql alchemy dialect for the following driver dialect '{}'.

SqlAlchemyDriverDialect.SetValueOnNoneConnection=[SqlAlchemyDriverDialect] Attempted to set the '{}' value on a pooled connection, but no underlying driver connection was found. This can happen if the pooled connection has previously been closed.

StaleDnsHelper.ClusterEndpointDns=[StaleDnsPlugin] Cluster endpoint {} resolves to {}.
Expand Down
13 changes: 9 additions & 4 deletions aws_advanced_python_wrapper/sqlalchemy_driver_dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,23 @@

from typing import TYPE_CHECKING, Any

from aws_advanced_python_wrapper.driver_dialect import DriverDialect
from aws_advanced_python_wrapper.errors import AwsWrapperError
from aws_advanced_python_wrapper.utils.messages import Messages

if TYPE_CHECKING:
from aws_advanced_python_wrapper.hostinfo import HostInfo
from aws_advanced_python_wrapper.pep249 import Connection
from aws_advanced_python_wrapper.utils.properties import Properties
from types import ModuleType

from sqlalchemy import PoolProxiedConnection

from aws_advanced_python_wrapper.driver_dialect import DriverDialect
from aws_advanced_python_wrapper.errors import AwsWrapperError
from aws_advanced_python_wrapper.utils.messages import Messages


class SqlAlchemyDriverDialect(DriverDialect):
_driver_name: str = "SQLAlchemy"
TARGET_DRIVER_CODE: str = "sqlalchemy"
_underlying_driver_dialect = None

def __init__(self, underlying_driver: DriverDialect, props: Properties):
super().__init__(props)
Expand Down Expand Up @@ -125,3 +127,6 @@ def transfer_session_state(self, from_conn: Connection, to_conn: Connection):
return None

return self._underlying_driver.transfer_session_state(from_driver_conn, to_driver_conn)

def get_driver_module(self) -> ModuleType:
return self._underlying_driver.get_driver_module()
37 changes: 37 additions & 0 deletions aws_advanced_python_wrapper/tortoise/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from tortoise.backends.base.config_generator import DB_LOOKUP

# Register AWS MySQL backend
DB_LOOKUP["aws-mysql"] = {
"engine": "aws_advanced_python_wrapper.tortoise.backends.mysql",
"vmap": {
"path": "database",
"hostname": "host",
"port": "port",
"username": "user",
"password": "password",
},
"defaults": {"port": 3306, "charset": "utf8mb4", "sql_mode": "STRICT_TRANS_TABLES"},
"cast": {
"minsize": int,
"maxsize": int,
"connect_timeout": int,
"echo": bool,
"use_unicode": bool,
"ssl": bool,
"use_pure": bool,
},
}
13 changes: 13 additions & 0 deletions aws_advanced_python_wrapper/tortoise/backends/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
13 changes: 13 additions & 0 deletions aws_advanced_python_wrapper/tortoise/backends/base/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
Loading
Loading