velocity-python 0.0.27__py3-none-any.whl → 0.0.29__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.

Potentially problematic release.


This version of velocity-python might be problematic. Click here for more details.

@@ -10,20 +10,19 @@ from velocity.misc.db import randomword
10
10
 
11
11
  debug = False
12
12
 
13
+
13
14
  class Transaction(object):
14
15
 
15
16
  def __init__(self, engine, connection=None):
16
17
  self.engine = engine
17
18
  self.connection = connection
19
+ self.__pg_types = {}
18
20
 
19
21
  def __str__(self):
20
22
  c = self.engine.config
21
- server = c.get('host',c.get('server'))
22
- database = c.get('database')
23
- return "{}.transaction({}:{})".format(
24
- self.engine.sql.server,
25
- server,
26
- database)
23
+ server = c.get("host", c.get("server"))
24
+ database = c.get("database")
25
+ return "{}.transaction({}:{})".format(self.engine.sql.server, server, database)
27
26
 
28
27
  def __enter__(self):
29
28
  return self
@@ -36,17 +35,29 @@ class Transaction(object):
36
35
  def cursor(self):
37
36
  if not self.connection:
38
37
  if debug:
39
- print('>>> {} open connection to {database}'.format(id(self), **self.engine.config))
38
+ print(
39
+ ">>> {} open connection to {database}".format(
40
+ id(self), **self.engine.config
41
+ )
42
+ )
40
43
  self.connection = self.engine.connect()
41
44
  if debug:
42
- print("*** {} open {database}.transaction.connection.cursor".format(id(self), **self.engine.config))
45
+ print(
46
+ "*** {} open {database}.transaction.connection.cursor".format(
47
+ id(self), **self.engine.config
48
+ )
49
+ )
43
50
  return self.connection.cursor()
44
51
 
45
52
  def close(self):
46
53
  if self.connection:
47
54
  self.commit()
48
55
  if debug:
49
- print('<<< {} close connection to {database}'.format(id(self), **self.engine.config))
56
+ print(
57
+ "<<< {} close connection to {database}".format(
58
+ id(self), **self.engine.config
59
+ )
60
+ )
50
61
  self.connection.close()
51
62
 
52
63
  def execute(self, sql, parms=None, single=False, cursor=None):
@@ -57,16 +68,20 @@ class Transaction(object):
57
68
  cursor = None
58
69
  if not self.connection:
59
70
  if debug:
60
- print('>>> {} open connection to {database}'.format(id(self), **self.engine.config))
71
+ print(
72
+ ">>> {} open connection to {database}".format(
73
+ id(self), **self.engine.config
74
+ )
75
+ )
61
76
  self.connection = self.engine.connect()
62
- action = re.search(r'(\w+)', sql, re.I)
77
+ action = re.search(r"(\w+)", sql, re.I)
63
78
  if action:
64
79
  action = action.group().lower()
65
80
  else:
66
- action = 'None'
81
+ action = "None"
67
82
  if debug:
68
83
  print(action)
69
- print(id(self), '------------>', sql, '::', parms)
84
+ print(id(self), "------------>", sql, "::", parms)
70
85
  print()
71
86
  if single:
72
87
  self.commit()
@@ -79,10 +94,10 @@ class Transaction(object):
79
94
  else:
80
95
  cursor.execute(sql)
81
96
  except:
82
- self.engine.ProcessError(sql,parms)
97
+ self.engine.ProcessError(sql, parms)
83
98
  if single:
84
99
  self.connection.autocommit = False
85
- return Result(cursor)
100
+ return Result(cursor, self, sql, parms)
86
101
 
87
102
  def server_execute(self, sql, parms=None):
88
103
  return self._execute(sql, parms, cursor=self.cursor())
@@ -90,13 +105,21 @@ class Transaction(object):
90
105
  def commit(self):
91
106
  if self.connection:
92
107
  if debug:
93
- print('{} --- connection commit {database}'.format(id(self), **self.engine.config))
108
+ print(
109
+ "{} --- connection commit {database}".format(
110
+ id(self), **self.engine.config
111
+ )
112
+ )
94
113
  self.connection.commit()
95
114
 
96
115
  def rollback(self):
97
116
  if self.connection:
98
117
  if debug:
99
- print('{} --- connection rollback {database}'.format(id(self), **self.engine.config))
118
+ print(
119
+ "{} --- connection rollback {database}".format(
120
+ id(self), **self.engine.config
121
+ )
122
+ )
100
123
  self.connection.rollback()
101
124
 
102
125
  def create_savepoint(self, sp=None, cursor=None):
@@ -126,28 +149,28 @@ class Transaction(object):
126
149
  def sequence(self, name):
127
150
  return Sequence(self, name)
128
151
 
129
- def row(self, tablename, pk):
152
+ def row(self, tablename, pk, lock=None):
130
153
  """
131
154
  Returns exactly one row based on primary key.
132
155
  raise exception if primary key not provided.
133
156
  """
134
- return Row(self.table(tablename), pk)
157
+ return Row(self.table(tablename), pk, lock=lock)
135
158
 
136
- def get(self, tablename, where):
159
+ def get(self, tablename, where, lock=None):
137
160
  """
138
161
  Search for row. return row if 1 found.
139
162
  raise exception if duplicates found.
140
163
  return new if not found. (creates new/use find otherwise)
141
164
  """
142
- return self.table(tablename).get(where)
165
+ return self.table(tablename).get(where, lock=lock)
143
166
 
144
- def find(self, tablename, where):
167
+ def find(self, tablename, where, lock=None):
145
168
  """
146
169
  Search for row. return row if 1 found.
147
170
  raise exception if duplicates found.
148
171
  return {} if not found. (Does not create new)
149
172
  """
150
- return self.table(tablename).find(where)
173
+ return self.table(tablename).find(where, lock=lock)
151
174
 
152
175
  def column(self, tablename, colname):
153
176
  return Column(self.table(tablename), colname)
@@ -162,13 +185,12 @@ class Transaction(object):
162
185
  self.connection.set_isolation_level(0)
163
186
  sql = ["VACUUM"]
164
187
  if full:
165
- sql.append('FULL')
188
+ sql.append("FULL")
166
189
  if analyze:
167
- sql.append('ANALYZE')
168
- self.execute(' '.join(sql))
169
- print(self.current_database())
190
+ sql.append("ANALYZE")
191
+ self.execute(" ".join(sql))
170
192
  if reindex:
171
- database = self.engine.config.get('database')
193
+ database = self.engine.config.get("database")
172
194
  self.execute("REINDEX DATABASE {}".format(database))
173
195
  self.connection.set_isolation_level(old_isolation_level)
174
196
 
@@ -176,10 +198,11 @@ class Transaction(object):
176
198
  sql, vals = self.engine.sql.tables()
177
199
  result = self.execute(sql, vals)
178
200
  return ["%s.%s" % x for x in result.as_tuple()]
179
-
201
+
202
+ @property
180
203
  def pg_types(self):
181
204
  if not self.__pg_types:
182
205
  sql, vals = "select oid,typname from pg_type", ()
183
206
  result = self.execute(sql, vals)
184
- self.__pg_types = dict(result.as_tuple())
185
- return self.__pg_types
207
+ self.__pg_types = dict(result.as_tuple())
208
+ return self.__pg_types