From 0b6de7701c834083890d93a2f73a47138589efdc Mon Sep 17 00:00:00 2001 From: Sanhe Hu Date: Thu, 16 May 2024 09:05:23 -0400 Subject: [PATCH] move public api to sqlalchemy_mate.api --- sqlalchemy_mate/__init__.py | 19 ------------------- sqlalchemy_mate/api.py | 22 ++++++++++++++-------- sqlalchemy_mate/crud/deleting_api.py | 3 +++ sqlalchemy_mate/crud/inserting_api.py | 3 +++ sqlalchemy_mate/crud/selecting_api.py | 12 ++++++++++++ sqlalchemy_mate/crud/updating_api.py | 4 ++++ sqlalchemy_mate/io_api.py | 4 ++++ sqlalchemy_mate/orm/api.py | 3 +++ sqlalchemy_mate/pt_api.py | 9 +++++++++ sqlalchemy_mate/types/__init__.py | 4 ---- sqlalchemy_mate/types/api.py | 5 +++++ sqlalchemy_mate/utils.py | 2 +- tests/test_api.py | 2 +- 13 files changed, 59 insertions(+), 33 deletions(-) create mode 100644 sqlalchemy_mate/crud/deleting_api.py create mode 100644 sqlalchemy_mate/crud/inserting_api.py create mode 100644 sqlalchemy_mate/crud/selecting_api.py create mode 100644 sqlalchemy_mate/crud/updating_api.py create mode 100644 sqlalchemy_mate/io_api.py create mode 100644 sqlalchemy_mate/orm/api.py create mode 100644 sqlalchemy_mate/pt_api.py create mode 100644 sqlalchemy_mate/types/api.py diff --git a/sqlalchemy_mate/__init__.py b/sqlalchemy_mate/__init__.py index d2c9dff..8c65610 100644 --- a/sqlalchemy_mate/__init__.py +++ b/sqlalchemy_mate/__init__.py @@ -7,22 +7,3 @@ __author__ = "Sanhe Hu" __author_email__ = "husanhe@gmail.com" __github_username__ = "MacHu-GWU" - - -try: - from . import engine_creator - from . import io - from . import pt - from . import types - from .utils import test_connection - from .engine_creator import EngineCreator - from .crud import selecting - from .crud import inserting - from .crud import updating - from .crud import deleting - from .orm.extended_declarative_base import ExtendedBase - from .vendor.timeout_decorator import TimeoutError -except ImportError as e: # pragma: no cover - print(e) -except Exception as e: # pragma: no cover - raise e diff --git a/sqlalchemy_mate/api.py b/sqlalchemy_mate/api.py index cce9027..41bc8e3 100644 --- a/sqlalchemy_mate/api.py +++ b/sqlalchemy_mate/api.py @@ -1,14 +1,20 @@ # -*- coding: utf-8 -*- +""" +Usage example: + + import sqlalchemy_mate.api as sm +""" + from . import engine_creator -from . import io -from . import pt -from . import types +from . import io_api as io +from . import pt_api as pt +from .types import api as types from .utils import test_connection from .engine_creator import EngineCreator -from .crud import selecting -from .crud import inserting -from .crud import updating -from .crud import deleting -from .orm.extended_declarative_base import ExtendedBase +from .crud import selecting_api as selecting +from .crud import inserting_api as inserting +from .crud import updating_api as updating +from .crud import deleting_api as deleting +from .orm.api import ExtendedBase from .vendor.timeout_decorator import TimeoutError diff --git a/sqlalchemy_mate/crud/deleting_api.py b/sqlalchemy_mate/crud/deleting_api.py new file mode 100644 index 0000000..94270d5 --- /dev/null +++ b/sqlalchemy_mate/crud/deleting_api.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from .deleting import delete_all diff --git a/sqlalchemy_mate/crud/inserting_api.py b/sqlalchemy_mate/crud/inserting_api.py new file mode 100644 index 0000000..926b18b --- /dev/null +++ b/sqlalchemy_mate/crud/inserting_api.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from .inserting import smart_insert diff --git a/sqlalchemy_mate/crud/selecting_api.py b/sqlalchemy_mate/crud/selecting_api.py new file mode 100644 index 0000000..09e500d --- /dev/null +++ b/sqlalchemy_mate/crud/selecting_api.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- + +from .selecting import count_row +from .selecting import by_pk +from .selecting import select_all +from .selecting import select_single_column +from .selecting import select_many_column +from .selecting import select_single_distinct +from .selecting import select_many_distinct +from .selecting import select_random +from .selecting import yield_tuple +from .selecting import yield_dict diff --git a/sqlalchemy_mate/crud/updating_api.py b/sqlalchemy_mate/crud/updating_api.py new file mode 100644 index 0000000..fb9b750 --- /dev/null +++ b/sqlalchemy_mate/crud/updating_api.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- + +from .updating import update_all +from .updating import upsert_all diff --git a/sqlalchemy_mate/io_api.py b/sqlalchemy_mate/io_api.py new file mode 100644 index 0000000..bdff05a --- /dev/null +++ b/sqlalchemy_mate/io_api.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- + +from .io import sql_to_csv +from .io import table_to_csv \ No newline at end of file diff --git a/sqlalchemy_mate/orm/api.py b/sqlalchemy_mate/orm/api.py new file mode 100644 index 0000000..798bdd1 --- /dev/null +++ b/sqlalchemy_mate/orm/api.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from .extended_declarative_base import ExtendedBase diff --git a/sqlalchemy_mate/pt_api.py b/sqlalchemy_mate/pt_api.py new file mode 100644 index 0000000..a9603e6 --- /dev/null +++ b/sqlalchemy_mate/pt_api.py @@ -0,0 +1,9 @@ +# -*- coding: utf-8 -*- + +from .pt import from_result +from .pt import from_text_clause +from .pt import from_stmt +from .pt import from_table +from .pt import from_model +from .pt import from_dict_list +from .pt import from_everything diff --git a/sqlalchemy_mate/types/__init__.py b/sqlalchemy_mate/types/__init__.py index 7f9ce98..40a96af 100644 --- a/sqlalchemy_mate/types/__init__.py +++ b/sqlalchemy_mate/types/__init__.py @@ -1,5 +1 @@ # -*- coding: utf-8 -*- - -from .compressed import CompressedStringType, CompressedBinaryType -from .compressed_json import CompressedJSONType -from .json_serializable import JSONSerializableType diff --git a/sqlalchemy_mate/types/api.py b/sqlalchemy_mate/types/api.py new file mode 100644 index 0000000..7f9ce98 --- /dev/null +++ b/sqlalchemy_mate/types/api.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- + +from .compressed import CompressedStringType, CompressedBinaryType +from .compressed_json import CompressedJSONType +from .json_serializable import JSONSerializableType diff --git a/sqlalchemy_mate/utils.py b/sqlalchemy_mate/utils.py index 0a3aa88..105a93f 100644 --- a/sqlalchemy_mate/utils.py +++ b/sqlalchemy_mate/utils.py @@ -102,7 +102,7 @@ def clean_session( from .vendor import timeout_decorator -def test_connection(engine, timeout=3): +def test_connection(engine: sa.Engine, timeout=3): @timeout_decorator.timeout(timeout) def _test_connection(engine): with engine.connect() as connection: diff --git a/tests/test_api.py b/tests/test_api.py index a8b4ccd..a4fb026 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -2,7 +2,7 @@ def test(): - import sqlalchemy_mate as sm + import sqlalchemy_mate.api as sm _ = sm.selecting.count_row _ = sm.selecting.by_pk