perfact-dbutils 1.7.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.
Files changed (45) hide show
  1. perfact_dbutils-1.7.0/.gitea/workflows/check.yml +53 -0
  2. perfact_dbutils-1.7.0/.gitea/workflows/publish.yml +31 -0
  3. perfact_dbutils-1.7.0/.gitignore +23 -0
  4. perfact_dbutils-1.7.0/CLAUDE.md +59 -0
  5. perfact_dbutils-1.7.0/PKG-INFO +37 -0
  6. perfact_dbutils-1.7.0/README.md +21 -0
  7. perfact_dbutils-1.7.0/bandit.yaml +3 -0
  8. perfact_dbutils-1.7.0/debian/changelog +89 -0
  9. perfact_dbutils-1.7.0/debian/control +19 -0
  10. perfact_dbutils-1.7.0/debian/copyright +13 -0
  11. perfact_dbutils-1.7.0/debian/manpages +1 -0
  12. perfact_dbutils-1.7.0/debian/python3-perfact-dbutils.install +1 -0
  13. perfact_dbutils-1.7.0/debian/rules +16 -0
  14. perfact_dbutils-1.7.0/debian/source/format +1 -0
  15. perfact_dbutils-1.7.0/doc/source/Makefile +20 -0
  16. perfact_dbutils-1.7.0/doc/source/_static/.gitkeep +0 -0
  17. perfact_dbutils-1.7.0/doc/source/conf.py +42 -0
  18. perfact_dbutils-1.7.0/doc/source/index.rst +18 -0
  19. perfact_dbutils-1.7.0/perfact/dbutils/__init__.py +4 -0
  20. perfact_dbutils-1.7.0/perfact/dbutils/allowedclasses.py +11 -0
  21. perfact_dbutils-1.7.0/perfact/dbutils/api.py +188 -0
  22. perfact_dbutils-1.7.0/perfact/dbutils/conn.py +127 -0
  23. perfact_dbutils-1.7.0/perfact/dbutils/crud.py +427 -0
  24. perfact_dbutils-1.7.0/perfact/dbutils/genericloader.py +264 -0
  25. perfact_dbutils-1.7.0/perfact/dbutils/lcc.py +656 -0
  26. perfact_dbutils-1.7.0/perfact/dbutils/py.typed +0 -0
  27. perfact_dbutils-1.7.0/perfact/dbutils/schemainfo.py +34 -0
  28. perfact_dbutils-1.7.0/perfact/dbutils/tests/__init__.py +0 -0
  29. perfact_dbutils-1.7.0/perfact/dbutils/tests/conftest.py +27 -0
  30. perfact_dbutils-1.7.0/perfact/dbutils/tests/test_api.py +46 -0
  31. perfact_dbutils-1.7.0/perfact/dbutils/tests/test_conn.py +130 -0
  32. perfact_dbutils-1.7.0/perfact/dbutils/tests/test_crud.py +351 -0
  33. perfact_dbutils-1.7.0/perfact/dbutils/tests/test_genericloader.py +307 -0
  34. perfact_dbutils-1.7.0/perfact/dbutils/tests/test_genericloader_setup.sql +52 -0
  35. perfact_dbutils-1.7.0/perfact/dbutils/tests/test_lcc.py +986 -0
  36. perfact_dbutils-1.7.0/perfact/dbutils/tests/test_lcc_setup.sql +65 -0
  37. perfact_dbutils-1.7.0/perfact/dbutils/tests/test_schemainfo.py +60 -0
  38. perfact_dbutils-1.7.0/perfact_dbutils.egg-info/PKG-INFO +37 -0
  39. perfact_dbutils-1.7.0/perfact_dbutils.egg-info/SOURCES.txt +44 -0
  40. perfact_dbutils-1.7.0/perfact_dbutils.egg-info/dependency_links.txt +1 -0
  41. perfact_dbutils-1.7.0/perfact_dbutils.egg-info/requires.txt +4 -0
  42. perfact_dbutils-1.7.0/perfact_dbutils.egg-info/top_level.txt +1 -0
  43. perfact_dbutils-1.7.0/pyproject.toml +47 -0
  44. perfact_dbutils-1.7.0/setup.cfg +38 -0
  45. perfact_dbutils-1.7.0/tox.ini +35 -0
@@ -0,0 +1,53 @@
1
+ name: Build Package
2
+ on:
3
+ push:
4
+ branches:
5
+ - 'main'
6
+ pull_request: {}
7
+
8
+ jobs:
9
+ build:
10
+ strategy:
11
+ matrix:
12
+ target: ['jammy', 'bookworm', 'trixie']
13
+ runs-on: perfact-build-${{ matrix.target }}
14
+ steps:
15
+ - name: Checkout Repository
16
+ uses: actions/checkout@v3
17
+ - name: Change owner of build output Folder
18
+ run: sudo chown build:build /workspace/DebianPackages/ && echo OK!
19
+
20
+ - name: Update NMU changelog
21
+ run: |
22
+ echo Setting environment Variables
23
+ export DEBFULLNAME=${{ github.actor }}
24
+ echo Debian Fullname: $DEBFULLNAME
25
+ export DEBEMAIL=${{ github.actor }}@perfact.de
26
+ echo Debian Email: $DEBEMAIL
27
+ debchange --nmu Automated build on commit: ${{ gitea.sha }}
28
+
29
+ - name: Update package sources
30
+ run: sudo apt update || true
31
+
32
+ - name: Install build dependencies
33
+ run: sudo apt build-dep -y .
34
+
35
+ - name: Build
36
+ run: dpkg-buildpackage
37
+
38
+ - name: Collect result files
39
+ run: |
40
+ rm -rf /workspace/outputs/${{ gitea.repository }}/${{ gitea.ref_name }}/${{ matrix.target }}/
41
+ mkdir -p /workspace/outputs/${{ gitea.repository }}/${{ gitea.ref_name }}/${{ matrix.target }}
42
+ cp /workspace/DebianPackages/*.buildinfo /workspace/outputs/${{ gitea.repository }}/${{ gitea.ref_name }}/${{ matrix.target }}/
43
+ cp /workspace/DebianPackages/*.changes /workspace/outputs/${{ gitea.repository }}/${{ gitea.ref_name }}/${{ matrix.target }}/
44
+ cp /workspace/DebianPackages/*.deb /workspace/outputs/${{ gitea.repository }}/${{ gitea.ref_name }}/${{ matrix.target }}/
45
+ cp /workspace/DebianPackages/*.dsc /workspace/outputs/${{ gitea.repository }}/${{ gitea.ref_name }}/${{ matrix.target }}/
46
+ cp /workspace/DebianPackages/*.tar.xz /workspace/outputs/${{ gitea.repository }}/${{ gitea.ref_name }}/${{ matrix.target }}/
47
+
48
+ - name: Output the result as artifact
49
+ uses: actions/upload-artifact@v3
50
+ with:
51
+ name: ${{ matrix.target }}
52
+ path: /workspace/outputs/${{ gitea.repository }}/${{ gitea.ref_name }}/${{ matrix.target }}/
53
+ overwrite: true
@@ -0,0 +1,31 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "[0-9]*"
7
+
8
+ jobs:
9
+ publish:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v4
13
+ with:
14
+ fetch-depth: 0
15
+
16
+ - name: Set up Python
17
+ uses: actions/setup-python@v5
18
+ with:
19
+ python-version: "3.x"
20
+
21
+ - name: Install build dependencies
22
+ run: python -m pip install --upgrade build twine
23
+
24
+ - name: Build package
25
+ run: python -m build
26
+
27
+ - name: Publish to PyPI
28
+ env:
29
+ TWINE_USERNAME: __token__
30
+ TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
31
+ run: twine upload dist/*
@@ -0,0 +1,23 @@
1
+ *.pyc
2
+ *.swp
3
+ perfact_dbutils.egg-info
4
+ venv*
5
+ doc/source/api
6
+ .tox
7
+ .coverage
8
+ __pycache__
9
+ build
10
+ dist
11
+ .temp-venv
12
+ .wheels
13
+ debian/python3-perfact-dbutils
14
+ debian/*.debhelper
15
+ debian/*.debhelper.log
16
+ debian/debhelper-build-stamp
17
+ debian/files
18
+ debian/*.substvars
19
+ tags
20
+ tags.lock
21
+ tags.temp
22
+ .pybuild
23
+ *.orig
@@ -0,0 +1,59 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Commands
6
+
7
+ ```bash
8
+ # Run all checks (lint, security, tests, types, docs)
9
+ tox
10
+
11
+ # Individual checks
12
+ ruff check perfact # Lint
13
+ ruff format --check perfact # Format check
14
+ ruff format perfact # Auto-format
15
+ mypy perfact # Type check
16
+ bandit --configfile bandit.yaml -r perfact # Security scan
17
+
18
+ # Tests (requires a running PostgreSQL instance)
19
+ pytest --doctest-modules --cov-branch --cov=perfact --cov-fail-under=100 --cov-report=term-missing
20
+
21
+ # Run a single test file
22
+ pytest perfact/dbutils/tests/test_crud.py
23
+
24
+ # Run a single test by name
25
+ pytest -k "test_create"
26
+ ```
27
+
28
+ **100% code coverage is enforced** — adding code without tests will fail the test run.
29
+
30
+ ## Architecture
31
+
32
+ The library (`perfact/dbutils/`) provides PostgreSQL database utilities usable from both plain Python and Zope environments.
33
+
34
+ ### Module Overview
35
+
36
+ - **`api.py`** — Core type definitions and context objects. `Context` is the central object passed through the library: it bundles a database connection (`conn`), a `User`, an `LCC` config, and optional hooks. `User` carries role/permission info. Protocol types (`CodedHook`, `MayHook`, `CodedHooksResolver`, `SelfilterGenerator`) define the hook interfaces used by `lcc.py`.
37
+
38
+ - **`conn.py`** — Database connection wrappers. `Connection` wraps a psycopg2 connection; `ZRDBConnectionWrapper` wraps Zope ZRDB connections. Both implement the `Executor` protocol exposing a unified `execute()` method. Query results are returned as `Results` dataclass instances with `.dicts()` and `.rows()` helpers.
39
+
40
+ - **`crud.py`** — CRUD operations (`create`, `read`, `update`, `delete`) built on parameterized SQL via psycopg2's `sql` module. `update()` has an optional audit mode that writes `author`/`modtime` fields. All query construction is internal; callers pass table names, column dicts, and filter conditions.
41
+
42
+ - **`lcc.py`** — Lifecycle/state transition management. `perform_transition()` runs a state change with pre/post hooks resolved via `collect_hooks()`. Side effects are loaded from the database. Transitions are logged to `*lch` tables. `transition_with_hooks()` is the main entry point for callers.
43
+
44
+ - **`schemainfo.py`** — Schema introspection. `get_columns()` queries `information_schema` to list columns for a given table.
45
+
46
+ - **`conn.py` (`wrap_zrdbconn_sqasession`)** — Also exposes a SQLAlchemy `Session` wrapper. SQLAlchemy is an optional dependency; importing the module succeeds without it, but calling `wrap_zrdbconn_sqasession()` raises `ImportError` if SQLAlchemy is not installed.
47
+
48
+ ### Key Dependency Flow
49
+
50
+ ```
51
+ Callers → Context (api.py)
52
+ ├── conn.py (Executor / Connection / ZRDBConnectionWrapper)
53
+ ├── crud.py (uses conn.execute internally)
54
+ └── lcc.py (uses crud + conn, resolves hooks from api.py protocols)
55
+ ```
56
+
57
+ ### Testing
58
+
59
+ Tests live in `perfact/dbutils/tests/`. Integration tests use `pytest-postgresql` to spin up a real PostgreSQL instance via fixtures in `conftest.py`. There are no mocked database tests — all DB tests run against a real Postgres connection.
@@ -0,0 +1,37 @@
1
+ Metadata-Version: 2.4
2
+ Name: perfact-dbutils
3
+ Version: 1.7.0
4
+ Summary: Basic tools for interacting with the database
5
+ Author: Viktor Dick
6
+ Author-email: Viktor Dick <viktor.dick@perfact.de>, Alexander Rolfes <alexander.rolfes@perfact.de>, Ján Jockusch <jan.jockusch@perfact.de>
7
+ License: GPL-2.0-or-later
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Operating System :: POSIX :: Linux
10
+ Classifier: Topic :: Database
11
+ Requires-Python: >=3.8
12
+ Description-Content-Type: text/markdown
13
+ Requires-Dist: psycopg2
14
+ Provides-Extra: sqlalchemy
15
+ Requires-Dist: sqlalchemy; extra == "sqlalchemy"
16
+
17
+ # Basic tools for interacting with the database
18
+
19
+ This module provides tools for interacting with a database connection that are
20
+ usable both from Zope and other modules.
21
+
22
+ As a first step, it has a Connection class that provides a unified execute
23
+ method as well as a wrapper that can be used to pass a ZRDBConnection from Zope
24
+ to obtain a similar class. Future increments will include CRUD functions for
25
+ DB-Utils compatible database interactions.
26
+
27
+ # Implement and run tests
28
+
29
+ If you add new functions place your tests below `perfact/dbutils/tests`.
30
+ Implement your test using `pytest`.
31
+
32
+ You may have to install postgres if not already installed:
33
+ `sudo apt install postgresql-<version>`
34
+
35
+ Now you can run your tests by running `tox`. All tests need to succeed and your
36
+ tests need to cover 100% of the code. Tox will tell you which lines are
37
+ missing.
@@ -0,0 +1,21 @@
1
+ # Basic tools for interacting with the database
2
+
3
+ This module provides tools for interacting with a database connection that are
4
+ usable both from Zope and other modules.
5
+
6
+ As a first step, it has a Connection class that provides a unified execute
7
+ method as well as a wrapper that can be used to pass a ZRDBConnection from Zope
8
+ to obtain a similar class. Future increments will include CRUD functions for
9
+ DB-Utils compatible database interactions.
10
+
11
+ # Implement and run tests
12
+
13
+ If you add new functions place your tests below `perfact/dbutils/tests`.
14
+ Implement your test using `pytest`.
15
+
16
+ You may have to install postgres if not already installed:
17
+ `sudo apt install postgresql-<version>`
18
+
19
+ Now you can run your tests by running `tox`. All tests need to succeed and your
20
+ tests need to cover 100% of the code. Tox will tell you which lines are
21
+ missing.
@@ -0,0 +1,3 @@
1
+ # FILE: bandit.yaml
2
+ assert_used:
3
+ skips: ['*_test.py', '*test_*.py']
@@ -0,0 +1,89 @@
1
+ python-perfact-dbutils (1.7.0) unstable; urgency=medium
2
+
3
+ [ Viktor Dick ]
4
+ * Add workflow to publish to pypi
5
+
6
+ [ Alexander Rolfes ]
7
+ * Add wrapper for sqlalchemy session
8
+
9
+ -- Viktor Dick <viktor.dick@perfact.de> Tue, 12 May 2026 08:39:41 +0200
10
+
11
+ python-perfact-dbutils (1.6.0) unstable; urgency=medium
12
+
13
+ [ Kai Joshua Martin ]
14
+ * Add generic loader function load_records with advanced options like join, aliasing
15
+ and automatic addition of lookups for id cols if desired
16
+
17
+ -- Viktor Dick <viktor.dick@perfact.de> Mon, 23 Mar 2026 11:17:18 +0100
18
+
19
+ python-perfact-dbutils (1.5.0) unstable; urgency=medium
20
+
21
+ [ Kai Joshua Martin ]
22
+ * Make selfilter_generator param optional for context object
23
+
24
+ [ Viktor Dick ]
25
+ * Use ruff
26
+
27
+ -- Viktor Dick <viktor.dick@perfact.de> Wed, 11 Mar 2026 11:17:59 +0100
28
+
29
+ python-perfact-dbutils (1.4.0) unstable; urgency=medium
30
+
31
+ [ Kai Joshua Martin ]
32
+ * Extend Context class with selfilter_generator param
33
+
34
+ [ Alexander Rolfes ]
35
+ * Added marker py.typed to mark module dbutils as typed
36
+
37
+ -- Viktor Dick <viktor.dick@perfact.de> Fri, 06 Mar 2026 11:17:46 +0100
38
+
39
+ python-perfact-dbutils (1.3.0) unstable; urgency=medium
40
+
41
+ [ Kai Joshua Martin ]
42
+ * Add lcc transitions functions and tests
43
+ * Add allowedclasses module
44
+
45
+ -- Viktor Dick <viktor.dick@perfact.de> Thu, 26 Feb 2026 14:17:30 +0100
46
+
47
+ python-perfact-dbutils (1.2) unstable; urgency=medium
48
+
49
+ [ Alexander Rolfes ]
50
+ * Fix build for jammy not containing any files
51
+
52
+ -- Viktor Dick <viktor.dick@perfact.de> Wed, 18 Feb 2026 07:07:04 +0100
53
+
54
+ python-perfact-dbutils (1.1) unstable; urgency=medium
55
+
56
+ [ Kai Joshua Martin ]
57
+ * Move generated documentation into filesystem. Docs will be found in
58
+ /usr/share/doc/python3-perfact-dbutils/
59
+
60
+ -- Viktor Dick <viktor.dick@perfact.de> Fri, 30 Jan 2026 14:36:03 +0100
61
+
62
+ python-perfact-dbutils (1.0+nmu1) UNRELEASED; urgency=medium
63
+
64
+ [ Alexander Rolfes ]
65
+ * Typehints in signature is now used for the "type" documentation
66
+ parameters
67
+
68
+ -- Alexander Rolfes <alexander.rolfes@perfact.de> Thu, 29 Jan 2026 15:50:39 +0100
69
+
70
+ python-perfact-dbutils (1.0) unstable; urgency=medium
71
+
72
+ [ Kai Joshua Martin ]
73
+ * Add crud functions and tests.
74
+
75
+ -- Viktor Dick <viktor.dick@perfact.de> Mon, 26 Jan 2026 12:35:45 +0100
76
+
77
+ python-perfact-dbutils (0.2) unstable; urgency=medium
78
+
79
+ [ Viktor Dick ]
80
+ * Cover with tests
81
+
82
+ -- Viktor Dick <viktor.dick@perfact.de> Wed, 07 Jan 2026 15:57:07 +0100
83
+
84
+ python-perfact-dbutils (0.1) unstable; urgency=medium
85
+
86
+ [ Viktor Dick ]
87
+ Initial release
88
+
89
+ -- Viktor Dick <viktor.dick@perfact.de> Mon, 05 Jan 2026 09:55:34 +0100
@@ -0,0 +1,19 @@
1
+ Source: python-perfact-dbutils
2
+ Section: unknown
3
+ Priority: optional
4
+ Maintainer: Viktor Dick <viktor.dick@perfact.de>
5
+ Rules-Requires-Root: no
6
+ Build-Depends:
7
+ debhelper-compat (= 13),
8
+ python3,
9
+ pybuild-plugin-pyproject,
10
+ python3-setuptools-scm,
11
+ Standards-Version: 4.6.2
12
+
13
+ Package: python3-perfact-dbutils
14
+ Architecture: all
15
+ Depends:
16
+ ${misc:Depends},
17
+ ${python3:Depends},
18
+ python3,
19
+ Description: Basic tools for interacting with the database
@@ -0,0 +1,13 @@
1
+ Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
2
+
3
+ Files: *
4
+ Copyright: 2002-2025, PerFact Innovation GmbH & Co. KG <info@perfact.de>
5
+ License: GPL-2+
6
+
7
+ License: GPL-2+
8
+ This program is free software; you can redistribute it and/or modify
9
+ it under the terms of the GNU General Public License as published by
10
+ the Free Software Foundation; version 2 dated June, 1991, or (at
11
+ your option) any later version.
12
+ On Debian systems, the complete text of version 2 of the GNU General
13
+ Public License can be found in '/usr/share/common-licenses/GPL-2'.
@@ -0,0 +1 @@
1
+ doc/build/man/*
@@ -0,0 +1 @@
1
+ doc/build/html /usr/share/doc/python3-perfact-dbutils/
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/make -f
2
+
3
+ # See debhelper(7) (uncomment to enable).
4
+ # Output every command that modifies files on the build system.
5
+ #export DH_VERBOSE = 1
6
+
7
+ override_dh_auto_test:
8
+ tox
9
+
10
+ %:
11
+ dh $@ --with python3 --buildsystem=pybuild
12
+
13
+ override_dh_auto_build:
14
+ dh_auto_build
15
+ tox -e docs
16
+
@@ -0,0 +1 @@
1
+ 3.0 (native)
@@ -0,0 +1,20 @@
1
+ # Minimal makefile for Sphinx documentation
2
+ #
3
+
4
+ # You can set these variables from the command line, and also
5
+ # from the environment for the first two.
6
+ SPHINXOPTS ?=
7
+ SPHINXBUILD ?= sphinx-build
8
+ SOURCEDIR = .
9
+ BUILDDIR = _build
10
+
11
+ # Put it first so that "make" without argument is like "make help".
12
+ help:
13
+ @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14
+
15
+ .PHONY: help Makefile
16
+
17
+ # Catch-all target: route all unknown targets to Sphinx using the new
18
+ # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19
+ %: Makefile
20
+ @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
File without changes
@@ -0,0 +1,42 @@
1
+ # Configuration file for the Sphinx documentation builder.
2
+ #
3
+ # For the full list of built-in configuration values, see the documentation:
4
+ # https://www.sphinx-doc.org/en/master/usage/configuration.html
5
+
6
+ # -- Project information -----------------------------------------------------
7
+ # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
8
+
9
+ project = "python-perfact-dbutils"
10
+ copyright = "2026"
11
+ author = "Alexander Rolfes, Viktor Dick, Ján Jockusch"
12
+
13
+ # -- General configuration ---------------------------------------------------
14
+ # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
15
+
16
+ extensions = [
17
+ "sphinx.ext.autodoc",
18
+ "sphinx_autodoc_typehints",
19
+ "sphinx.ext.viewcode",
20
+ "sphinx.ext.todo",
21
+ "sphinx.ext.coverage",
22
+ ]
23
+
24
+ templates_path = ["_templates"]
25
+ exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
26
+
27
+ language = "en"
28
+
29
+ # -- Options for HTML output -------------------------------------------------
30
+ # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
31
+
32
+ html_theme = "sphinx_rtd_theme"
33
+ html_static_path = ["_static"]
34
+
35
+ # -- Options for todo extension ----------------------------------------------
36
+ # https://www.sphinx-doc.org/en/master/usage/extensions/todo.html#configuration
37
+
38
+ todo_include_todos = True
39
+
40
+ # -- Options for auto documentation of typehints -----------------------------
41
+
42
+ always_document_param_types = True
@@ -0,0 +1,18 @@
1
+ .. perfact documentation master file, created by
2
+ sphinx-quickstart on Fri Jan 9 12:50:21 2026.
3
+ You can adapt this file completely to your liking, but it should at least
4
+ contain the root `toctree` directive.
5
+
6
+ perfact documentation
7
+ =====================
8
+
9
+ Add your content using ``reStructuredText`` syntax. See the
10
+ `reStructuredText <https://www.sphinx-doc.org/en/master/usage/restructuredtext/index.html>`_
11
+ documentation for details.
12
+
13
+
14
+ .. toctree::
15
+ :maxdepth: 4
16
+ :caption: Contents:
17
+
18
+ api/modules
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/python3
2
+ from .conn import wrap_zrdbconn, wrap_zrdbconn_sqasession
3
+
4
+ __all__ = ["wrap_zrdbconn", "wrap_zrdbconn_sqasession"]
@@ -0,0 +1,11 @@
1
+ from .api import LCC, Context, User
2
+ from .conn import Namespace, Results, ZRDBConnectionWrapper
3
+
4
+ __all__ = [
5
+ "User",
6
+ "LCC",
7
+ "Context",
8
+ "ZRDBConnectionWrapper",
9
+ "Namespace",
10
+ "Results",
11
+ ]
@@ -0,0 +1,188 @@
1
+ from dataclasses import dataclass
2
+ from typing import Any, Callable, Optional, Protocol, TypedDict
3
+
4
+ from .conn import Executor
5
+
6
+
7
+ @dataclass
8
+ class User:
9
+ """
10
+ Class for the user object within the Context object
11
+
12
+ :param name: Name of the user
13
+ :param user_roles: List of active user roles
14
+ :param is_manager: Pointer to the function is_manager
15
+ :param user_has_role: Pointer to the function is_manager user_has_role
16
+ """
17
+
18
+ name: str
19
+ user_roles: list[str]
20
+ is_manager: Callable[[], bool]
21
+ user_has_role: Callable[[list[str]], bool]
22
+
23
+
24
+ class CodedHook(Protocol):
25
+ """
26
+ Class describing the expected signature of the coded hooks.
27
+
28
+ :param conn: DB Connector
29
+ :type conn: Executor
30
+
31
+ :param lib: Pointer to the lib functions
32
+ :type lib: Any
33
+
34
+ :param user: User object
35
+ :type user: User
36
+
37
+ :param id: Id of the record
38
+ :type id: int
39
+
40
+ :param table: Name of the table
41
+ :type table: str
42
+ """
43
+
44
+ def __call__(self, conn: Executor, id: int, table: str, **kw: Any): ...
45
+
46
+
47
+ class MayResult(TypedDict):
48
+ """The MayResult dict may be returned by may hooks"""
49
+
50
+ may: bool
51
+ """True if the lc transition is allowed. Otherwise false."""
52
+ hint: str
53
+ """May contain a hint for the user why the transition is not allowed."""
54
+
55
+
56
+ class MayHook(Protocol):
57
+ """
58
+ Class describing the expected signature of the may hooks. A may hook
59
+ function must have the following signature:
60
+
61
+ :param conn: DB Connector
62
+ :type conn: Executor
63
+
64
+ :param lib: Pointer to the lib functions
65
+ :type lib: Any
66
+
67
+ :param user: User object
68
+ :type user: User
69
+
70
+ :param id: Id of the record
71
+ :type id: int
72
+
73
+ :param table: Name of the table
74
+ :type table: str
75
+
76
+ :return: Returns true if the lc transition is allowed. May also return a
77
+ MayResult dict instead.
78
+ :rtype: bool | MayResult
79
+ """
80
+
81
+ def __call__(
82
+ self, conn: Executor, id: int, table: str, **kw
83
+ ) -> bool | MayResult: ...
84
+
85
+
86
+ class CodedHooksResolver(Protocol):
87
+ """
88
+ Class describing the signature of the coded_hooks_resolver function. The
89
+ coded hooks resolver function must have the following signature:
90
+
91
+ :param table: Name of the table
92
+ :type table: str
93
+
94
+ :param src_lc_id: ID of the source lc
95
+ :type src_lc_id: int
96
+
97
+ :param tgt_lc_id: ID of the target lc
98
+ :type tgt_lc_id: int
99
+
100
+ :param hook_name: Name of the hook
101
+ :type hook_name: str
102
+
103
+ :param hook_path: Overwrites the automatically build path. Defaults to None
104
+ :type hook_path: Optional[str]
105
+
106
+ :return: Returns a callable if the hook could be resolved
107
+ :rtype: CodedHook | MayHook | None
108
+ """
109
+
110
+ def __call__(
111
+ self,
112
+ table: str,
113
+ src_lc_id: int,
114
+ tgt_lc_id: int,
115
+ hook_name: str,
116
+ hook_path: Optional[str] = None,
117
+ ) -> CodedHook | MayHook | None: ...
118
+
119
+
120
+ @dataclass
121
+ class LCC:
122
+ """
123
+ Class for the lcc object within the Context object
124
+
125
+ :param coded_hooks_resolver: Pointer to the function that will be used to
126
+ resolve the coded hooks.
127
+ :param side_effect_resolver: Pointer to the function that will be used to
128
+ resolve the side effects.
129
+ """
130
+
131
+ coded_hooks_resolver: CodedHooksResolver
132
+ side_effect_resolver: Callable[[str], Callable]
133
+
134
+
135
+ class SelfilterGenerator(Protocol):
136
+ """
137
+ Class describing the signature of the coded_hooks_resolver function. The
138
+ coded hooks resolver function must have the following signature:
139
+
140
+ :param table: Name of the table
141
+ :type table: str
142
+
143
+ :param column: Name of the column
144
+ :type column: str
145
+
146
+ :param kw: Additonal keyword arguments
147
+ :type kw: Any
148
+
149
+ :return: Returns the selfilter for the given table and column
150
+ :rtype: str
151
+ """
152
+
153
+ def __call__(
154
+ self,
155
+ table: str,
156
+ column: str,
157
+ **kw: Any,
158
+ ) -> str: ...
159
+
160
+
161
+ def dummy_selfilter_gen(
162
+ table: str,
163
+ column: str,
164
+ **kw: Any,
165
+ ) -> str:
166
+ return ""
167
+
168
+
169
+ @dataclass
170
+ class Context:
171
+ """
172
+ Class for the ctx object
173
+
174
+ :param conn: DB connector
175
+ :param user: User object, containing information about the current user
176
+ :param lcc: LCC object, containing functions to resolve the lcc hooks
177
+ :param lib: Pointer to the lib context
178
+ :param api: Pointer to the api context
179
+ :param selfilter_generator: Pointer to a function that can generate the
180
+ selfilter for a table.
181
+ """
182
+
183
+ conn: Executor
184
+ user: User
185
+ lcc: LCC
186
+ lib: Any
187
+ api: Any
188
+ selfilter_generator: SelfilterGenerator = dummy_selfilter_gen