Skip to content
Merged
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
16 changes: 15 additions & 1 deletion aurora_data_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Time,
Timestamp,
DateFromTicks,
# TimeFromTicks,
TimeFromTicks,
TimestampFromTicks,
Binary,
STRING,
Expand All @@ -22,3 +22,17 @@
ROWID,
DECIMAL,
)
from .exceptions import (
Warning,
Error,
InterfaceError,
DatabaseError,
DataError,
OperationalError,
IntegrityError,
InternalError,
ProgrammingError,
NotSupportedError,
MySQLError,
PostgreSQLError,
)
64 changes: 38 additions & 26 deletions aurora_data_api/async_.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,41 @@
"""
aurora-data-api - A Python DB-API 2.0 client for the AWS Aurora Serverless Data API (Async version)
"""
import os, datetime, ipaddress, uuid, time, random, string, logging, itertools, reprlib, json, re, asyncio
from decimal import Decimal
from collections import namedtuple
from collections.abc import Mapping

import time
import random
import string
import reprlib
from .base import BaseAuroraDataAPIClient, BaseAuroraDataAPICursor, logger
from .base import (
apilevel, threadsafety, paramstyle, Date, Time, Timestamp, DateFromTicks,
TimestampFromTicks, Binary, STRING, BINARY, NUMBER, DATETIME, ROWID, DECIMAL,
ColumnDescription
apilevel, # noqa: F401
threadsafety, # noqa: F401
paramstyle, # noqa: F401
Date, # noqa: F401
Time, # noqa: F401
Timestamp, # noqa: F401
DateFromTicks, # noqa: F401
TimeFromTicks, # noqa: F401
TimestampFromTicks, # noqa: F401
Binary, # noqa: F401
STRING, # noqa: F401
BINARY, # noqa: F401
NUMBER, # noqa: F401
DATETIME, # noqa: F401
ROWID, # noqa: F401
DECIMAL, # noqa: F401
)
from .exceptions import (
Warning,
Error,
InterfaceError,
DatabaseError,
DataError,
OperationalError,
IntegrityError,
InternalError,
ProgrammingError,
NotSupportedError,
MySQLError,
PostgreSQLError,
Warning, # noqa: F401
Error, # noqa: F401
InterfaceError, # noqa: F401
DatabaseError, # noqa: F401
DataError, # noqa: F401
OperationalError, # noqa: F401
IntegrityError, # noqa: F401
InternalError, # noqa: F401
ProgrammingError, # noqa: F401
NotSupportedError, # noqa: F401
)
import aiobotocore.session

Expand Down Expand Up @@ -184,14 +196,14 @@ def __aiter__(self):

async def __anext__(self):
if self._paging_state:
if not hasattr(self, '_page_iterator'):
if not hasattr(self, "_page_iterator"):
self._page_iterator = self._fetch_paginated_records()
try:
return await self._page_iterator.__anext__()
except StopAsyncIteration:
raise StopAsyncIteration
else:
if not hasattr(self, '_record_index'):
if not hasattr(self, "_record_index"):
self._record_index = 0
records = self._current_response.get("records", [])
if self._record_index >= len(records):
Expand All @@ -203,16 +215,16 @@ async def __anext__(self):
async def _fetch_paginated_records(self):
next_page_args = self._paging_state["execute_statement_args"]
while True:
logger.debug(
"Fetching page of %d records for auto-paginated query", self._paging_state["records_per_page"]
)
logger.debug("Fetching page of %d records for auto-paginated query", self._paging_state["records_per_page"])
next_page_args["sql"] = "FETCH {records_per_page} FROM {pg_cursor_name}".format(**self._paging_state)
try:
page = await self._client.execute_statement(**next_page_args)
except self._client.exceptions.BadRequestException as e:
cur_rpp = self._paging_state["records_per_page"]
if "Database returned more than the allowed response size limit" in str(e) and cur_rpp > 1:
await self.scroll(-self._paging_state["records_per_page"]) # Rewind the cursor to read the page again
await self.scroll(
-self._paging_state["records_per_page"]
) # Rewind the cursor to read the page again
logger.debug("Halving records per page")
self._paging_state["records_per_page"] //= 2
continue
Expand Down Expand Up @@ -262,7 +274,7 @@ async def __aexit__(self, err_type, value, traceback):
self._current_response = None


def connect(
async def connect(
aurora_cluster_arn=None,
secret_arn=None,
rds_data_client=None,
Expand Down
31 changes: 17 additions & 14 deletions aurora_data_api/base.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
"""
Base classes for Aurora Data API clients and cursors
"""
import os, datetime, ipaddress, uuid, time, random, string, logging, itertools, reprlib, json, re

import os
import datetime
import ipaddress
import uuid
import time
import logging
import itertools
import re
from decimal import Decimal
from collections import namedtuple
from collections.abc import Mapping
from .exceptions import (
Warning,
Error,
InterfaceError,
DatabaseError,
DataError,
OperationalError,
IntegrityError,
InternalError,
ProgrammingError,
NotSupportedError,
MySQLError,
PostgreSQLError,
)
from .error_codes_mysql import MySQLErrorCodes
from .error_codes_postgresql import PostgreSQLErrorCodes

apilevel = "2.0"

Expand All @@ -32,7 +30,12 @@
Time = datetime.time
Timestamp = datetime.datetime
DateFromTicks = datetime.date.fromtimestamp
# TimeFromTicks = datetime.time.fromtimestamp TODO


def TimeFromTicks(ticks):
return Time(*time.localtime(ticks)[3:6])


TimestampFromTicks = datetime.datetime.fromtimestamp
Binary = bytes
STRING = str
Expand All @@ -50,7 +53,7 @@

class BaseAuroraDataAPIClient:
"""Base class for Aurora Data API clients"""

def __init__(
self,
dbname=None,
Expand All @@ -74,7 +77,7 @@ def close(self):

class BaseAuroraDataAPICursor:
"""Base class for Aurora Data API cursors"""

_pg_type_map = {
"int": int,
"int2": int,
Expand Down
51 changes: 32 additions & 19 deletions aurora_data_api/sync.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,42 @@
"""
aurora-data-api - A Python DB-API 2.0 client for the AWS Aurora Serverless Data API
"""
import os, datetime, ipaddress, uuid, time, random, string, logging, itertools, reprlib, json, re, threading
from decimal import Decimal
from collections import namedtuple
from collections.abc import Mapping

import time
import random
import string
import reprlib
import threading
from .base import BaseAuroraDataAPIClient, BaseAuroraDataAPICursor, logger
from .base import (
apilevel, threadsafety, paramstyle, Date, Time, Timestamp, DateFromTicks,
TimestampFromTicks, Binary, STRING, BINARY, NUMBER, DATETIME, ROWID, DECIMAL,
ColumnDescription
apilevel, # noqa: F401
threadsafety, # noqa: F401
paramstyle, # noqa: F401
Date, # noqa: F401
Time, # noqa: F401
Timestamp, # noqa: F401
DateFromTicks, # noqa: F401
TimeFromTicks, # noqa: F401
TimestampFromTicks, # noqa: F401
Binary, # noqa: F401
STRING, # noqa: F401
BINARY, # noqa: F401
NUMBER, # noqa: F401
DATETIME, # noqa: F401
ROWID, # noqa: F401
DECIMAL, # noqa: F401
)
from .exceptions import (
Warning,
Error,
InterfaceError,
DatabaseError,
DataError,
OperationalError,
IntegrityError,
InternalError,
ProgrammingError,
NotSupportedError,
MySQLError,
PostgreSQLError,
Warning, # noqa: F401
Error, # noqa: F401
InterfaceError, # noqa: F401
DatabaseError, # noqa: F401
DataError, # noqa: F401
OperationalError, # noqa: F401
IntegrityError, # noqa: F401
InternalError, # noqa: F401
ProgrammingError, # noqa: F401
NotSupportedError, # noqa: F401
)
import botocore.session

Expand Down
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
description="A Python DB-API 2.0 client for the AWS Aurora Serverless Data API",
long_description=open("README.rst").read(),
install_requires=["botocore >= 1.38.40, < 2"],
extras_require={
"async": "aiobotocore >= 2.23.1, < 3"
},
extras_require={"async": "aiobotocore >= 2.23.1, < 3"},
packages=find_packages(exclude=["test"]),
platforms=["MacOS X", "Posix"],
test_suite="test",
Expand Down
Loading