maleo-foundation 0.0.21__tar.gz → 0.0.22__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 (59) hide show
  1. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/PKG-INFO +1 -1
  2. maleo_foundation-0.0.22/maleo_foundation/query.py +81 -0
  3. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation.egg-info/PKG-INFO +1 -1
  4. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation.egg-info/SOURCES.txt +1 -0
  5. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/pyproject.toml +1 -1
  6. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/README.md +0 -0
  7. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/__init__.py +0 -0
  8. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/clients/__init__.py +0 -0
  9. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/clients/general/__init__.py +0 -0
  10. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/clients/general/http.py +0 -0
  11. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/clients/google/__init__.py +0 -0
  12. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/clients/google/cloud/__init__.py +0 -0
  13. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/clients/google/cloud/logging.py +0 -0
  14. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/clients/google/cloud/secret.py +0 -0
  15. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/clients/google/cloud/storage.py +0 -0
  16. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/constants.py +0 -0
  17. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/controller.py +0 -0
  18. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/db/__init__.py +0 -0
  19. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/db/database.py +0 -0
  20. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/db/engine.py +0 -0
  21. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/db/session.py +0 -0
  22. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/middlewares/__init__.py +0 -0
  23. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/middlewares/base.py +0 -0
  24. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/middlewares/cors.py +0 -0
  25. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/models/__init__.py +0 -0
  26. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/models/enums.py +0 -0
  27. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/models/responses.py +0 -0
  28. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/models/schemas/__init__.py +0 -0
  29. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/models/schemas/general.py +0 -0
  30. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/models/schemas/parameter.py +0 -0
  31. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/models/schemas/result.py +0 -0
  32. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/models/transfers/__init__.py +0 -0
  33. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/models/transfers/parameters/__init__.py +0 -0
  34. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/models/transfers/parameters/client.py +0 -0
  35. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/models/transfers/parameters/general.py +0 -0
  36. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/models/transfers/parameters/service.py +0 -0
  37. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/models/transfers/results/__init__.py +0 -0
  38. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/models/transfers/results/client/__init__.py +0 -0
  39. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/models/transfers/results/client/controllers/__init__.py +0 -0
  40. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/models/transfers/results/client/controllers/http.py +0 -0
  41. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/models/transfers/results/client/service.py +0 -0
  42. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/models/transfers/results/service/__init__.py +0 -0
  43. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/models/transfers/results/service/controllers/__init__.py +0 -0
  44. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/models/transfers/results/service/controllers/rest.py +0 -0
  45. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/models/transfers/results/service/general.py +0 -0
  46. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/models/transfers/results/service/query.py +0 -0
  47. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/models/types/__init__.py +0 -0
  48. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/models/types/client.py +0 -0
  49. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/models/types/query.py +0 -0
  50. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/models/types/service.py +0 -0
  51. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/utils/__init__.py +0 -0
  52. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/utils/exceptions.py +0 -0
  53. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/utils/formatter/__init__.py +0 -0
  54. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/utils/formatter/case.py +0 -0
  55. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation/utils/logger.py +0 -0
  56. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation.egg-info/dependency_links.txt +0 -0
  57. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation.egg-info/requires.txt +0 -0
  58. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/maleo_foundation.egg-info/top_level.txt +0 -0
  59. {maleo_foundation-0.0.21 → maleo_foundation-0.0.22}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maleo_foundation
3
- Version: 0.0.21
3
+ Version: 0.0.22
4
4
  Summary: Foundation package for Maleo
5
5
  Author-email: Agra Bima Yuda <agra@nexmedis.com>
6
6
  License: MIT
@@ -0,0 +1,81 @@
1
+ from sqlalchemy import Column, Table
2
+ from sqlalchemy.orm import Query
3
+ from sqlalchemy.orm.attributes import InstrumentedAttribute
4
+ from sqlalchemy.sql.expression import or_, asc, cast, desc
5
+ from sqlalchemy.types import DATE, String, TEXT, TIMESTAMP
6
+ from typing import Optional, Type
7
+ from maleo_foundation.db import DatabaseManager
8
+ from maleo_foundation.models.enums import BaseEnums
9
+ from maleo_foundation.models.schemas.general import BaseGeneralSchemas
10
+
11
+ class BaseQuery:
12
+ @staticmethod
13
+ def filter_ids(query:Query, table:Type[DatabaseManager.Base], column:str, ids:Optional[list[int]]) -> Query:
14
+ if ids is not None:
15
+ column_attr = getattr(table, column, None)
16
+ if column_attr:
17
+ id_filters = [column_attr == id for id in ids]
18
+ query = query.filter(or_(*id_filters))
19
+ return query
20
+
21
+ @staticmethod
22
+ def filter_timestamps(query:Query, table:Type[DatabaseManager.Base], date_filters:list[BaseGeneralSchemas.DateFilter]) -> Query:
23
+ if date_filters and len(date_filters) > 0:
24
+ for date_filter in date_filters:
25
+ try:
26
+ table:Table = table.__table__
27
+ column:Column = table.columns[date_filter.name]
28
+ column_attr:InstrumentedAttribute = getattr(table, date_filter.name)
29
+ if isinstance(column.type, (TIMESTAMP, DATE)):
30
+ if date_filter.from_date and date_filter.to_date:
31
+ query = query.filter(column_attr.between(date_filter.from_date, date_filter.to_date))
32
+ elif date_filter.from_date:
33
+ query = query.filter(column_attr >= date_filter.from_date)
34
+ elif date_filter.to_date:
35
+ query = query.filter(column_attr <= date_filter.to_date)
36
+ except KeyError:
37
+ continue
38
+ return query
39
+
40
+ @staticmethod
41
+ def filter_statuses(query:Query, table:Type[DatabaseManager.Base], statuses:Optional[list[BaseEnums.StatusType]]) -> Query:
42
+ if statuses is not None:
43
+ status_filters = [table.status == status for status in statuses]
44
+ query = query.filter(or_(*status_filters))
45
+ return query
46
+
47
+ @staticmethod
48
+ def filter_search(query:Query, table:Type[DatabaseManager.Base], search:Optional[str]) -> Query:
49
+ if search:
50
+ search_term = f"%{search}%" #* Use wildcard for partial matching
51
+ search_filters = []
52
+ sqla_table:Table = table.__table__
53
+ for name, attr in vars(table).items():
54
+ try:
55
+ column: Column = sqla_table.columns[name]
56
+ if not isinstance(attr, InstrumentedAttribute):
57
+ continue
58
+ if isinstance(column.type, (String, TEXT)):
59
+ search_filters.append(cast(attr, TEXT).ilike(search_term))
60
+ except KeyError:
61
+ continue
62
+ if search_filters:
63
+ query = query.filter(or_(*search_filters))
64
+ return query
65
+
66
+ @staticmethod
67
+ def sort(query:Query, table:Type[DatabaseManager.Base], sort_columns:list[BaseGeneralSchemas.SortColumn]) -> Query:
68
+ for sort_column in sort_columns:
69
+ try:
70
+ sort_col = getattr(table, sort_column.name)
71
+ sort_col = asc(sort_col) if sort_column.order.value.lower() == "asc" else desc(sort_col)
72
+ query = query.order_by(sort_col)
73
+ except AttributeError:
74
+ continue
75
+ return query
76
+
77
+ @staticmethod
78
+ def paginate(query:Query, page:int, limit:int) -> Query:
79
+ offset:int = (page - 1) * limit #* Calculate offset based on page
80
+ query = query.limit(limit=limit).offset(offset=offset)
81
+ return query
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: maleo_foundation
3
- Version: 0.0.21
3
+ Version: 0.0.22
4
4
  Summary: Foundation package for Maleo
5
5
  Author-email: Agra Bima Yuda <agra@nexmedis.com>
6
6
  License: MIT
@@ -3,6 +3,7 @@ pyproject.toml
3
3
  maleo_foundation/__init__.py
4
4
  maleo_foundation/constants.py
5
5
  maleo_foundation/controller.py
6
+ maleo_foundation/query.py
6
7
  maleo_foundation.egg-info/PKG-INFO
7
8
  maleo_foundation.egg-info/SOURCES.txt
8
9
  maleo_foundation.egg-info/dependency_links.txt
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "maleo_foundation"
7
- version = "0.0.21"
7
+ version = "0.0.22"
8
8
  description = "Foundation package for Maleo"
9
9
  authors = [
10
10
  { name = "Agra Bima Yuda", email = "agra@nexmedis.com" }