python-corekit 0.6.0__py3-none-any.whl → 0.6.2__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.
- corekit/connections/sql/connection.py +25 -3
- corekit/connections/sql/operations/statements.py +12 -0
- corekit/data/__init__.py +2 -0
- corekit/data/expressions/__init__.py +2 -0
- corekit/data/expressions/comparison.py +31 -0
- corekit/data/expressions/operator.py +1 -0
- {python_corekit-0.6.0.dist-info → python_corekit-0.6.2.dist-info}/METADATA +1 -1
- {python_corekit-0.6.0.dist-info → python_corekit-0.6.2.dist-info}/RECORD +11 -11
- {python_corekit-0.6.0.dist-info → python_corekit-0.6.2.dist-info}/WHEEL +0 -0
- {python_corekit-0.6.0.dist-info → python_corekit-0.6.2.dist-info}/licenses/LICENSE +0 -0
- {python_corekit-0.6.0.dist-info → python_corekit-0.6.2.dist-info}/top_level.txt +0 -0
|
@@ -220,14 +220,36 @@ class SQLConnection(Connectable):
|
|
|
220
220
|
# Writes
|
|
221
221
|
# =============
|
|
222
222
|
|
|
223
|
-
def
|
|
223
|
+
def add(self, *items: Any) -> None:
|
|
224
224
|
"""
|
|
225
|
-
|
|
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
|
-
|
|
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
|
|
corekit/data/__init__.py
CHANGED
|
@@ -30,6 +30,7 @@ from corekit.data.expressions import (
|
|
|
30
30
|
FieldExpression,
|
|
31
31
|
GreaterThan,
|
|
32
32
|
GreaterThanOrEquals,
|
|
33
|
+
IContains,
|
|
33
34
|
IsIn,
|
|
34
35
|
LessThan,
|
|
35
36
|
LessThanOrEquals,
|
|
@@ -62,6 +63,7 @@ __all__ = [
|
|
|
62
63
|
"Comparison",
|
|
63
64
|
"Contains",
|
|
64
65
|
"Dataset",
|
|
66
|
+
"IContains",
|
|
65
67
|
"DatasetStats",
|
|
66
68
|
"Equals",
|
|
67
69
|
"Expression",
|
|
@@ -20,6 +20,7 @@ from corekit.data.expressions.comparison import (
|
|
|
20
20
|
FieldExpression,
|
|
21
21
|
GreaterThan,
|
|
22
22
|
GreaterThanOrEquals,
|
|
23
|
+
IContains,
|
|
23
24
|
IsIn,
|
|
24
25
|
LessThan,
|
|
25
26
|
LessThanOrEquals,
|
|
@@ -36,6 +37,7 @@ __all__ = [
|
|
|
36
37
|
"Comparison",
|
|
37
38
|
"Contains",
|
|
38
39
|
"Equals",
|
|
40
|
+
"IContains",
|
|
39
41
|
"Expression",
|
|
40
42
|
"FieldExpression",
|
|
41
43
|
"GreaterThan",
|
|
@@ -182,6 +182,34 @@ class Contains(Comparison):
|
|
|
182
182
|
self._reject_sql("substring match is case-sensitive in Python and LIKE is not")
|
|
183
183
|
|
|
184
184
|
|
|
185
|
+
class IContains(Comparison):
|
|
186
|
+
"""
|
|
187
|
+
Case-insensitive substring: the left side contains the right.
|
|
188
|
+
|
|
189
|
+
Python folds both sides with ``casefold``. SQL uses ``ILIKE``, which is
|
|
190
|
+
case-insensitive on PostgreSQL and compiled to ``lower`` comparisons
|
|
191
|
+
elsewhere. ``Contains`` stays case-sensitive and does not compile, because
|
|
192
|
+
LIKE would not mean the same thing.
|
|
193
|
+
"""
|
|
194
|
+
|
|
195
|
+
operator = Operator.ICONTAINS
|
|
196
|
+
|
|
197
|
+
def __call__(self, context: Any, *args: Any, **kwargs: Any) -> bool:
|
|
198
|
+
left = self.get_left(context, *args, **kwargs)
|
|
199
|
+
right = self.get_right(context, *args, **kwargs)
|
|
200
|
+
if not isinstance(left, str) or not isinstance(right, str):
|
|
201
|
+
return False
|
|
202
|
+
return right.casefold() in left.casefold()
|
|
203
|
+
|
|
204
|
+
def to_sqlalchemy(self, context: Any) -> Any:
|
|
205
|
+
if self.compares_fields:
|
|
206
|
+
self._reject_sql("the right side is a field, and ILIKE needs a value")
|
|
207
|
+
needle = self.get_right(context)
|
|
208
|
+
if not isinstance(needle, str):
|
|
209
|
+
self._reject_sql("case-insensitive substring match needs a string")
|
|
210
|
+
return self.get_left(context).ilike(f"%{needle}%")
|
|
211
|
+
|
|
212
|
+
|
|
185
213
|
class ValueExpression(Expression):
|
|
186
214
|
"""
|
|
187
215
|
Expression representing a single value to be compared.
|
|
@@ -220,6 +248,9 @@ class ValueExpression(Expression):
|
|
|
220
248
|
def contains(self, substring: Any) -> "Comparison":
|
|
221
249
|
return Contains(self, substring)
|
|
222
250
|
|
|
251
|
+
def icontains(self, substring: Any) -> "Comparison":
|
|
252
|
+
return IContains(self, substring)
|
|
253
|
+
|
|
223
254
|
def resolve(self, context: Any = None, target: Target = Target.VALUE, *args: Any, **kwargs: Any) -> Any:
|
|
224
255
|
"""
|
|
225
256
|
Resolve this literal, which is its own value for every target.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: python-corekit
|
|
3
|
-
Version: 0.6.
|
|
3
|
+
Version: 0.6.2
|
|
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=
|
|
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,19 +34,19 @@ 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=
|
|
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
|
|
41
41
|
corekit/crypto/hasher.py,sha256=KkxBM8pwaFwdUV31D-LO7Pg8bFULI5Y8rtUDTWti08w,3184
|
|
42
|
-
corekit/data/__init__.py,sha256=
|
|
42
|
+
corekit/data/__init__.py,sha256=4hBzfN0gQ3wxvIdf50sXQMDOM6SmsvC_DRLlyZA7YIU,2009
|
|
43
43
|
corekit/data/dataset.py,sha256=TK1yAs7bNCQpV7Z16YqCzYf2Q_Vpu2IbEs1sqMMbikM,12835
|
|
44
44
|
corekit/data/record.py,sha256=EczoOvcxl-lHO1M92AjUh_5E9UQJ2qwBsiu6Yo-34gs,5233
|
|
45
45
|
corekit/data/stats.py,sha256=cRnLGgUHEz66GS1Rs7c_wr2ZVvIJ8WbKq4ifBKR_t0U,4950
|
|
46
|
-
corekit/data/expressions/__init__.py,sha256=
|
|
47
|
-
corekit/data/expressions/comparison.py,sha256=
|
|
46
|
+
corekit/data/expressions/__init__.py,sha256=9JspaJamghkPuExiZRyjK-f60Q7aYDkO8a3X4z1X7r0,1333
|
|
47
|
+
corekit/data/expressions/comparison.py,sha256=Hx4YpNI_vaUieU93MYNq4MdOw7lwY9aQ3zpTeCmLaBs,10608
|
|
48
48
|
corekit/data/expressions/expression.py,sha256=J8EVyzRjh3VZvqiJyryjHZJfp5c2KwwENVYhZo8S2aw,2126
|
|
49
|
-
corekit/data/expressions/operator.py,sha256=
|
|
49
|
+
corekit/data/expressions/operator.py,sha256=BMvGq8obCym-8XdTpqfuxDePRG_olz2FNvqhagHhoX8,930
|
|
50
50
|
corekit/data/expressions/target.py,sha256=QSl7sH1qFVUc-mL7gsasTsCahWKhHqdo0bMHt--t2m8,470
|
|
51
51
|
corekit/decorators/__init__.py,sha256=YrBcc_4wkSs7nEb3OjC7C7a8fNEvBk3RzOpD8QccHKM,83
|
|
52
52
|
corekit/decorators/exception_handling.py,sha256=p86gfvdmsmC7_va042NSoGkWrJrbLLuw0ncE131wLWU,2326
|
|
@@ -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.
|
|
189
|
-
python_corekit-0.6.
|
|
190
|
-
python_corekit-0.6.
|
|
191
|
-
python_corekit-0.6.
|
|
192
|
-
python_corekit-0.6.
|
|
188
|
+
python_corekit-0.6.2.dist-info/licenses/LICENSE,sha256=357LYxbxAQZ95q5cV-8JK6j-KNgiE6AteRodjEsm-kE,1072
|
|
189
|
+
python_corekit-0.6.2.dist-info/METADATA,sha256=-r-63dBItRnnlnDQudj-Jc98X342NSib335VnNrFzDo,15304
|
|
190
|
+
python_corekit-0.6.2.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
191
|
+
python_corekit-0.6.2.dist-info/top_level.txt,sha256=SDK4o8BoaI47E9tPbiNCbbWoc2y6N_wCjwnIEfr-GWI,8
|
|
192
|
+
python_corekit-0.6.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|