iceaxe 0.8.3__cp313-cp313-macosx_11_0_arm64.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.
Potentially problematic release.
This version of iceaxe might be problematic. Click here for more details.
- iceaxe/__init__.py +20 -0
- iceaxe/__tests__/__init__.py +0 -0
- iceaxe/__tests__/benchmarks/__init__.py +0 -0
- iceaxe/__tests__/benchmarks/test_bulk_insert.py +45 -0
- iceaxe/__tests__/benchmarks/test_select.py +114 -0
- iceaxe/__tests__/conf_models.py +133 -0
- iceaxe/__tests__/conftest.py +204 -0
- iceaxe/__tests__/docker_helpers.py +208 -0
- iceaxe/__tests__/helpers.py +268 -0
- iceaxe/__tests__/migrations/__init__.py +0 -0
- iceaxe/__tests__/migrations/conftest.py +36 -0
- iceaxe/__tests__/migrations/test_action_sorter.py +237 -0
- iceaxe/__tests__/migrations/test_generator.py +140 -0
- iceaxe/__tests__/migrations/test_generics.py +91 -0
- iceaxe/__tests__/mountaineer/__init__.py +0 -0
- iceaxe/__tests__/mountaineer/dependencies/__init__.py +0 -0
- iceaxe/__tests__/mountaineer/dependencies/test_core.py +76 -0
- iceaxe/__tests__/schemas/__init__.py +0 -0
- iceaxe/__tests__/schemas/test_actions.py +1265 -0
- iceaxe/__tests__/schemas/test_cli.py +25 -0
- iceaxe/__tests__/schemas/test_db_memory_serializer.py +1571 -0
- iceaxe/__tests__/schemas/test_db_serializer.py +435 -0
- iceaxe/__tests__/schemas/test_db_stubs.py +190 -0
- iceaxe/__tests__/test_alias.py +83 -0
- iceaxe/__tests__/test_base.py +52 -0
- iceaxe/__tests__/test_comparison.py +383 -0
- iceaxe/__tests__/test_field.py +11 -0
- iceaxe/__tests__/test_helpers.py +9 -0
- iceaxe/__tests__/test_modifications.py +151 -0
- iceaxe/__tests__/test_queries.py +764 -0
- iceaxe/__tests__/test_queries_str.py +173 -0
- iceaxe/__tests__/test_session.py +1511 -0
- iceaxe/__tests__/test_text_search.py +287 -0
- iceaxe/alias_values.py +67 -0
- iceaxe/base.py +351 -0
- iceaxe/comparison.py +560 -0
- iceaxe/field.py +263 -0
- iceaxe/functions.py +1432 -0
- iceaxe/generics.py +140 -0
- iceaxe/io.py +107 -0
- iceaxe/logging.py +91 -0
- iceaxe/migrations/__init__.py +5 -0
- iceaxe/migrations/action_sorter.py +98 -0
- iceaxe/migrations/cli.py +228 -0
- iceaxe/migrations/client_io.py +62 -0
- iceaxe/migrations/generator.py +404 -0
- iceaxe/migrations/migration.py +86 -0
- iceaxe/migrations/migrator.py +101 -0
- iceaxe/modifications.py +176 -0
- iceaxe/mountaineer/__init__.py +10 -0
- iceaxe/mountaineer/cli.py +74 -0
- iceaxe/mountaineer/config.py +46 -0
- iceaxe/mountaineer/dependencies/__init__.py +6 -0
- iceaxe/mountaineer/dependencies/core.py +67 -0
- iceaxe/postgres.py +133 -0
- iceaxe/py.typed +0 -0
- iceaxe/queries.py +1459 -0
- iceaxe/queries_str.py +294 -0
- iceaxe/schemas/__init__.py +0 -0
- iceaxe/schemas/actions.py +864 -0
- iceaxe/schemas/cli.py +30 -0
- iceaxe/schemas/db_memory_serializer.py +711 -0
- iceaxe/schemas/db_serializer.py +347 -0
- iceaxe/schemas/db_stubs.py +529 -0
- iceaxe/session.py +860 -0
- iceaxe/session_optimized.c +12207 -0
- iceaxe/session_optimized.cpython-313-darwin.so +0 -0
- iceaxe/session_optimized.pyx +212 -0
- iceaxe/sql_types.py +149 -0
- iceaxe/typing.py +73 -0
- iceaxe-0.8.3.dist-info/METADATA +262 -0
- iceaxe-0.8.3.dist-info/RECORD +75 -0
- iceaxe-0.8.3.dist-info/WHEEL +6 -0
- iceaxe-0.8.3.dist-info/licenses/LICENSE +21 -0
- iceaxe-0.8.3.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
from iceaxe.base import TableBase
|
|
2
|
+
from iceaxe.queries_str import QueryIdentifier, QueryLiteral, sql
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class DemoModel(TableBase):
|
|
6
|
+
field_one: str
|
|
7
|
+
field_two: int
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def test_query_identifier():
|
|
11
|
+
"""Test the QueryIdentifier class for proper SQL identifier quoting."""
|
|
12
|
+
identifier = QueryIdentifier("test_field")
|
|
13
|
+
assert str(identifier) == '"test_field"'
|
|
14
|
+
|
|
15
|
+
# Test with special characters and SQL keywords
|
|
16
|
+
identifier = QueryIdentifier("group")
|
|
17
|
+
assert str(identifier) == '"group"'
|
|
18
|
+
|
|
19
|
+
identifier = QueryIdentifier("test.field")
|
|
20
|
+
assert str(identifier) == '"test.field"'
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def test_query_literal():
|
|
24
|
+
"""Test the QueryLiteral class for raw SQL inclusion."""
|
|
25
|
+
literal = QueryLiteral("COUNT(*)")
|
|
26
|
+
assert str(literal) == "COUNT(*)"
|
|
27
|
+
|
|
28
|
+
literal = QueryLiteral("CASE WHEN x > 0 THEN 1 ELSE 0 END")
|
|
29
|
+
assert str(literal) == "CASE WHEN x > 0 THEN 1 ELSE 0 END"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def test_query_element_hashable():
|
|
33
|
+
"""Test that QueryElementBase subclasses are hashable and work in sets/dicts."""
|
|
34
|
+
# Test set behavior
|
|
35
|
+
elements = {
|
|
36
|
+
QueryIdentifier("users"),
|
|
37
|
+
QueryIdentifier("users"), # Duplicate should be removed
|
|
38
|
+
QueryIdentifier("posts"),
|
|
39
|
+
QueryLiteral("COUNT(*)"),
|
|
40
|
+
QueryLiteral("COUNT(*)"), # Duplicate should be removed
|
|
41
|
+
}
|
|
42
|
+
assert len(elements) == 3
|
|
43
|
+
assert QueryIdentifier("users") in elements
|
|
44
|
+
assert QueryLiteral("COUNT(*)") in elements
|
|
45
|
+
|
|
46
|
+
# Test dictionary behavior
|
|
47
|
+
element_map = {
|
|
48
|
+
QueryIdentifier("users"): "users table",
|
|
49
|
+
QueryLiteral("COUNT(*)"): "count function",
|
|
50
|
+
}
|
|
51
|
+
assert element_map[QueryIdentifier("users")] == "users table"
|
|
52
|
+
assert element_map[QueryLiteral("COUNT(*)")] == "count function"
|
|
53
|
+
|
|
54
|
+
# Test hash consistency with equality
|
|
55
|
+
id1 = QueryIdentifier("test")
|
|
56
|
+
id2 = QueryIdentifier("test")
|
|
57
|
+
assert id1 == id2
|
|
58
|
+
assert hash(id1) == hash(id2)
|
|
59
|
+
|
|
60
|
+
lit1 = QueryLiteral("COUNT(*)")
|
|
61
|
+
lit2 = QueryLiteral("COUNT(*)")
|
|
62
|
+
assert lit1 == lit2
|
|
63
|
+
assert hash(lit1) == hash(lit2)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def test_query_element_sortable():
|
|
67
|
+
"""Test that QueryElementBase subclasses can be sorted."""
|
|
68
|
+
# Test sorting of identifiers
|
|
69
|
+
identifiers = [
|
|
70
|
+
QueryIdentifier("users"),
|
|
71
|
+
QueryIdentifier("posts"),
|
|
72
|
+
QueryIdentifier("comments"),
|
|
73
|
+
]
|
|
74
|
+
sorted_identifiers = sorted(identifiers)
|
|
75
|
+
assert [str(literal) for literal in sorted_identifiers] == [
|
|
76
|
+
'"comments"',
|
|
77
|
+
'"posts"',
|
|
78
|
+
'"users"',
|
|
79
|
+
]
|
|
80
|
+
|
|
81
|
+
# Test sorting of literals
|
|
82
|
+
literals = [
|
|
83
|
+
QueryLiteral("SUM(*)"),
|
|
84
|
+
QueryLiteral("COUNT(*)"),
|
|
85
|
+
QueryLiteral("AVG(*)"),
|
|
86
|
+
]
|
|
87
|
+
sorted_literals = sorted(literals)
|
|
88
|
+
assert [str(literal) for literal in sorted_literals] == [
|
|
89
|
+
"AVG(*)",
|
|
90
|
+
"COUNT(*)",
|
|
91
|
+
"SUM(*)",
|
|
92
|
+
]
|
|
93
|
+
|
|
94
|
+
# Test sorting mixed elements
|
|
95
|
+
mixed = [
|
|
96
|
+
QueryIdentifier("users"),
|
|
97
|
+
QueryLiteral("COUNT(*)"),
|
|
98
|
+
QueryIdentifier("posts"),
|
|
99
|
+
]
|
|
100
|
+
sorted_mixed = sorted(mixed)
|
|
101
|
+
assert [str(literal) for literal in sorted_mixed] == [
|
|
102
|
+
'"posts"',
|
|
103
|
+
'"users"',
|
|
104
|
+
"COUNT(*)",
|
|
105
|
+
]
|
|
106
|
+
|
|
107
|
+
# Test sorting with duplicates
|
|
108
|
+
with_duplicates = [
|
|
109
|
+
QueryIdentifier("users"),
|
|
110
|
+
QueryIdentifier("posts"),
|
|
111
|
+
QueryIdentifier("users"),
|
|
112
|
+
QueryIdentifier("comments"),
|
|
113
|
+
]
|
|
114
|
+
sorted_with_duplicates = sorted(with_duplicates)
|
|
115
|
+
assert [str(literal) for literal in sorted_with_duplicates] == [
|
|
116
|
+
'"comments"',
|
|
117
|
+
'"posts"',
|
|
118
|
+
'"users"',
|
|
119
|
+
'"users"',
|
|
120
|
+
]
|
|
121
|
+
|
|
122
|
+
# Test reverse sorting
|
|
123
|
+
reverse_sorted = sorted(identifiers, reverse=True)
|
|
124
|
+
assert [str(literal) for literal in reverse_sorted] == [
|
|
125
|
+
'"users"',
|
|
126
|
+
'"posts"',
|
|
127
|
+
'"comments"',
|
|
128
|
+
]
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def test_sql_call_column():
|
|
132
|
+
"""Test SQLGenerator's __call__ method with a column."""
|
|
133
|
+
result = sql(DemoModel.field_one)
|
|
134
|
+
assert isinstance(result, QueryLiteral)
|
|
135
|
+
assert str(result) == '"demomodel"."field_one"'
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def test_sql_call_table():
|
|
139
|
+
"""Test SQLGenerator's __call__ method with a table."""
|
|
140
|
+
result = sql(DemoModel)
|
|
141
|
+
assert isinstance(result, QueryIdentifier)
|
|
142
|
+
assert str(result) == '"demomodel"'
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def test_sql_select_column():
|
|
146
|
+
"""Test SQLGenerator's select method with a column."""
|
|
147
|
+
result = sql.select(DemoModel.field_one)
|
|
148
|
+
assert isinstance(result, QueryLiteral)
|
|
149
|
+
assert str(result) == '"demomodel"."field_one" AS "demomodel_field_one"'
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def test_sql_select_table():
|
|
153
|
+
"""Test SQLGenerator's select method with a table."""
|
|
154
|
+
result = sql.select(DemoModel)
|
|
155
|
+
assert isinstance(result, QueryLiteral)
|
|
156
|
+
assert str(result) == (
|
|
157
|
+
'"demomodel"."field_one" AS "demomodel_field_one", '
|
|
158
|
+
'"demomodel"."field_two" AS "demomodel_field_two"'
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def test_sql_raw_column():
|
|
163
|
+
"""Test SQLGenerator's raw method with a column."""
|
|
164
|
+
result = sql.raw(DemoModel.field_one)
|
|
165
|
+
assert isinstance(result, QueryIdentifier)
|
|
166
|
+
assert str(result) == '"field_one"'
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def test_sql_raw_table():
|
|
170
|
+
"""Test SQLGenerator's raw method with a table."""
|
|
171
|
+
result = sql.raw(DemoModel)
|
|
172
|
+
assert isinstance(result, QueryIdentifier)
|
|
173
|
+
assert str(result) == '"demomodel"'
|