python-corekit 0.6.0__py3-none-any.whl → 0.6.1__py3-none-any.whl

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.
@@ -220,14 +220,36 @@ class SQLConnection(Connectable):
220
220
  # Writes
221
221
  # =============
222
222
 
223
- def insert(self, *items: Any) -> None:
223
+ def add(self, *items: Any) -> None:
224
224
  """
225
- Insert new rows.
225
+ Stage rows in the open transaction. Call commit to keep them.
226
226
  """
227
227
  self.require_writable()
228
228
  self._start_session()
229
229
  self.session.add_all(items)
230
- self.session.commit()
230
+
231
+ def flush(self) -> None:
232
+ """
233
+ Send staged rows to the database without ending the transaction.
234
+ """
235
+ self.require_writable()
236
+ self._start_session()
237
+ self.session.flush()
238
+
239
+ def commit(self) -> None:
240
+ """
241
+ Persist the open transaction.
242
+ """
243
+ self.require_writable()
244
+ if self._session is not None:
245
+ self._session.commit()
246
+
247
+ def insert(self, *items: Any) -> None:
248
+ """
249
+ Insert new rows.
250
+ """
251
+ self.add(*items)
252
+ self.commit()
231
253
 
232
254
  def upsert(self, *items: Any) -> None:
233
255
  """
@@ -28,12 +28,14 @@ class Select(DqlOperation):
28
28
  Select(table=User).where(Field("age") >= 18)
29
29
 
30
30
  ``limit(-1)`` means no cap. ``limit(0)`` returns no rows.
31
+ ``for_update`` locks the matching rows until the transaction ends.
31
32
  """
32
33
 
33
34
  order_by_field: Any = None
34
35
  order_by_desc: bool = False
35
36
  limit_count: int = -1
36
37
  offset_count: int = 0
38
+ for_update_lock: bool = False
37
39
 
38
40
  def order_by(self, field: Any, desc: bool = False) -> "Select":
39
41
  """
@@ -59,6 +61,13 @@ class Select(DqlOperation):
59
61
  self.offset_count = offset
60
62
  return self
61
63
 
64
+ def for_update(self) -> "Select":
65
+ """
66
+ Lock the matching rows until the transaction ends.
67
+ """
68
+ self.for_update_lock = True
69
+ return self
70
+
62
71
  def build(self) -> Any:
63
72
  """
64
73
  Produce the select statement.
@@ -77,6 +86,9 @@ class Select(DqlOperation):
77
86
  if self.limit_count >= 0:
78
87
  statement = statement.limit(self.limit_count)
79
88
 
89
+ if self.for_update_lock:
90
+ statement = statement.with_for_update()
91
+
80
92
  return statement
81
93
 
82
94
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-corekit
3
- Version: 0.6.0
3
+ Version: 0.6.1
4
4
  Summary: Shared foundations for Python projects: logging, benchmarking, registries, FastAPI application and routers, SQL statements and migrations, background tasks, ETL, LLM chat/tool primitives, and HTML scraping
5
5
  Author: Steven Jacobsen
6
6
  License-Expression: MIT
@@ -22,7 +22,7 @@ corekit/connections/registry.py,sha256=BR04dGthcGCtON2MxNsl-TlhRgbRlvGj0RLymDFBk
22
22
  corekit/connections/redis/__init__.py,sha256=BsWLZNqpKAqIoreHGLEtftnMqVw-ESK8jbexDAughag,174
23
23
  corekit/connections/redis/connection.py,sha256=H6r5WsDfXFgIQlp6vq3rKjp-oBFQoE5h_YaJXZEvHIs,9850
24
24
  corekit/connections/sql/__init__.py,sha256=WRBcQ9draDQSooYi4k4peWyuRTgSyEk_WwOYYOAN9K4,882
25
- corekit/connections/sql/connection.py,sha256=1ieLXssO2lyFZD9Uf_5wyM5TJmdEqYl8RzR2fMTJTlg,12410
25
+ corekit/connections/sql/connection.py,sha256=jADuzaCUxf58qs_TkRAn7ifo3zZH7Yl_yfjzHfkfVsc,12978
26
26
  corekit/connections/sql/query.py,sha256=8s5atIssmN2l9FCL2IHnIQqwxOk0fA_mPNh36koLhoE,233
27
27
  corekit/connections/sql/table.py,sha256=C7_QCRPd7C1JeH7aIByUBVWsx5qiEOFavWOo6c72djM,3125
28
28
  corekit/connections/sql/fields/__init__.py,sha256=2I-TCsvi321yQhesKNZgY1T77FtATZ6o7pw0MNHtbAo,184
@@ -34,7 +34,7 @@ corekit/connections/sql/migration/registry.py,sha256=M1iS7v7aKYfgyf_grvF-6Ogn4Kf
34
34
  corekit/connections/sql/migration/table.py,sha256=CpOkJl-4rcG2hTZYq-Yt7OvGTpVhVJ42IrubVO3BUvs,666
35
35
  corekit/connections/sql/operations/__init__.py,sha256=f6fnAbD3k8ALXwcwJ31fIHQwkvud_WqmUod_apTErpY,480
36
36
  corekit/connections/sql/operations/base.py,sha256=PQSiEz79qd_bp29K7mOh4-qQA-_Wk_r4QfL4oo3hGPY,3286
37
- corekit/connections/sql/operations/statements.py,sha256=AuJyMM-a3Kiqky_jxi2lH40a6rCeHOaesRPKJuIOGrY,4888
37
+ corekit/connections/sql/operations/statements.py,sha256=u2DSCgOUPQ4PoxpDC9x2ktgYnMGTUy0iDdL8CUJMqTU,5257
38
38
  corekit/crypto/__init__.py,sha256=Qf_FCUoG_jb7Q9tnN4ctX8I6xyaeaJwk74ag_bSchAQ,87
39
39
  corekit/crypto/constants.py,sha256=m-uq7_EJ4XfUTSZxFv6h429UkKSrGTj3o_9DfRFGyvU,298
40
40
  corekit/crypto/enum.py,sha256=0csj06cATCYDPY_QTNy66j_hB16WCqcHg8tJOO0lMNU,212
@@ -185,8 +185,8 @@ corekit/utils/text.py,sha256=0322DdZGuDGEagTyejuda6QT1jbbxNIO6loC-_AGml0,2311
185
185
  corekit/utils/time.py,sha256=-iPaETXcgDu7J39Kwe938JyZKhPVjl6a572BBqsqcDQ,2215
186
186
  corekit/utils/validators.py,sha256=_HVKo3y264KGNaZ-1RyM1x46VPvu7XKcQkrHWDC9uxs,340
187
187
  corekit/utils/void.py,sha256=eXDb2QynuguiSgHGJLdgE08MuRnxBdYebRdMD7s1m9o,178
188
- python_corekit-0.6.0.dist-info/licenses/LICENSE,sha256=357LYxbxAQZ95q5cV-8JK6j-KNgiE6AteRodjEsm-kE,1072
189
- python_corekit-0.6.0.dist-info/METADATA,sha256=YrgBgcZgbYS5eB2yhz2B-9Jvx-K3AZ9VhGt4ihLuZCs,15304
190
- python_corekit-0.6.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
191
- python_corekit-0.6.0.dist-info/top_level.txt,sha256=SDK4o8BoaI47E9tPbiNCbbWoc2y6N_wCjwnIEfr-GWI,8
192
- python_corekit-0.6.0.dist-info/RECORD,,
188
+ python_corekit-0.6.1.dist-info/licenses/LICENSE,sha256=357LYxbxAQZ95q5cV-8JK6j-KNgiE6AteRodjEsm-kE,1072
189
+ python_corekit-0.6.1.dist-info/METADATA,sha256=HXyIOMiQU418S4Kvn5SEWoOzH1FJMNoHm_zqYOvhPlU,15304
190
+ python_corekit-0.6.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
191
+ python_corekit-0.6.1.dist-info/top_level.txt,sha256=SDK4o8BoaI47E9tPbiNCbbWoc2y6N_wCjwnIEfr-GWI,8
192
+ python_corekit-0.6.1.dist-info/RECORD,,