velocity-python 0.0.33__tar.gz → 0.0.34__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.
Potentially problematic release.
This version of velocity-python might be problematic. Click here for more details.
- {velocity_python-0.0.33 → velocity_python-0.0.34}/PKG-INFO +1 -1
- {velocity_python-0.0.33 → velocity_python-0.0.34}/pyproject.toml +1 -1
- {velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity/__init__.py +1 -1
- {velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity/db/core/decorators.py +2 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity/db/core/engine.py +3 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity/db/core/transaction.py +13 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity/db/servers/postgres.py +1 -1
- {velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity_python.egg-info/PKG-INFO +1 -1
- {velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity_python.egg-info/SOURCES.txt +1 -0
- velocity_python-0.0.34/tests/test_foreign_key_handling.py +169 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/LICENSE +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/README.md +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/setup.cfg +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity/aws/__init__.py +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity/aws/handlers/__init__.py +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity/aws/handlers/context.py +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity/aws/handlers/lambda_handler.py +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity/aws/handlers/response.py +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity/aws/handlers/sqs_handler.py +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity/db/__init__.py +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity/db/core/__init__.py +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity/db/core/column.py +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity/db/core/database.py +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity/db/core/exceptions.py +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity/db/core/result.py +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity/db/core/row.py +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity/db/core/sequence.py +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity/db/core/table.py +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity/db/servers/__init__.py +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity/db/servers/mysql.py +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity/db/servers/sqlite.py +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity/db/servers/sqlserver.py +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity/misc/__init__.py +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity/misc/conv/__init__.py +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity/misc/conv/iconv.py +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity/misc/conv/oconv.py +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity/misc/db.py +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity/misc/export.py +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity/misc/format.py +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity/misc/mail.py +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity/misc/merge.py +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity/misc/timer.py +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity_python.egg-info/dependency_links.txt +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity_python.egg-info/requires.txt +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity_python.egg-info/top_level.txt +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/tests/test_db.py +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/tests/test_email_processing.py +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/tests/test_format.py +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/tests/test_iconv.py +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/tests/test_merge.py +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/tests/test_oconv.py +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/tests/test_postgres.py +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/tests/test_postgres_advanced.py +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/tests/test_response.py +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/tests/test_spreadsheet_functions.py +0 -0
- {velocity_python-0.0.33 → velocity_python-0.0.34}/tests/test_timer.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: velocity-python
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.34
|
|
4
4
|
Summary: A rapid application development library for interfacing with data storage
|
|
5
5
|
Author-email: Paul Perez <pperez@codeclubs.org>
|
|
6
6
|
Project-URL: Homepage, https://codeclubs.org/projects/velocity
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from functools import wraps
|
|
2
2
|
from velocity.db import exceptions
|
|
3
|
+
import traceback
|
|
3
4
|
|
|
4
5
|
|
|
5
6
|
def retry_on_dup_key(function):
|
|
@@ -55,6 +56,7 @@ def return_default(
|
|
|
55
56
|
if result is None:
|
|
56
57
|
result = default
|
|
57
58
|
except f.exceptions as e:
|
|
59
|
+
traceback.print_exc()
|
|
58
60
|
self.tx.rollback_savepoint(sp, cursor=self.cursor)
|
|
59
61
|
return f.default
|
|
60
62
|
self.tx.release_savepoint(sp, cursor=self.cursor)
|
|
@@ -169,6 +169,8 @@ class Engine(object):
|
|
|
169
169
|
return function(*args, **kwds)
|
|
170
170
|
except exceptions.DbRetryTransaction as e:
|
|
171
171
|
if e.args and e.args[0]:
|
|
172
|
+
print(e)
|
|
173
|
+
print("**Retry Transaction. Rollback and start over")
|
|
172
174
|
_tx.rollback()
|
|
173
175
|
continue
|
|
174
176
|
retry_count += 1
|
|
@@ -249,6 +251,7 @@ class Engine(object):
|
|
|
249
251
|
conf["database"] = database
|
|
250
252
|
if "dbname" in conf:
|
|
251
253
|
conf["dbname"] = database
|
|
254
|
+
|
|
252
255
|
return self
|
|
253
256
|
|
|
254
257
|
def set_config(self, config):
|
|
@@ -6,6 +6,7 @@ from velocity.db.core.column import Column
|
|
|
6
6
|
from velocity.db.core.database import Database
|
|
7
7
|
from velocity.db.core.sequence import Sequence
|
|
8
8
|
from velocity.misc.db import randomword
|
|
9
|
+
import traceback
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
debug = False
|
|
@@ -29,6 +30,11 @@ class Transaction(object):
|
|
|
29
30
|
|
|
30
31
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
31
32
|
if exc_type:
|
|
33
|
+
if debug:
|
|
34
|
+
print("Transaction.__exit__")
|
|
35
|
+
tb_str = "".join(traceback.format_exception(exc_type, exc_val, exc_tb))
|
|
36
|
+
if debug:
|
|
37
|
+
print(tb_str)
|
|
32
38
|
self.rollback()
|
|
33
39
|
self.close()
|
|
34
40
|
|
|
@@ -206,3 +212,10 @@ class Transaction(object):
|
|
|
206
212
|
result = self.execute(sql, vals)
|
|
207
213
|
self.__pg_types = dict(result.as_tuple())
|
|
208
214
|
return self.__pg_types
|
|
215
|
+
|
|
216
|
+
def switch_to_database(self, name):
|
|
217
|
+
if self.connection:
|
|
218
|
+
self.connection.close()
|
|
219
|
+
self.connection = None
|
|
220
|
+
self.engine.switch_to_database(name)
|
|
221
|
+
return self
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: velocity-python
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.34
|
|
4
4
|
Summary: A rapid application development library for interfacing with data storage
|
|
5
5
|
Author-email: Paul Perez <pperez@codeclubs.org>
|
|
6
6
|
Project-URL: Homepage, https://codeclubs.org/projects/velocity
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from velocity.db.servers import postgres
|
|
3
|
+
|
|
4
|
+
test_db = "test_foreign_key_db"
|
|
5
|
+
engine = postgres.initialize(database=test_db)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@engine.transaction
|
|
9
|
+
class TestForeignKeyHandling(unittest.TestCase):
|
|
10
|
+
@classmethod
|
|
11
|
+
@engine.transaction
|
|
12
|
+
def setUpClass(cls, tx):
|
|
13
|
+
# Drop and recreate the test database
|
|
14
|
+
tx.switch_to_database("postgres")
|
|
15
|
+
tx.execute(f"drop database if exists {test_db}", single=True)
|
|
16
|
+
tx.execute(f"create database {test_db}", single=True)
|
|
17
|
+
tx.switch_to_database(test_db)
|
|
18
|
+
|
|
19
|
+
# Create parent_table
|
|
20
|
+
parent_table = tx.table("parent_table")
|
|
21
|
+
parent_table.create(
|
|
22
|
+
columns={
|
|
23
|
+
"name": str,
|
|
24
|
+
}
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
# Create middle_table with a foreign key to parent_table
|
|
28
|
+
middle_table = tx.table("middle_table")
|
|
29
|
+
middle_table.create(
|
|
30
|
+
columns={
|
|
31
|
+
"parent_id": int,
|
|
32
|
+
"title": str,
|
|
33
|
+
}
|
|
34
|
+
)
|
|
35
|
+
middle_table.create_foreign_key("parent_id", "parent_table", "sys_id")
|
|
36
|
+
|
|
37
|
+
# Create child_table with foreign keys to both parent_table and middle_table
|
|
38
|
+
child_table = tx.table("child_table")
|
|
39
|
+
child_table.create(
|
|
40
|
+
columns={
|
|
41
|
+
"parent_id": int,
|
|
42
|
+
"middle_id": int,
|
|
43
|
+
}
|
|
44
|
+
)
|
|
45
|
+
child_table.create_foreign_key("parent_id", "parent_table", "sys_id")
|
|
46
|
+
child_table.create_foreign_key("middle_id", "middle_table", "sys_id")
|
|
47
|
+
|
|
48
|
+
@classmethod
|
|
49
|
+
@engine.transaction
|
|
50
|
+
def tearDownClass(cls, tx):
|
|
51
|
+
# Drop the test database
|
|
52
|
+
# tx.switch_to_database("postgres")
|
|
53
|
+
# tx.execute(f"drop database if exists {test_db}", single=True)
|
|
54
|
+
pass
|
|
55
|
+
|
|
56
|
+
def test_foreign_key_with_specified_sys_id(self, tx):
|
|
57
|
+
# Insert data into parent_table with specified sys_id
|
|
58
|
+
parent_table = tx.table("parent_table")
|
|
59
|
+
parent_table.insert({"sys_id": 100, "name": "Parent 1"})
|
|
60
|
+
parent_table.insert({"sys_id": 200, "name": "Parent 2"})
|
|
61
|
+
|
|
62
|
+
# Insert data into middle_table with specified sys_id
|
|
63
|
+
middle_table = tx.table("middle_table")
|
|
64
|
+
middle_table.insert({"sys_id": 300, "parent_id": 100, "title": "Title 1"})
|
|
65
|
+
middle_table.insert({"sys_id": 400, "parent_id": 200, "title": "Title 2"})
|
|
66
|
+
|
|
67
|
+
# Insert data into child_table with specified sys_id
|
|
68
|
+
child_table = tx.table("child_table")
|
|
69
|
+
child_table.insert(
|
|
70
|
+
{
|
|
71
|
+
"sys_id": 500,
|
|
72
|
+
"parent_id": 100,
|
|
73
|
+
"middle_id": 300,
|
|
74
|
+
"description": "Child A",
|
|
75
|
+
}
|
|
76
|
+
)
|
|
77
|
+
child_table.insert(
|
|
78
|
+
{
|
|
79
|
+
"sys_id": 600,
|
|
80
|
+
"parent_id": 200,
|
|
81
|
+
"middle_id": 400,
|
|
82
|
+
"description": "Child B",
|
|
83
|
+
}
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
# Query selecting columns with three foreign key references
|
|
87
|
+
result = list(
|
|
88
|
+
child_table.select(
|
|
89
|
+
columns=[
|
|
90
|
+
"parent_id>name",
|
|
91
|
+
"middle_id>title",
|
|
92
|
+
"sys_id",
|
|
93
|
+
"description",
|
|
94
|
+
]
|
|
95
|
+
)
|
|
96
|
+
)
|
|
97
|
+
expected_result = [
|
|
98
|
+
{
|
|
99
|
+
"parent_id_name": "Parent 1",
|
|
100
|
+
"middle_id_title": "Title 1",
|
|
101
|
+
"sys_id": 500,
|
|
102
|
+
"description": "Child A",
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
"parent_id_name": "Parent 2",
|
|
106
|
+
"middle_id_title": "Title 2",
|
|
107
|
+
"sys_id": 600,
|
|
108
|
+
"description": "Child B",
|
|
109
|
+
},
|
|
110
|
+
]
|
|
111
|
+
self.assertEqual(result, expected_result)
|
|
112
|
+
|
|
113
|
+
def test_foreign_key_conditions_with_specified_sys_id(self, tx):
|
|
114
|
+
# Query with conditions on foreign key references
|
|
115
|
+
child_table = tx.table("child_table")
|
|
116
|
+
result = list(
|
|
117
|
+
child_table.select(
|
|
118
|
+
columns=[
|
|
119
|
+
"parent_id>name",
|
|
120
|
+
"middle_id>title",
|
|
121
|
+
"sys_id",
|
|
122
|
+
"description",
|
|
123
|
+
],
|
|
124
|
+
where={"parent_id>name": "Parent 1", "middle_id>title": "Title 1"},
|
|
125
|
+
)
|
|
126
|
+
)
|
|
127
|
+
expected_result = [
|
|
128
|
+
{
|
|
129
|
+
"parent_id_name": "Parent 1",
|
|
130
|
+
"middle_id_title": "Title 1",
|
|
131
|
+
"sys_id": 500,
|
|
132
|
+
"description": "Child A",
|
|
133
|
+
}
|
|
134
|
+
]
|
|
135
|
+
self.assertEqual(result, expected_result)
|
|
136
|
+
|
|
137
|
+
def test_foreign_key_ordering_with_specified_sys_id(self, tx):
|
|
138
|
+
# Query with ordering based on foreign key references
|
|
139
|
+
child_table = tx.table("child_table")
|
|
140
|
+
result = list(
|
|
141
|
+
child_table.select(
|
|
142
|
+
columns=[
|
|
143
|
+
"parent_id>name",
|
|
144
|
+
"middle_id>title",
|
|
145
|
+
"sys_id",
|
|
146
|
+
"description",
|
|
147
|
+
],
|
|
148
|
+
orderby="parent_id>name DESC, middle_id>title ASC",
|
|
149
|
+
)
|
|
150
|
+
)
|
|
151
|
+
expected_result = [
|
|
152
|
+
{
|
|
153
|
+
"parent_id_name": "Parent 2",
|
|
154
|
+
"middle_id_title": "Title 2",
|
|
155
|
+
"sys_id": 600,
|
|
156
|
+
"description": "Child B",
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
"parent_id_name": "Parent 1",
|
|
160
|
+
"middle_id_title": "Title 1",
|
|
161
|
+
"sys_id": 500,
|
|
162
|
+
"description": "Child A",
|
|
163
|
+
},
|
|
164
|
+
]
|
|
165
|
+
self.assertEqual(result, expected_result)
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
if __name__ == "__main__":
|
|
169
|
+
unittest.main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity/aws/handlers/lambda_handler.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity_python.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
{velocity_python-0.0.33 → velocity_python-0.0.34}/src/velocity_python.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|