simple-module-db 0.0.31__tar.gz → 0.0.32__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 (28) hide show
  1. {simple_module_db-0.0.31 → simple_module_db-0.0.32}/PKG-INFO +2 -2
  2. {simple_module_db-0.0.31 → simple_module_db-0.0.32}/pyproject.toml +2 -2
  3. {simple_module_db-0.0.31 → simple_module_db-0.0.32}/simple_module_db/__init__.py +4 -0
  4. simple_module_db-0.0.32/simple_module_db/search.py +32 -0
  5. {simple_module_db-0.0.31 → simple_module_db-0.0.32}/.gitignore +0 -0
  6. {simple_module_db-0.0.31 → simple_module_db-0.0.32}/LICENSE +0 -0
  7. {simple_module_db-0.0.31 → simple_module_db-0.0.32}/README.md +0 -0
  8. {simple_module_db-0.0.31 → simple_module_db-0.0.32}/simple_module_db/audit.py +0 -0
  9. {simple_module_db-0.0.31 → simple_module_db-0.0.32}/simple_module_db/base.py +0 -0
  10. {simple_module_db-0.0.31 → simple_module_db-0.0.32}/simple_module_db/deps.py +0 -0
  11. {simple_module_db-0.0.31 → simple_module_db-0.0.32}/simple_module_db/listeners.py +0 -0
  12. {simple_module_db-0.0.31 → simple_module_db-0.0.32}/simple_module_db/migrations.py +0 -0
  13. {simple_module_db-0.0.31 → simple_module_db-0.0.32}/simple_module_db/mixins.py +0 -0
  14. {simple_module_db-0.0.31 → simple_module_db-0.0.32}/simple_module_db/provider.py +0 -0
  15. {simple_module_db-0.0.31 → simple_module_db-0.0.32}/simple_module_db/py.typed +0 -0
  16. {simple_module_db-0.0.31 → simple_module_db-0.0.32}/simple_module_db/session.py +0 -0
  17. {simple_module_db-0.0.31 → simple_module_db-0.0.32}/simple_module_db/transaction.py +0 -0
  18. {simple_module_db-0.0.31 → simple_module_db-0.0.32}/tests/_audit_models.py +0 -0
  19. {simple_module_db-0.0.31 → simple_module_db-0.0.32}/tests/_models.py +0 -0
  20. {simple_module_db-0.0.31 → simple_module_db-0.0.32}/tests/conftest.py +0 -0
  21. {simple_module_db-0.0.31 → simple_module_db-0.0.32}/tests/test_audit.py +0 -0
  22. {simple_module_db-0.0.31 → simple_module_db-0.0.32}/tests/test_base.py +0 -0
  23. {simple_module_db-0.0.31 → simple_module_db-0.0.32}/tests/test_db_logging.py +0 -0
  24. {simple_module_db-0.0.31 → simple_module_db-0.0.32}/tests/test_migrations.py +0 -0
  25. {simple_module_db-0.0.31 → simple_module_db-0.0.32}/tests/test_mixins.py +0 -0
  26. {simple_module_db-0.0.31 → simple_module_db-0.0.32}/tests/test_multi_tenancy.py +0 -0
  27. {simple_module_db-0.0.31 → simple_module_db-0.0.32}/tests/test_session.py +0 -0
  28. {simple_module_db-0.0.31 → simple_module_db-0.0.32}/tests/test_transaction.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: simple_module_db
3
- Version: 0.0.31
3
+ Version: 0.0.32
4
4
  Summary: Per-module SQLModel Base, async session, standard mixins (Audit, SoftDelete, MultiTenant, Versioned) for simple_module
5
5
  Project-URL: Homepage, https://github.com/antosubash/simple_module_python
6
6
  Project-URL: Repository, https://github.com/antosubash/simple_module_python
@@ -25,7 +25,7 @@ Requires-Dist: aiosqlite>=0.20
25
25
  Requires-Dist: alembic>=1.14
26
26
  Requires-Dist: asyncpg>=0.30
27
27
  Requires-Dist: psycopg2-binary>=2.9
28
- Requires-Dist: simple-module-core==0.0.31
28
+ Requires-Dist: simple-module-core==0.0.32
29
29
  Requires-Dist: sqlalchemy[asyncio]>=2.0
30
30
  Requires-Dist: sqlmodel>=0.0.22
31
31
  Description-Content-Type: text/markdown
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "simple_module_db"
3
- version = "0.0.31"
3
+ version = "0.0.32"
4
4
  description = "Per-module SQLModel Base, async session, standard mixins (Audit, SoftDelete, MultiTenant, Versioned) for simple_module"
5
5
  readme = "README.md"
6
6
  license = "MIT"
@@ -28,7 +28,7 @@ dependencies = [
28
28
  # The async app code goes through asyncpg; migration env.py rewrites the
29
29
  # URL to +psycopg2 because Alembic's online migrations are sync-only.
30
30
  "psycopg2-binary>=2.9",
31
- "simple_module_core==0.0.31",
31
+ "simple_module_core==0.0.32",
32
32
  "sqlalchemy[asyncio]>=2.0",
33
33
  "sqlmodel>=0.0.22",
34
34
  ]
@@ -12,10 +12,12 @@ from simple_module_db.migrations import (
12
12
  )
13
13
  from simple_module_db.mixins import AuditMixin, MultiTenantMixin, SoftDeleteMixin, VersionedMixin
14
14
  from simple_module_db.provider import DatabaseProvider, detect_provider
15
+ from simple_module_db.search import LIKE_ESCAPE_CHAR, like_contains_pattern, like_prefix_pattern
15
16
  from simple_module_db.session import DatabaseState, init_db
16
17
  from simple_module_db.transaction import CommitBeforeResponseMiddleware, finalize_session
17
18
 
18
19
  __all__ = [
20
+ "LIKE_ESCAPE_CHAR",
19
21
  "AuditMixin",
20
22
  "AuditRecord",
21
23
  "CommitBeforeResponseMiddleware",
@@ -32,6 +34,8 @@ __all__ = [
32
34
  "finalize_session",
33
35
  "get_db",
34
36
  "init_db",
37
+ "like_contains_pattern",
38
+ "like_prefix_pattern",
35
39
  "make_include_object",
36
40
  "make_process_revision_directives",
37
41
  "render_item",
@@ -0,0 +1,32 @@
1
+ """Shared search-pattern helpers for LIKE/ILIKE filters."""
2
+
3
+ from __future__ import annotations
4
+
5
+ LIKE_ESCAPE_CHAR = "\\"
6
+
7
+
8
+ def _escape_like_term(term: str) -> str:
9
+ return term.replace("\\", "\\\\").replace("%", "\\%").replace("_", "\\_")
10
+
11
+
12
+ def like_contains_pattern(term: str) -> str:
13
+ """Contains-match LIKE pattern with metacharacters escaped, so a literal
14
+ ``%`` or ``_`` in a search term matches as text, not as a wildcard.
15
+
16
+ Pair with ``ilike(pattern, escape=LIKE_ESCAPE_CHAR)`` (or ``like(...)``)
17
+ so the escape character actually takes effect.
18
+ """
19
+ return f"%{_escape_like_term(term)}%"
20
+
21
+
22
+ def like_prefix_pattern(term: str) -> str:
23
+ """Prefix-match LIKE pattern with metacharacters escaped, so a literal
24
+ ``%`` or ``_`` in the prefix matches as text, not as a wildcard.
25
+
26
+ Without this, a caller-supplied prefix containing ``%`` (e.g. a
27
+ ``content_type`` family filter built from a query param) widens the match
28
+ instead of narrowing it. Pair with ``ilike(pattern,
29
+ escape=LIKE_ESCAPE_CHAR)`` (or ``like(...)``) so the escape character
30
+ actually takes effect.
31
+ """
32
+ return f"{_escape_like_term(term)}%"