atquery 2.11.15__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. atquery-2.11.15/LICENSE +21 -0
  2. atquery-2.11.15/PKG-INFO +63 -0
  3. atquery-2.11.15/README.md +29 -0
  4. atquery-2.11.15/pyproject.toml +143 -0
  5. atquery-2.11.15/src/atquery/__init__.py +47 -0
  6. atquery-2.11.15/src/atquery/aio/__init__.py +101 -0
  7. atquery-2.11.15/src/atquery/aio/engine.py +431 -0
  8. atquery-2.11.15/src/atquery/aio/query.py +391 -0
  9. atquery-2.11.15/src/atquery/api_v2.py +182 -0
  10. atquery-2.11.15/src/atquery/atquery2.py +730 -0
  11. atquery-2.11.15/src/atquery/cli/__init__.py +0 -0
  12. atquery-2.11.15/src/atquery/cli/columns.py +159 -0
  13. atquery-2.11.15/src/atquery/cli/ddl.py +151 -0
  14. atquery-2.11.15/src/atquery/cli/diff.py +196 -0
  15. atquery-2.11.15/src/atquery/cli/main.py +749 -0
  16. atquery-2.11.15/src/atquery/cli/migrate.py +312 -0
  17. atquery-2.11.15/src/atquery/cli/routines.py +142 -0
  18. atquery-2.11.15/src/atquery/cli/scenario.py +170 -0
  19. atquery-2.11.15/src/atquery/cli/schemas.py +138 -0
  20. atquery-2.11.15/src/atquery/cli/tables.py +166 -0
  21. atquery-2.11.15/src/atquery/dialect/__init__.py +107 -0
  22. atquery-2.11.15/src/atquery/dialect/duckdb.py +561 -0
  23. atquery-2.11.15/src/atquery/dialect/mysql/__init__.py +67 -0
  24. atquery-2.11.15/src/atquery/dialect/mysql/aio.py +166 -0
  25. atquery-2.11.15/src/atquery/dialect/mysql/core.py +439 -0
  26. atquery-2.11.15/src/atquery/dialect/mysql/dump/__init__.py +10 -0
  27. atquery-2.11.15/src/atquery/dialect/mysql/dump/__main__.py +94 -0
  28. atquery-2.11.15/src/atquery/dialect/mysql/dump/core.py +377 -0
  29. atquery-2.11.15/src/atquery/dialect/mysql/meta.py +408 -0
  30. atquery-2.11.15/src/atquery/dialect/mysql/pooling.py +94 -0
  31. atquery-2.11.15/src/atquery/dialect/mysql/restore/__init__.py +10 -0
  32. atquery-2.11.15/src/atquery/dialect/mysql/restore/__main__.py +83 -0
  33. atquery-2.11.15/src/atquery/dialect/mysql/restore/core.py +313 -0
  34. atquery-2.11.15/src/atquery/dialect/sqlite.py +391 -0
  35. atquery-2.11.15/src/atquery/diff/__init__.py +1 -0
  36. atquery-2.11.15/src/atquery/diff/comparator.py +290 -0
  37. atquery-2.11.15/src/atquery/diff/generator.py +189 -0
  38. atquery-2.11.15/src/atquery/diff/git_integration.py +93 -0
  39. atquery-2.11.15/src/atquery/diff/models.py +31 -0
  40. atquery-2.11.15/src/atquery/diff/parser.py +83 -0
  41. atquery-2.11.15/src/atquery/engine.py +1011 -0
  42. atquery-2.11.15/src/atquery/factory.py +140 -0
  43. atquery-2.11.15/src/atquery/migration/__init__.py +39 -0
  44. atquery-2.11.15/src/atquery/migration/_migrator.py +163 -0
  45. atquery-2.11.15/src/atquery/migration/_protocol.py +98 -0
  46. atquery-2.11.15/src/atquery/migration/_standard.py +250 -0
  47. atquery-2.11.15/src/atquery/migration/_types.py +48 -0
  48. atquery-2.11.15/src/atquery/py.typed +0 -0
  49. atquery-2.11.15/src/atquery/testing/__init__.py +39 -0
  50. atquery-2.11.15/src/atquery/testing/creator.py +117 -0
  51. atquery-2.11.15/src/atquery/testing/loader.py +546 -0
  52. atquery-2.11.15/src/atquery/testing/schema.py +217 -0
  53. atquery-2.11.15/src/atquery/testing/validator.py +145 -0
  54. atquery-2.11.15/src/atquery/type.py +126 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 alpine
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,63 @@
1
+ Metadata-Version: 2.4
2
+ Name: atquery
3
+ Version: 2.11.15
4
+ Summary: A Python module for simplifying DBAPI usage with one-query-per-file SQL management.
5
+ Keywords: sql,database,dbapi,mysql,sqlite,duckdb
6
+ Author: alpine
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3 :: Only
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Topic :: Database
18
+ Requires-Dist: mysql-connector-python ; extra == 'all'
19
+ Requires-Dist: duckdb ; extra == 'all'
20
+ Requires-Dist: json5 ; extra == 'all'
21
+ Requires-Dist: sqlglot ; extra == 'all'
22
+ Requires-Dist: python-dotenv>=1.2.2 ; extra == 'all'
23
+ Requires-Dist: sqlglot>=30.4.2 ; extra == 'diff'
24
+ Requires-Dist: duckdb>=0.10.0 ; extra == 'duckdb'
25
+ Requires-Dist: mysql-connector-python>=8.0,<10 ; extra == 'mysql'
26
+ Requires-Dist: json5>=0.12.1 ; extra == 'testing'
27
+ Requires-Python: >=3.10
28
+ Provides-Extra: all
29
+ Provides-Extra: diff
30
+ Provides-Extra: duckdb
31
+ Provides-Extra: mysql
32
+ Provides-Extra: testing
33
+ Description-Content-Type: text/markdown
34
+
35
+ # ATQuery
36
+
37
+ DBAPI用のSQLファイル実行ヘルパーです。
38
+
39
+ ## インストール
40
+
41
+ ```bash
42
+ pip install atquery
43
+ ```
44
+
45
+ ## 使い方
46
+
47
+ ```python
48
+ import atquery
49
+
50
+ ds = atquery.create_datasource("sqlite:///:memory:")
51
+ q = atquery.load(__file__, "sql/SELECT__users.sql")
52
+
53
+ with ds.connect() as conn:
54
+ users = q.getall(conn, {"status": "active"})
55
+ ```
56
+
57
+ ## 要件
58
+
59
+ - Python 3.10以上
60
+
61
+ ## ライセンス
62
+
63
+ MIT
@@ -0,0 +1,29 @@
1
+ # ATQuery
2
+
3
+ DBAPI用のSQLファイル実行ヘルパーです。
4
+
5
+ ## インストール
6
+
7
+ ```bash
8
+ pip install atquery
9
+ ```
10
+
11
+ ## 使い方
12
+
13
+ ```python
14
+ import atquery
15
+
16
+ ds = atquery.create_datasource("sqlite:///:memory:")
17
+ q = atquery.load(__file__, "sql/SELECT__users.sql")
18
+
19
+ with ds.connect() as conn:
20
+ users = q.getall(conn, {"status": "active"})
21
+ ```
22
+
23
+ ## 要件
24
+
25
+ - Python 3.10以上
26
+
27
+ ## ライセンス
28
+
29
+ MIT
@@ -0,0 +1,143 @@
1
+ [build-system]
2
+ requires = ["uv_build>=0.11.15,<0.12"]
3
+ build-backend = "uv_build"
4
+
5
+ [project]
6
+ name = "atquery"
7
+ version = "2.11.15"
8
+ description = "A Python module for simplifying DBAPI usage with one-query-per-file SQL management."
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ authors = [
14
+ { name = "alpine" },
15
+ ]
16
+ keywords = ["sql", "database", "dbapi", "mysql", "sqlite", "duckdb"]
17
+ classifiers = [
18
+ "Development Status :: 4 - Beta",
19
+ "Intended Audience :: Developers",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3 :: Only",
22
+ "Programming Language :: Python :: 3.10",
23
+ "Programming Language :: Python :: 3.11",
24
+ "Programming Language :: Python :: 3.12",
25
+ "Programming Language :: Python :: 3.13",
26
+ "Topic :: Database",
27
+ ]
28
+
29
+ [project.scripts]
30
+ atquery = "atquery.cli.main:main"
31
+
32
+ [project.optional-dependencies]
33
+ mysql = [
34
+ "mysql-connector-python>=8.0,<10",
35
+ ]
36
+ duckdb = [
37
+ "duckdb>=0.10.0",
38
+ ]
39
+ testing = [
40
+ "json5>=0.12.1",
41
+ ]
42
+ diff = [
43
+ "sqlglot>=30.4.2",
44
+ ]
45
+ all = [
46
+ "mysql-connector-python",
47
+ "duckdb",
48
+ "json5",
49
+ "sqlglot",
50
+ "python-dotenv>=1.2.2",
51
+ ]
52
+
53
+ [dependency-groups]
54
+ dev = [
55
+ # -- optional dependencies --
56
+ "mysql-connector-python",
57
+ "duckdb",
58
+ "json5",
59
+ "python-dotenv",
60
+ "sqlglot",
61
+ # -- ruff --
62
+ "ruff",
63
+ # -- pyright --
64
+ "pyright",
65
+ #-- pytest --
66
+ "pytest>=7.0.0",
67
+ "pytest-cov>=4.0.0",
68
+ "pytest-mock>=3.10.0",
69
+ #-- dev-docs skill --
70
+ "pyyaml>=6.0.3",
71
+ "rich>=14.3.3",
72
+ "pytest-asyncio>=1.4.0",
73
+ ]
74
+
75
+
76
+ [tool.uv]
77
+ package = true
78
+
79
+ [tool.ruff]
80
+ # https://docs.astral.sh/ruff/configuration/
81
+ src = ["src"]
82
+
83
+ [tool.ruff.lint]
84
+ # https://docs.astral.sh/ruff/rules/
85
+ select = [
86
+ # pycodestyle (E, W)
87
+ "E2",
88
+ "E4",
89
+ "E7",
90
+ "E9",
91
+ "W",
92
+
93
+ # Pyflakes (F)
94
+ "F",
95
+
96
+ # flake8-no-pep420 (INP)
97
+ "INP",
98
+
99
+ # pep8-naming (N)
100
+ #"N",
101
+ ]
102
+
103
+ [tool.ruff.lint.per-file-ignores]
104
+ "docker/*.py" = ["INP"]
105
+ "scripts/*.py" = ["INP"]
106
+ "tests/*.py" = ["INP"]
107
+ "var/*.py" = ["INP"]
108
+
109
+
110
+ [tool.pyright]
111
+ # https://microsoft.github.io/pyright/#/configuration
112
+ include = ["src"]
113
+ venvPath = "."
114
+ venv = ".venv"
115
+ typeCheckingMode = "basic"
116
+
117
+
118
+ [tool.pytest.ini_options]
119
+ cache_dir = "var/.pytest_cache"
120
+ asyncio_mode = "auto"
121
+ testpaths = ["tests"]
122
+
123
+
124
+ [tool.coverage.run]
125
+ source = ["src"]
126
+ data_file = "var/.coverage"
127
+ omit = [
128
+ "tests/*",
129
+ ]
130
+
131
+ [tool.coverage.report]
132
+ exclude_lines = [
133
+ "pragma: no cover",
134
+ "def __repr__",
135
+ "if self.debug:",
136
+ "if settings.DEBUG",
137
+ "raise AssertionError",
138
+ "raise NotImplementedError",
139
+ "if 0:",
140
+ "if __name__ == .__main__.:",
141
+ "class .*\\bProtocol\\):",
142
+ "@(abc\\.)?abstractmethod",
143
+ ]
@@ -0,0 +1,47 @@
1
+ from .api_v2 import (
2
+ NULL,
3
+ ATConnection,
4
+ ATDataSource,
5
+ ATQuery,
6
+ ATResult,
7
+ ATRow,
8
+ ATRowCountError,
9
+ ATSQLError,
10
+ ATString,
11
+ ATWarning,
12
+ Resource,
13
+ create_async_datasource,
14
+ create_datasource,
15
+ escape4like,
16
+ execute,
17
+ execute_script,
18
+ export_csv,
19
+ insert_csv,
20
+ load,
21
+ sql,
22
+ upsert_csv,
23
+ )
24
+
25
+ __all__ = [
26
+ "NULL",
27
+ "ATConnection",
28
+ "ATDataSource",
29
+ "ATQuery",
30
+ "ATResult",
31
+ "ATRow",
32
+ "ATRowCountError",
33
+ "ATSQLError",
34
+ "ATString",
35
+ "ATWarning",
36
+ "Resource",
37
+ "create_async_datasource",
38
+ "create_datasource",
39
+ "escape4like",
40
+ "execute",
41
+ "execute_script",
42
+ "insert_csv",
43
+ "load",
44
+ "sql",
45
+ "upsert_csv",
46
+ "export_csv",
47
+ ]
@@ -0,0 +1,101 @@
1
+ """atquery.aio - async 専用 DataSource / Query の公開 API
2
+
3
+ Usage:
4
+ import atquery.aio
5
+
6
+ async_ds = atquery.aio.create_datasource("mysql://user:pass@host/db")
7
+ async_ds = atquery.aio.create_datasource("mysql://user:pass@host/db", pool_size=10)
8
+
9
+ async with async_ds.connect() as conn:
10
+ users = await at.aquery("SELECT__users.sql").getall(conn, {"status": "active"})
11
+ """
12
+ import re
13
+ from importlib import import_module
14
+ from typing import Any
15
+ from urllib.parse import parse_qsl, urlparse
16
+
17
+ from atquery.aio.engine import (
18
+ ATAsyncConnection,
19
+ ATAsyncConnectionPool,
20
+ ATAsyncDataSource,
21
+ ATAsyncResult,
22
+ )
23
+ from atquery.aio.query import ATAsyncQuery, ATAsyncTypedQueryProxy
24
+
25
+ _ASYNC_DATASOURCE_TYPES: dict[str, tuple[str, str]] = {
26
+ "mysql": ("atquery.dialect.mysql.aio", "ATMySQLAsyncDataSource"),
27
+ "mysql+mysqlconnector": ("atquery.dialect.mysql.aio", "ATMySQLAsyncDataSource"),
28
+ "mysql+mysqlconnector#poolable": ("atquery.dialect.mysql.aio", "ATMySQLAsyncPoolableDataSource"),
29
+ "mysql#poolable": ("atquery.dialect.mysql.aio", "ATMySQLAsyncPoolableDataSource"),
30
+ }
31
+
32
+ _USER = re.compile(r"^.+:\/\/([^:]+:[^@]+@)")
33
+
34
+
35
+ def create_datasource(uri: str, pool_size: int = 0) -> ATAsyncDataSource:
36
+ """async 専用 DataSource を生成する。
37
+
38
+ Args:
39
+ uri: 接続URI。例: "mysql://user:pass@host/db"
40
+ pool_size: コネクションプールサイズ。0の場合はプールなし。
41
+
42
+ Returns:
43
+ ATAsyncDataSource: async専用DataSource
44
+ """
45
+ username = None
46
+ password = None
47
+ if match := _USER.match(uri):
48
+ user = match.group(1)
49
+ (username, password) = user.split(":", 1)
50
+ password = password[:-1] # '@' を除く
51
+ uri = uri.replace(user, "", 1)
52
+
53
+ sr = urlparse(uri)
54
+ scheme = sr.scheme
55
+ params: dict[str, Any] = dict(parse_qsl(sr.query))
56
+
57
+ if pool_size:
58
+ scheme += "#poolable"
59
+ params["pool_size"] = pool_size
60
+
61
+ info = _ASYNC_DATASOURCE_TYPES.get(scheme)
62
+ if info is None:
63
+ raise ValueError(f'scheme "{scheme}" は async DataSource でサポートされていません。')
64
+
65
+ cls = getattr(import_module(info[0]), info[1])
66
+ return cls(
67
+ user=username or sr.username,
68
+ password=password or sr.password,
69
+ host=sr.hostname,
70
+ port=sr.port,
71
+ database=sr.path[1:],
72
+ **params,
73
+ )
74
+
75
+
76
+ def load(py: str, filepath: str, use_cache: bool = True) -> ATAsyncQuery:
77
+ """SQLファイルを読み込んで ATAsyncQuery のインスタンスを生成する。
78
+
79
+ Args:
80
+ py: ファイル検索の起点モジュール(通常は __file__)
81
+ filepath: SQLファイルの相対パス
82
+ use_cache: キャッシュを使用するか
83
+
84
+ Returns:
85
+ ATAsyncQuery: インスタンス
86
+ """
87
+ from atquery.factory import Resource
88
+
89
+ return Resource.aload(py, filepath, use_cache=use_cache)
90
+
91
+
92
+ __all__ = [
93
+ "ATAsyncConnection",
94
+ "ATAsyncConnectionPool",
95
+ "ATAsyncDataSource",
96
+ "ATAsyncResult",
97
+ "ATAsyncQuery",
98
+ "ATAsyncTypedQueryProxy",
99
+ "create_datasource",
100
+ "load",
101
+ ]