kajenn-db 0.1.0__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.
- kajenn_db-0.1.0/.github/workflows/publish.yml +81 -0
- kajenn_db-0.1.0/.github/workflows/tests.yml +55 -0
- kajenn_db-0.1.0/.gitignore +17 -0
- kajenn_db-0.1.0/.readthedocs.yaml +23 -0
- kajenn_db-0.1.0/CHANGELOG.md +39 -0
- kajenn_db-0.1.0/LICENSE +201 -0
- kajenn_db-0.1.0/PKG-INFO +211 -0
- kajenn_db-0.1.0/README.md +174 -0
- kajenn_db-0.1.0/docs/_static/.gitkeep +0 -0
- kajenn_db-0.1.0/docs/api.rst +25 -0
- kajenn_db-0.1.0/docs/changelog.md +2 -0
- kajenn_db-0.1.0/docs/conf.py +59 -0
- kajenn_db-0.1.0/docs/index.md +10 -0
- kajenn_db-0.1.0/pyproject.toml +70 -0
- kajenn_db-0.1.0/src/kajenn_db/__init__.py +19 -0
- kajenn_db-0.1.0/src/kajenn_db/asqueel.py +232 -0
- kajenn_db-0.1.0/src/kajenn_db/django.py +103 -0
- kajenn_db-0.1.0/src/kajenn_db/py.typed +0 -0
- kajenn_db-0.1.0/src/kajenn_db/sqlalchemy.py +83 -0
- kajenn_db-0.1.0/tests/__init__.py +0 -0
- kajenn_db-0.1.0/tests/asqueel/__init__.py +0 -0
- kajenn_db-0.1.0/tests/asqueel/test_async_view.py +292 -0
- kajenn_db-0.1.0/tests/asqueel/test_postgresql.py +207 -0
- kajenn_db-0.1.0/tests/asqueel/test_sqlite.py +144 -0
- kajenn_db-0.1.0/tests/conftest.py +289 -0
- kajenn_db-0.1.0/tests/contract/__init__.py +0 -0
- kajenn_db-0.1.0/tests/contract/test_contract.py +162 -0
- kajenn_db-0.1.0/tests/django/__init__.py +0 -0
- kajenn_db-0.1.0/tests/django/test_sqlite.py +129 -0
- kajenn_db-0.1.0/tests/sqlalchemy/__init__.py +0 -0
- kajenn_db-0.1.0/tests/sqlalchemy/test_sqlite.py +115 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
"on":
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- 'v*' # Trigger on version tags (v0.20.0, v1.0.0, etc.)
|
|
7
|
+
workflow_dispatch: # Allow manual trigger
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
build:
|
|
11
|
+
name: Build distribution
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
|
|
16
|
+
- name: Set up Python
|
|
17
|
+
uses: actions/setup-python@v5
|
|
18
|
+
with:
|
|
19
|
+
python-version: '3.11'
|
|
20
|
+
|
|
21
|
+
- name: Install build dependencies
|
|
22
|
+
run: |
|
|
23
|
+
python -m pip install --upgrade pip
|
|
24
|
+
pip install build
|
|
25
|
+
|
|
26
|
+
- name: Build package
|
|
27
|
+
run: python -m build
|
|
28
|
+
|
|
29
|
+
- name: Upload distribution artifacts
|
|
30
|
+
uses: actions/upload-artifact@v4
|
|
31
|
+
with:
|
|
32
|
+
name: python-package-distributions
|
|
33
|
+
path: dist/
|
|
34
|
+
|
|
35
|
+
publish-to-pypi:
|
|
36
|
+
name: Publish to PyPI
|
|
37
|
+
needs: build
|
|
38
|
+
runs-on: ubuntu-latest
|
|
39
|
+
if: startsWith(github.ref, 'refs/tags/v')
|
|
40
|
+
environment:
|
|
41
|
+
name: release
|
|
42
|
+
url: https://pypi.org/p/kajenn-db
|
|
43
|
+
permissions:
|
|
44
|
+
id-token: write # REQUIRED for Trusted Publisher
|
|
45
|
+
|
|
46
|
+
steps:
|
|
47
|
+
- name: Download distribution artifacts
|
|
48
|
+
uses: actions/download-artifact@v4
|
|
49
|
+
with:
|
|
50
|
+
name: python-package-distributions
|
|
51
|
+
path: dist/
|
|
52
|
+
|
|
53
|
+
- name: Publish to PyPI
|
|
54
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
55
|
+
|
|
56
|
+
github-release:
|
|
57
|
+
name: Create GitHub Release
|
|
58
|
+
needs: publish-to-pypi
|
|
59
|
+
runs-on: ubuntu-latest
|
|
60
|
+
if: startsWith(github.ref, 'refs/tags/v')
|
|
61
|
+
permissions:
|
|
62
|
+
contents: write # REQUIRED to create releases
|
|
63
|
+
|
|
64
|
+
steps:
|
|
65
|
+
- uses: actions/checkout@v4
|
|
66
|
+
|
|
67
|
+
- name: Download distribution artifacts
|
|
68
|
+
uses: actions/download-artifact@v4
|
|
69
|
+
with:
|
|
70
|
+
name: python-package-distributions
|
|
71
|
+
path: dist/
|
|
72
|
+
|
|
73
|
+
- name: Create GitHub Release
|
|
74
|
+
env:
|
|
75
|
+
GITHUB_TOKEN: ${{ github.token }}
|
|
76
|
+
run: |
|
|
77
|
+
gh release create '${{ github.ref_name }}' \
|
|
78
|
+
--repo='${{ github.repository }}' \
|
|
79
|
+
--title='${{ github.ref_name }}' \
|
|
80
|
+
--generate-notes \
|
|
81
|
+
dist/*
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
name: Tests
|
|
2
|
+
|
|
3
|
+
"on":
|
|
4
|
+
push:
|
|
5
|
+
branches: ['main']
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: ['main']
|
|
8
|
+
workflow_dispatch:
|
|
9
|
+
# Daily run against the latest kajenn and backend releases: a change
|
|
10
|
+
# published upstream surfaces here without a push.
|
|
11
|
+
schedule:
|
|
12
|
+
- cron: '0 5 * * *'
|
|
13
|
+
|
|
14
|
+
jobs:
|
|
15
|
+
test:
|
|
16
|
+
name: pytest + ruff (Linux/glibc)
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
permissions:
|
|
19
|
+
contents: read
|
|
20
|
+
timeout-minutes: 15
|
|
21
|
+
services:
|
|
22
|
+
postgres:
|
|
23
|
+
image: postgres:16
|
|
24
|
+
env:
|
|
25
|
+
POSTGRES_PASSWORD: postgres
|
|
26
|
+
ports:
|
|
27
|
+
- 5432:5432
|
|
28
|
+
options: >-
|
|
29
|
+
--health-cmd pg_isready
|
|
30
|
+
--health-interval 5s
|
|
31
|
+
--health-timeout 5s
|
|
32
|
+
--health-retries 10
|
|
33
|
+
env:
|
|
34
|
+
GNR_TEST_PG_HOST: 127.0.0.1
|
|
35
|
+
GNR_TEST_PG_PORT: '5432'
|
|
36
|
+
GNR_TEST_PG_USER: postgres
|
|
37
|
+
GNR_TEST_PG_PASSWORD: postgres
|
|
38
|
+
steps:
|
|
39
|
+
- uses: actions/checkout@v4
|
|
40
|
+
|
|
41
|
+
- name: Set up Python
|
|
42
|
+
uses: actions/setup-python@v5
|
|
43
|
+
with:
|
|
44
|
+
python-version: '3.11'
|
|
45
|
+
|
|
46
|
+
- name: Install project with all extras
|
|
47
|
+
run: |
|
|
48
|
+
python -m pip install --upgrade pip
|
|
49
|
+
pip install ".[dev,asqueel,sqlalchemy,django]"
|
|
50
|
+
|
|
51
|
+
- name: Ruff
|
|
52
|
+
run: ruff check src/ tests/
|
|
53
|
+
|
|
54
|
+
- name: Tests
|
|
55
|
+
run: pytest tests/
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Read the Docs configuration for kajenn-db.
|
|
2
|
+
# https://docs.readthedocs.io/en/stable/config-file/v2.html
|
|
3
|
+
|
|
4
|
+
version: 2
|
|
5
|
+
|
|
6
|
+
build:
|
|
7
|
+
os: ubuntu-24.04
|
|
8
|
+
tools:
|
|
9
|
+
python: "3.12"
|
|
10
|
+
|
|
11
|
+
sphinx:
|
|
12
|
+
configuration: docs/conf.py
|
|
13
|
+
fail_on_warning: true
|
|
14
|
+
|
|
15
|
+
python:
|
|
16
|
+
install:
|
|
17
|
+
- method: pip
|
|
18
|
+
path: .
|
|
19
|
+
extra_requirements:
|
|
20
|
+
- docs
|
|
21
|
+
- asqueel
|
|
22
|
+
- sqlalchemy
|
|
23
|
+
- django
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to kajenn-db are recorded here. The format follows
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/); versions follow
|
|
5
|
+
[Semantic Versioning](https://semver.org/).
|
|
6
|
+
|
|
7
|
+
## [0.1.0] — 2026-10-27
|
|
8
|
+
|
|
9
|
+
First release. Requires `kajenn>=0.6.0`, the first kajenn with the
|
|
10
|
+
`DbHandlerBase` contract.
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- `kajenn_db.asqueel.AsqueelDbHandler` (extra `[asqueel]`, asqueel 0.9): one
|
|
15
|
+
`AsqueelDb` per database, built from `source`, `parents` and `db_class`; one
|
|
16
|
+
main `SessionDb` per name per call; the end of the call closes the call's
|
|
17
|
+
named sessions, then the main one.
|
|
18
|
+
- The asqueel async view: session, table, query and cursor levels, with
|
|
19
|
+
awaitable terminals run on the server pool and blocked methods that name
|
|
20
|
+
what to use instead.
|
|
21
|
+
- `AsqueelDbHandler.migration_plan(name)` and `migrate(name)`, tested on
|
|
22
|
+
PostgreSQL and SQLite.
|
|
23
|
+
- `kajenn_db.sqlalchemy.SqlAlchemyDbHandler` (extra `[sqlalchemy]`), a probe:
|
|
24
|
+
one `Engine` per database, one `Session` per call, kajenn's `AsyncDbView`
|
|
25
|
+
over the same `Session` for async routes; no migration.
|
|
26
|
+
- `kajenn_db.django.DjangoDbHandler` (extra `[django]`), a probe:
|
|
27
|
+
`connections[alias]` per call, closed at the end of the call; sync routes
|
|
28
|
+
only; `migration_plan(name)` and `migrate(name)`.
|
|
29
|
+
- A contract suite that runs kajenn's handler contract on every installed
|
|
30
|
+
backend.
|
|
31
|
+
|
|
32
|
+
### Known limits
|
|
33
|
+
|
|
34
|
+
- A session opens with no environment: `currentUser` is `None`.
|
|
35
|
+
- Rows as asqueel returns them do not survive kajenn's JSON serialisation:
|
|
36
|
+
convert them in the route.
|
|
37
|
+
- The Django probe cannot serve `async def` routes: kajenn takes their
|
|
38
|
+
databases on the event-loop thread, and Django binds a connection to its
|
|
39
|
+
thread.
|
kajenn_db-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2025 Softwell S.r.l.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
kajenn_db-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: kajenn-db
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Database handlers for kajenn: asqueel, with SQLAlchemy and Django probes
|
|
5
|
+
Project-URL: Repository, https://github.com/kajenn-org/kajenn-db
|
|
6
|
+
Project-URL: Documentation, https://kajenn-db.readthedocs.io
|
|
7
|
+
Author-email: Genropy Team <info@softwell.it>
|
|
8
|
+
License: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: asgi,asqueel,database,kajenn
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Framework :: AsyncIO
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: Database
|
|
20
|
+
Requires-Python: >=3.11
|
|
21
|
+
Requires-Dist: kajenn>=0.6.0
|
|
22
|
+
Provides-Extra: asqueel
|
|
23
|
+
Requires-Dist: asqueel[migration,postgresql]<0.10,>=0.9; extra == 'asqueel'
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
|
|
26
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
27
|
+
Requires-Dist: ruff>=0.1.0; extra == 'dev'
|
|
28
|
+
Provides-Extra: django
|
|
29
|
+
Requires-Dist: django>=4.2; extra == 'django'
|
|
30
|
+
Provides-Extra: docs
|
|
31
|
+
Requires-Dist: myst-parser>=2.0; extra == 'docs'
|
|
32
|
+
Requires-Dist: sphinx-rtd-theme>=2.0; extra == 'docs'
|
|
33
|
+
Requires-Dist: sphinx>=7.0; extra == 'docs'
|
|
34
|
+
Provides-Extra: sqlalchemy
|
|
35
|
+
Requires-Dist: sqlalchemy>=2.0.22; extra == 'sqlalchemy'
|
|
36
|
+
Description-Content-Type: text/markdown
|
|
37
|
+
|
|
38
|
+
# kajenn-db
|
|
39
|
+
|
|
40
|
+
Database handlers for [kajenn](https://github.com/kajenn-org/kajenn): the
|
|
41
|
+
implementations of kajenn's `DbHandlerBase` contract, one module per backend.
|
|
42
|
+
|
|
43
|
+
- `kajenn_db.asqueel.AsqueelDbHandler` — [asqueel](https://pypi.org/project/asqueel/) 0.9.
|
|
44
|
+
- `kajenn_db.sqlalchemy.SqlAlchemyDbHandler` — SQLAlchemy 2, a probe.
|
|
45
|
+
- `kajenn_db.django.DjangoDbHandler` — Django, a probe.
|
|
46
|
+
|
|
47
|
+
The probes are incomplete by declaration: they run kajenn's handler contract
|
|
48
|
+
on another backend and stop there (see [Probes](#probes)).
|
|
49
|
+
|
|
50
|
+
## Install
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pip install kajenn-db[asqueel]
|
|
54
|
+
pip install kajenn-db[sqlalchemy]
|
|
55
|
+
pip install kajenn-db[django]
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Importing a backend module without its extra raises an `ImportError` that
|
|
59
|
+
names the command above.
|
|
60
|
+
|
|
61
|
+
## Declare an asqueel database
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
from kajenn import AsgiServer
|
|
65
|
+
from kajenn.config import AsgiConfigBuilder
|
|
66
|
+
from kajenn_db.asqueel import AsqueelDbHandler
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
class Configuration(AsgiConfigBuilder):
|
|
70
|
+
default_config = False
|
|
71
|
+
|
|
72
|
+
def main(self, root):
|
|
73
|
+
cfg = root.configuration()
|
|
74
|
+
dbs = cfg.databases(handler_class=AsqueelDbHandler)
|
|
75
|
+
dbs.database(code="default", source="shop.xml")
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Each database accepts:
|
|
79
|
+
|
|
80
|
+
- `source` — anything `AsqueelDb(source, parents=...)` accepts: a recipe, a
|
|
81
|
+
registered name, a file, a `db` node.
|
|
82
|
+
- `parents` — passed to `AsqueelDb` as it is.
|
|
83
|
+
- `db_class` — an `AsqueelDb` subclass to build instead of `AsqueelDb`.
|
|
84
|
+
|
|
85
|
+
The server builds one `AsqueelDbHandler` and hands it every database declared
|
|
86
|
+
with it. No database is opened at declaration time.
|
|
87
|
+
|
|
88
|
+
## One session per call
|
|
89
|
+
|
|
90
|
+
- `request.db(name)` takes the main `SessionDb` of the call (`db.session()`),
|
|
91
|
+
once per name per call.
|
|
92
|
+
- At the end of the call the handler closes the named sessions of the call,
|
|
93
|
+
then the main one. Work not committed is rolled back, and asqueel logs a
|
|
94
|
+
warning.
|
|
95
|
+
- In 0.1.0 a session opens with no environment: `currentUser` is `None`, and
|
|
96
|
+
`workdate` and `locale` take asqueel's defaults.
|
|
97
|
+
|
|
98
|
+
## Async routes
|
|
99
|
+
|
|
100
|
+
An `async def` route takes `request.async_db(name)`: the async view of the same
|
|
101
|
+
main `SessionDb`. Its I/O methods are awaitable and run on the server pool, so
|
|
102
|
+
the event loop keeps serving other calls.
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
@route()
|
|
106
|
+
async def add(self, _request=None):
|
|
107
|
+
db = _request.async_db()
|
|
108
|
+
notes = db.table("app.note")
|
|
109
|
+
await notes.insert({"id": "n1", "text": "first"})
|
|
110
|
+
await db.commit()
|
|
111
|
+
return await notes.query(columns="$id").fetchPkeys()
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
The view has three levels, plus the cursor:
|
|
115
|
+
|
|
116
|
+
- session — awaitable: `execute`, `executemany`, `commit`, `rollback`,
|
|
117
|
+
`vacuum`, `analyze`. `table(name)` and `session(name)` return views.
|
|
118
|
+
- table — awaitable: `insert`, `update`, `delete`, `insertOrUpdate`, `lock`.
|
|
119
|
+
`query(...)` returns a view.
|
|
120
|
+
- query — awaitable: `fetch`, `fetchRecord`, `fetchPkeys`, `fetchAsJson`,
|
|
121
|
+
`fetchAsDict`, `fetchAsBag`, `fetchGrouped`, `count`, `delete`, `update`,
|
|
122
|
+
`execute`, `cursor`.
|
|
123
|
+
- cursor — returned by `execute` and `cursor`; awaitable: `fetchone`,
|
|
124
|
+
`fetchmany`, `fetchall`, `close`.
|
|
125
|
+
|
|
126
|
+
Every other I/O method raises `UnsupportedFeatureError` on the view, naming
|
|
127
|
+
what to use instead: `iterfetch` and `serverfetch` name `cursor()`; `close`
|
|
128
|
+
belongs to the end of the call; `migrate` and `migration_plan` belong to the
|
|
129
|
+
handler. Methods that do no I/O pass through as asqueel has them.
|
|
130
|
+
|
|
131
|
+
Rules:
|
|
132
|
+
|
|
133
|
+
- In an async route, never call a `SessionDb` method on `request.db()`: it
|
|
134
|
+
runs on the event loop and blocks every other call, with no error.
|
|
135
|
+
- Consume a cursor before the call ends: the end of the call closes the
|
|
136
|
+
session, and the cursor with it.
|
|
137
|
+
- A streaming response that reads a cursor registers the release after its
|
|
138
|
+
last chunk.
|
|
139
|
+
- `query(...).fetch()` loads every row in memory. For large results, read a
|
|
140
|
+
server-side cursor (`cursorname`) in chunks.
|
|
141
|
+
|
|
142
|
+
## Serialising rows
|
|
143
|
+
|
|
144
|
+
kajenn serialises a `dict`/`list` result with `genro_tytx.json_dumps`
|
|
145
|
+
(genro-tytx 0.16.4). Rows returned as asqueel gives them do not survive it:
|
|
146
|
+
|
|
147
|
+
- a row of `fetch()` or `fetchAsDict()` (`NamedList`) becomes a bare list of
|
|
148
|
+
values: the column names are lost;
|
|
149
|
+
- `date`, `datetime`, `Decimal` and `UUID` values raise `TypeError`.
|
|
150
|
+
|
|
151
|
+
Convert in the route: `dict(row.items())` keeps the column names, and the
|
|
152
|
+
values of those four types need converting too. `fetchAsJson()` returns the
|
|
153
|
+
JSON text itself: kajenn serves a `str` result as `text/plain`. The handler
|
|
154
|
+
converts nothing, so a query gives the same types in a sync and in an async
|
|
155
|
+
route.
|
|
156
|
+
|
|
157
|
+
## Probes
|
|
158
|
+
|
|
159
|
+
### SQLAlchemy
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
from kajenn_db.sqlalchemy import SqlAlchemyDbHandler
|
|
163
|
+
|
|
164
|
+
dbs = cfg.databases(handler_class=SqlAlchemyDbHandler)
|
|
165
|
+
dbs.database(code="default", url="sqlite:///shop.sqlite")
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
- `url` — the SQLAlchemy database URL; one shared `Engine` per database,
|
|
169
|
+
disposed at server shutdown.
|
|
170
|
+
- `request.db(name)` takes a `Session` of the call; the end of the call closes
|
|
171
|
+
it, and a closed `Session` refuses any further use.
|
|
172
|
+
- `request.async_db(name)` is kajenn's `AsyncDbView` over the same `Session`,
|
|
173
|
+
so one call has one transaction in a sync and in an async route. Awaitable:
|
|
174
|
+
`execute`, `scalars`, `scalar`, `get`, `get_one`, `merge`, `flush`,
|
|
175
|
+
`refresh`, `commit`, `rollback`. Every other attribute passes through as it
|
|
176
|
+
is, I/O included: `query()` and its `Query.all()`, `delete()`, `connection()`
|
|
177
|
+
and `begin()` run on the event loop and block it, with no error. Unlike the
|
|
178
|
+
asqueel view, the probe refuses nothing.
|
|
179
|
+
- A `Result` reads its rows from the cursor when it is iterated, on the event
|
|
180
|
+
loop: keep the results of an async route small.
|
|
181
|
+
- No `migrate`: SQLAlchemy has no migration of its own (Alembic is a separate
|
|
182
|
+
tool).
|
|
183
|
+
|
|
184
|
+
### Django
|
|
185
|
+
|
|
186
|
+
```python
|
|
187
|
+
from kajenn_db.django import DjangoDbHandler
|
|
188
|
+
|
|
189
|
+
dbs = cfg.databases(handler_class=DjangoDbHandler)
|
|
190
|
+
dbs.database(code="default", alias="default")
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
- Django is configured by the process (`DJANGO_SETTINGS_MODULE` or
|
|
194
|
+
`settings.configure()`, then `django.setup()`), not by the handler.
|
|
195
|
+
- `alias` — a key of Django's `DATABASES`; the database's own name by default.
|
|
196
|
+
- `request.db(name)` takes `connections[alias]`, the connection Django's ORM
|
|
197
|
+
uses on the calling thread: the ORM in a sync route works on it. The end of
|
|
198
|
+
the call closes it on the same thread.
|
|
199
|
+
- Sync routes only. Django binds a connection to the thread that opened it,
|
|
200
|
+
and kajenn takes a database of an `async def` route on the event-loop
|
|
201
|
+
thread: `request.async_db(name)` raises `NotImplementedError`. An async route
|
|
202
|
+
uses Django's async ORM, whose connections kajenn does not release.
|
|
203
|
+
- Not for sync work outside a route either: a task, a kbus call or a WSX
|
|
204
|
+
message takes the connection on one pool thread, and kajenn releases it with
|
|
205
|
+
`server.run_sync`, possibly on another. Django refuses to close it there
|
|
206
|
+
(`DatabaseError`, logged by kajenn) and the connection stays open on the
|
|
207
|
+
thread that opened it.
|
|
208
|
+
- `migration_plan(name)` lists the migrations not yet applied, as
|
|
209
|
+
`app_label.name`; `migrate(name)` applies them (`manage.py migrate
|
|
210
|
+
--database alias`). Both are sync and close the calling thread's connection
|
|
211
|
+
at the end.
|