velocity-python 0.0.27__tar.gz → 0.0.29__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.27 → velocity-python-0.0.29}/PKG-INFO +1 -1
- {velocity-python-0.0.27 → velocity-python-0.0.29}/pyproject.toml +1 -1
- {velocity-python-0.0.27 → velocity-python-0.0.29}/src/velocity/__init__.py +1 -1
- velocity-python-0.0.29/src/velocity/db/core/decorators.py +100 -0
- {velocity-python-0.0.27 → velocity-python-0.0.29}/src/velocity/db/core/row.py +33 -21
- velocity-python-0.0.29/src/velocity/db/core/table.py +622 -0
- {velocity-python-0.0.27 → velocity-python-0.0.29}/src/velocity/db/core/transaction.py +54 -31
- velocity-python-0.0.29/src/velocity/db/servers/postgres.py +1396 -0
- {velocity-python-0.0.27 → velocity-python-0.0.29}/src/velocity_python.egg-info/PKG-INFO +1 -1
- {velocity-python-0.0.27 → velocity-python-0.0.29}/src/velocity_python.egg-info/SOURCES.txt +0 -1
- velocity-python-0.0.27/src/velocity/db/core/decorators.py +0 -81
- velocity-python-0.0.27/src/velocity/db/core/table.py +0 -473
- velocity-python-0.0.27/src/velocity/db/servers/postgres.py +0 -1275
- velocity-python-0.0.27/src/velocity/db/servers/sql.py +0 -558
- {velocity-python-0.0.27 → velocity-python-0.0.29}/LICENSE +0 -0
- {velocity-python-0.0.27 → velocity-python-0.0.29}/README.md +0 -0
- {velocity-python-0.0.27 → velocity-python-0.0.29}/setup.cfg +0 -0
- {velocity-python-0.0.27 → velocity-python-0.0.29}/src/velocity/aws/__init__.py +0 -0
- {velocity-python-0.0.27 → velocity-python-0.0.29}/src/velocity/aws/handlers/__init__.py +0 -0
- {velocity-python-0.0.27 → velocity-python-0.0.29}/src/velocity/aws/handlers/context.py +0 -0
- {velocity-python-0.0.27 → velocity-python-0.0.29}/src/velocity/aws/handlers/lambda_handler.py +0 -0
- {velocity-python-0.0.27 → velocity-python-0.0.29}/src/velocity/aws/handlers/response.py +0 -0
- {velocity-python-0.0.27 → velocity-python-0.0.29}/src/velocity/aws/handlers/sqs_handler.py +0 -0
- {velocity-python-0.0.27 → velocity-python-0.0.29}/src/velocity/db/__init__.py +0 -0
- {velocity-python-0.0.27 → velocity-python-0.0.29}/src/velocity/db/core/__init__.py +0 -0
- {velocity-python-0.0.27 → velocity-python-0.0.29}/src/velocity/db/core/column.py +0 -0
- {velocity-python-0.0.27 → velocity-python-0.0.29}/src/velocity/db/core/database.py +0 -0
- {velocity-python-0.0.27 → velocity-python-0.0.29}/src/velocity/db/core/engine.py +0 -0
- {velocity-python-0.0.27 → velocity-python-0.0.29}/src/velocity/db/core/exceptions.py +0 -0
- {velocity-python-0.0.27 → velocity-python-0.0.29}/src/velocity/db/core/result.py +0 -0
- {velocity-python-0.0.27 → velocity-python-0.0.29}/src/velocity/db/core/sequence.py +0 -0
- {velocity-python-0.0.27 → velocity-python-0.0.29}/src/velocity/db/servers/__init__.py +0 -0
- {velocity-python-0.0.27 → velocity-python-0.0.29}/src/velocity/db/servers/mysql.py +0 -0
- {velocity-python-0.0.27 → velocity-python-0.0.29}/src/velocity/db/servers/sqlite.py +0 -0
- {velocity-python-0.0.27 → velocity-python-0.0.29}/src/velocity/db/servers/sqlserver.py +0 -0
- {velocity-python-0.0.27 → velocity-python-0.0.29}/src/velocity/misc/__init__.py +0 -0
- {velocity-python-0.0.27 → velocity-python-0.0.29}/src/velocity/misc/conv/__init__.py +0 -0
- {velocity-python-0.0.27 → velocity-python-0.0.29}/src/velocity/misc/conv/iconv.py +0 -0
- {velocity-python-0.0.27 → velocity-python-0.0.29}/src/velocity/misc/conv/oconv.py +0 -0
- {velocity-python-0.0.27 → velocity-python-0.0.29}/src/velocity/misc/db.py +0 -0
- {velocity-python-0.0.27 → velocity-python-0.0.29}/src/velocity/misc/export.py +0 -0
- {velocity-python-0.0.27 → velocity-python-0.0.29}/src/velocity/misc/format.py +0 -0
- {velocity-python-0.0.27 → velocity-python-0.0.29}/src/velocity/misc/mail.py +0 -0
- {velocity-python-0.0.27 → velocity-python-0.0.29}/src/velocity/misc/merge.py +0 -0
- {velocity-python-0.0.27 → velocity-python-0.0.29}/src/velocity/misc/timer.py +0 -0
- {velocity-python-0.0.27 → velocity-python-0.0.29}/src/velocity_python.egg-info/dependency_links.txt +0 -0
- {velocity-python-0.0.27 → velocity-python-0.0.29}/src/velocity_python.egg-info/requires.txt +0 -0
- {velocity-python-0.0.27 → velocity-python-0.0.29}/src/velocity_python.egg-info/top_level.txt +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.29
|
|
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,100 @@
|
|
|
1
|
+
from functools import wraps
|
|
2
|
+
from velocity.db import exceptions
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def retry_on_dup_key(function):
|
|
6
|
+
# retry_on_dup_key is needed to skip past existing autogenerated ids when inserting
|
|
7
|
+
@wraps(function)
|
|
8
|
+
def retry_decorator(self, *args, **kwds):
|
|
9
|
+
sp = self.tx.create_savepoint(cursor=self.cursor)
|
|
10
|
+
while True:
|
|
11
|
+
try:
|
|
12
|
+
return function(self, *args, **kwds)
|
|
13
|
+
except exceptions.DbDuplicateKeyError:
|
|
14
|
+
self.tx.rollback_savepoint(sp, cursor=self.cursor)
|
|
15
|
+
continue
|
|
16
|
+
|
|
17
|
+
return retry_decorator
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def reset_id_on_dup_key(function):
|
|
21
|
+
# reset_id_on_dup_key sets sys_id to max(sys_id) + 1 when inserting
|
|
22
|
+
@wraps(function)
|
|
23
|
+
def reset_decorator(self, *args, **kwds):
|
|
24
|
+
sp = self.tx.create_savepoint(cursor=self.cursor)
|
|
25
|
+
try:
|
|
26
|
+
return function(self, *args, **kwds)
|
|
27
|
+
except exceptions.DbDuplicateKeyError:
|
|
28
|
+
self.tx.rollback_savepoint(sp, cursor=self.cursor)
|
|
29
|
+
self.set_sequence(self.max("sys_id") + 1)
|
|
30
|
+
return function(self, *args, **kwds)
|
|
31
|
+
|
|
32
|
+
return reset_decorator
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def return_default(
|
|
36
|
+
default=None,
|
|
37
|
+
exceptions=(
|
|
38
|
+
StopIteration,
|
|
39
|
+
exceptions.DbApplicationError,
|
|
40
|
+
exceptions.DbTableMissingError,
|
|
41
|
+
exceptions.DbColumnMissingError,
|
|
42
|
+
exceptions.DbTruncationError,
|
|
43
|
+
exceptions.DbObjectExistsError,
|
|
44
|
+
),
|
|
45
|
+
):
|
|
46
|
+
def decorator(f):
|
|
47
|
+
f.default = default
|
|
48
|
+
f.exceptions = exceptions
|
|
49
|
+
|
|
50
|
+
@wraps(f)
|
|
51
|
+
def return_default(self, *args, **kwds):
|
|
52
|
+
sp = self.tx.create_savepoint(cursor=self.cursor)
|
|
53
|
+
try:
|
|
54
|
+
result = f(self, *args, **kwds)
|
|
55
|
+
if result is None:
|
|
56
|
+
result = default
|
|
57
|
+
except f.exceptions as e:
|
|
58
|
+
self.tx.rollback_savepoint(sp, cursor=self.cursor)
|
|
59
|
+
return f.default
|
|
60
|
+
self.tx.release_savepoint(sp, cursor=self.cursor)
|
|
61
|
+
return result
|
|
62
|
+
|
|
63
|
+
return return_default
|
|
64
|
+
|
|
65
|
+
return decorator
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def create_missing(function):
|
|
69
|
+
@wraps(function)
|
|
70
|
+
def create_missing_decorator(self, *args, **kwds):
|
|
71
|
+
sp = self.tx.create_savepoint(cursor=self.cursor)
|
|
72
|
+
try:
|
|
73
|
+
result = function(self, *args, **kwds)
|
|
74
|
+
self.tx.release_savepoint(sp, cursor=self.cursor)
|
|
75
|
+
except exceptions.DbColumnMissingError:
|
|
76
|
+
self.tx.rollback_savepoint(sp, cursor=self.cursor)
|
|
77
|
+
data = {}
|
|
78
|
+
if "pk" in kwds:
|
|
79
|
+
data.update(kwds["pk"])
|
|
80
|
+
if "data" in kwds:
|
|
81
|
+
data.update(kwds["data"])
|
|
82
|
+
for i in range(len(args)):
|
|
83
|
+
if args[i]:
|
|
84
|
+
data.update(args[i])
|
|
85
|
+
self.alter(data)
|
|
86
|
+
result = function(self, *args, **kwds)
|
|
87
|
+
except exceptions.DbTableMissingError:
|
|
88
|
+
self.tx.rollback_savepoint(sp, cursor=self.cursor)
|
|
89
|
+
data = {}
|
|
90
|
+
if "pk" in kwds:
|
|
91
|
+
data.update(kwds["pk"])
|
|
92
|
+
if "data" in kwds:
|
|
93
|
+
data.update(kwds["data"])
|
|
94
|
+
for i in range(len(args)):
|
|
95
|
+
data.update(args[i])
|
|
96
|
+
self.create(data)
|
|
97
|
+
result = function(self, *args, **kwds)
|
|
98
|
+
return result
|
|
99
|
+
|
|
100
|
+
return create_missing_decorator
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import pprint
|
|
2
2
|
|
|
3
|
+
|
|
3
4
|
class Row(object):
|
|
4
5
|
def __init__(self, table, key, lock=None):
|
|
5
6
|
if isinstance(table, str):
|
|
6
|
-
raise Exception(
|
|
7
|
-
"table parameter of row class must `table` instance")
|
|
7
|
+
raise Exception("table parameter of row class must `table` instance")
|
|
8
8
|
self.table = table
|
|
9
9
|
if isinstance(key, (dict, Row)):
|
|
10
10
|
pk = {}
|
|
@@ -37,7 +37,7 @@ class Row(object):
|
|
|
37
37
|
def __setitem__(self, key, val):
|
|
38
38
|
if key in self.pk:
|
|
39
39
|
raise Exception("Can't update a primary key, idiot!")
|
|
40
|
-
self.table.
|
|
40
|
+
self.table.upsert({key: val}, self.pk)
|
|
41
41
|
|
|
42
42
|
def __delitem__(self, key):
|
|
43
43
|
if key in self.pk:
|
|
@@ -90,7 +90,7 @@ class Row(object):
|
|
|
90
90
|
if kwds:
|
|
91
91
|
data.update(kwds)
|
|
92
92
|
if data:
|
|
93
|
-
self.table.
|
|
93
|
+
self.table.upsert(data, self.pk)
|
|
94
94
|
return self
|
|
95
95
|
|
|
96
96
|
def iterkeys(self):
|
|
@@ -105,7 +105,7 @@ class Row(object):
|
|
|
105
105
|
def __cmp__(self, other):
|
|
106
106
|
# zero == same (not less than or greater than other)
|
|
107
107
|
diff = -1
|
|
108
|
-
if hasattr(other,
|
|
108
|
+
if hasattr(other, "keys"):
|
|
109
109
|
k1 = list(self.keys())
|
|
110
110
|
k2 = list(other.keys())
|
|
111
111
|
if k1 == k2:
|
|
@@ -122,23 +122,34 @@ class Row(object):
|
|
|
122
122
|
def copy(self, lock=None):
|
|
123
123
|
old = self.to_dict()
|
|
124
124
|
for key in list(old.keys()):
|
|
125
|
-
if
|
|
125
|
+
if "sys_" in key:
|
|
126
126
|
old.pop(key)
|
|
127
127
|
return self.table.new(old, lock=lock)
|
|
128
128
|
|
|
129
129
|
# ================================================================
|
|
130
130
|
# This stuff is not implemented
|
|
131
131
|
|
|
132
|
-
def pop(self):
|
|
133
|
-
|
|
132
|
+
def pop(self):
|
|
133
|
+
raise NotImplementedError
|
|
134
|
+
|
|
135
|
+
def popitem(self):
|
|
136
|
+
raise NotImplementedError
|
|
137
|
+
|
|
138
|
+
def __lt__(self, other):
|
|
139
|
+
raise NotImplementedError
|
|
134
140
|
|
|
135
|
-
def
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
def
|
|
141
|
+
def __gt__(self, other):
|
|
142
|
+
raise NotImplementedError
|
|
143
|
+
|
|
144
|
+
def __le__(self, other):
|
|
145
|
+
raise NotImplementedError
|
|
146
|
+
|
|
147
|
+
def __ge__(self, other):
|
|
148
|
+
raise NotImplementedError
|
|
139
149
|
|
|
140
150
|
@classmethod
|
|
141
|
-
def fromkeys(cls, iterable, value=None):
|
|
151
|
+
def fromkeys(cls, iterable, value=None):
|
|
152
|
+
raise NotImplementedError
|
|
142
153
|
|
|
143
154
|
def to_dict(self):
|
|
144
155
|
return self.table.select(where=self.pk).as_dict().one()
|
|
@@ -154,14 +165,14 @@ class Row(object):
|
|
|
154
165
|
|
|
155
166
|
@property
|
|
156
167
|
def key_cols(self):
|
|
157
|
-
#result = self.execute(*self.sql.primary_keys(self.tablename))
|
|
168
|
+
# result = self.execute(*self.sql.primary_keys(self.tablename))
|
|
158
169
|
# return [x[0] for x in result.as_tuple()]
|
|
159
|
-
return [
|
|
170
|
+
return ["sys_id"]
|
|
160
171
|
|
|
161
172
|
def split(self):
|
|
162
173
|
old = self.to_dict()
|
|
163
174
|
for key in list(old.keys()):
|
|
164
|
-
if
|
|
175
|
+
if "sys_" in key:
|
|
165
176
|
old.pop(key)
|
|
166
177
|
return old, self.pk
|
|
167
178
|
|
|
@@ -177,8 +188,9 @@ class Row(object):
|
|
|
177
188
|
fk = self.table.foreign_key_info(key)
|
|
178
189
|
if not fk:
|
|
179
190
|
raise Exception(
|
|
180
|
-
"Column `{}` is not a foreign key in `{}`".format(key, self.table.name)
|
|
181
|
-
|
|
191
|
+
"Column `{}` is not a foreign key in `{}`".format(key, self.table.name)
|
|
192
|
+
)
|
|
193
|
+
return tx.Row(fk["referenced_table_name"], value, lock=lock)
|
|
182
194
|
|
|
183
195
|
def match(self, other):
|
|
184
196
|
for key in other:
|
|
@@ -187,7 +199,7 @@ class Row(object):
|
|
|
187
199
|
return True
|
|
188
200
|
|
|
189
201
|
def touch(self):
|
|
190
|
-
self[
|
|
202
|
+
self["sys_modified"] = "@@CURRENT_TIMESTAMP"
|
|
191
203
|
return self
|
|
192
204
|
|
|
193
205
|
delete = clear
|
|
@@ -196,14 +208,14 @@ class Row(object):
|
|
|
196
208
|
self.table.select(where=self.pk, lock=True)
|
|
197
209
|
return self
|
|
198
210
|
|
|
199
|
-
|
|
200
211
|
def notBlank(self, key, failobj=None):
|
|
201
212
|
data = self[key]
|
|
202
213
|
if not data:
|
|
203
214
|
return failobj
|
|
204
215
|
return data
|
|
216
|
+
|
|
205
217
|
getBlank = notBlank
|
|
206
218
|
|
|
207
219
|
@property
|
|
208
220
|
def sys_id(self):
|
|
209
|
-
return self.pk[
|
|
221
|
+
return self.pk["sys_id"]
|