pjdev-postgres 4.2.1__tar.gz → 4.3.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pjdev-postgres
3
- Version: 4.2.1
3
+ Version: 4.3.0
4
4
  Project-URL: Documentation, https://gitlab.purplejay.net/keystone/python/-/tree/main/keystone-postgres/README.md
5
5
  Project-URL: Issues, https://gitlab.purplejay.net/keystone/python/-/issues
6
6
  Project-URL: Source, https://gitlab.purplejay.net/keystone/python
@@ -1,4 +1,4 @@
1
1
  # SPDX-FileCopyrightText: 2024-present Chris O'Neill <chris@purplejay.io>
2
2
  #
3
3
  # SPDX-License-Identifier: MIT
4
- __version__ = "4.2.1"
4
+ __version__ = "4.3.0"
@@ -68,12 +68,31 @@ def get_session() -> Generator[Session, Any, None]:
68
68
  yield session
69
69
 
70
70
 
71
+ def create_new(
72
+ obj: T,
73
+ session: SQLModelSession,
74
+ commit: bool = True,
75
+ user_resolver: Callable[[], Tuple[Optional[str], str]] = lambda: ('anonymous_id', 'anonymous_name'),
76
+ ) -> T:
77
+ new_obj = concurrency_service.validate_version(obj)
78
+ session.add(new_obj)
79
+ user_oid, username = user_resolver()
80
+ new_obj.created_by_id = user_oid
81
+ new_obj.created_by = username
82
+
83
+ if commit:
84
+ session.commit()
85
+ session.refresh(new_obj)
86
+
87
+ return new_obj
88
+
89
+
71
90
  def save(
72
91
  obj: T,
73
- user_resolver: Callable[[], Tuple[Optional[str], str]],
74
92
  session: SQLModelSession,
75
93
  concurrency_token: Optional[UUID] = None,
76
94
  commit: bool = True,
95
+ user_resolver: Callable[[], Tuple[Optional[str], str]] = lambda: ('anonymous_id', 'anonymous_name'),
77
96
  ) -> T:
78
97
  updated_obj = concurrency_service.validate_version(obj, concurrency_token)
79
98
  updated_obj.last_modified_datetime = datetime.now(timezone.utc)
@@ -7,4 +7,4 @@ collecting ... collected 1 item
7
7
 
8
8
  tests/tests_for_history.py::test_history_item_is_created_and_saved PASSED [100%]
9
9
 
10
- ============================== 1 passed in 1.13s ===============================
10
+ ============================== 1 passed in 1.05s ===============================
@@ -17,7 +17,7 @@ def test_history_item_is_created_and_saved():
17
17
  obj = MockTable()
18
18
  session.add(obj)
19
19
  saved_obj = postgres_service.save(
20
- obj, session=session, user_resolver=lambda: ("mock_oid", "mock_user")
20
+ obj, session=session
21
21
  )
22
22
 
23
23
  assert saved_obj.last_modified_datetime is not None
File without changes
File without changes