|
43 | 43 | ] |
44 | 44 |
|
45 | 45 | class Message(Element): |
46 | | - "A message emitted by PostgreSQL" |
47 | | - _e_label = property(lambda x: getattr(x, 'details', None).get('severity', 'MESSAGE')) |
| 46 | + """ |
| 47 | + A message emitted by PostgreSQL. This element is universal, so |
| 48 | + `postgresql.api.Message` is a complete implementation for representing a |
| 49 | + message. Any interface should produce these objects. |
| 50 | + """ |
| 51 | + _e_label = property(lambda x: getattr(x, 'details').get('severity', 'MESSAGE')) |
48 | 52 | _e_factors = ('creator',) |
49 | 53 |
|
50 | 54 | severities = ( |
@@ -154,44 +158,17 @@ def raise_message(self, starting_point = None): |
154 | 158 | # send the message to postgresql.sys.msghook |
155 | 159 | pg_sys.msghook(self) |
156 | 160 |
|
157 | | -class Chunks( |
158 | | - collections.Iterator, |
159 | | - collections.Iterable, |
160 | | -): |
161 | | - """ |
162 | | - A `Chunks` object is an interface to an iterator of row-sets produced |
163 | | - by a cursor. |
| 161 | +class Result(Element): |
164 | 162 | """ |
| 163 | + A result is an object managing the results of a prepared statement. |
165 | 164 |
|
166 | | - def __iter__(self): |
167 | | - return self |
168 | | - |
169 | | -class Cursor( |
170 | | - Element, |
171 | | - collections.Iterator, |
172 | | - collections.Iterable, |
173 | | -): |
174 | | - """ |
175 | | - A `Cursor` object is an interface to a sequence of tuples(rows). A result |
176 | | - set. Cursors publish a file-like interface for reading tuples from a cursor |
177 | | - declared on the database. |
| 165 | + These objects represent a binding of parameters to a given statement object. |
178 | 166 |
|
179 | | - `Cursor` objects are created by invoking the `PreparedStatement.declare` |
180 | | - method or by opening a cursor using an identifier via the |
181 | | - `Database.cursor_from_id` method. |
| 167 | + For results that were constructed on the server and a reference passed back |
| 168 | + to the client, parameters may be None. |
182 | 169 | """ |
183 | | - _e_label = 'CURSOR' |
184 | | - _e_factors = ('statement', 'parameters') |
185 | | - |
186 | | - _seek_whence_map = { |
187 | | - 0 : 'ABSOLUTE', |
188 | | - 1 : 'RELATIVE', |
189 | | - 2 : 'FROM_END', |
190 | | - } |
191 | | - _direction_map = { |
192 | | - True : 'FORWARD', |
193 | | - False : 'BACKWARD', |
194 | | - } |
| 170 | + _e_label = 'RESULT' |
| 171 | + _e_factors = ('statement', 'parameters', 'cursor_id') |
195 | 172 |
|
196 | 173 | @propertydoc |
197 | 174 | @abstractproperty |
@@ -252,15 +229,61 @@ def parameters(self) -> (tuple, None): |
252 | 229 | `()`, if no parameters were given. |
253 | 230 |
|
254 | 231 | These should be the *original* parameters given to the invoked statement. |
| 232 | +
|
| 233 | + This should only be `None` when the cursor is created from an identifier, |
| 234 | + `postgresql.api.Database.cursor_from_id`. |
255 | 235 | """ |
256 | 236 |
|
257 | 237 | @propertydoc |
258 | 238 | @abstractproperty |
259 | 239 | def statement(self) -> ("PreparedStatement", None): |
260 | 240 | """ |
261 | 241 | The query object used to create the cursor. `None`, if unknown. |
| 242 | +
|
| 243 | + This should only be `None` when the cursor is created from an identifier, |
| 244 | + `postgresql.api.Database.cursor_from_id`. |
262 | 245 | """ |
263 | 246 |
|
| 247 | +class Chunks( |
| 248 | + collections.Iterator, |
| 249 | + collections.Iterable, |
| 250 | +): |
| 251 | + """ |
| 252 | + A `Chunks` object is an interface to an iterator of row-sets produced |
| 253 | + by a cursor. |
| 254 | + """ |
| 255 | + def __iter__(self): |
| 256 | + return self |
| 257 | + |
| 258 | +class Cursor( |
| 259 | + Result, |
| 260 | + collections.Iterator, |
| 261 | + collections.Iterable, |
| 262 | +): |
| 263 | + """ |
| 264 | + A `Cursor` object is an interface to a sequence of tuples(rows). A result |
| 265 | + set. Cursors publish a file-like interface for reading tuples from a cursor |
| 266 | + declared on the database. |
| 267 | +
|
| 268 | + `Cursor` objects are created by invoking the `PreparedStatement.declare` |
| 269 | + method or by opening a cursor using an identifier via the |
| 270 | + `Database.cursor_from_id` method. |
| 271 | + """ |
| 272 | + _e_label = 'CURSOR' |
| 273 | + |
| 274 | + _seek_whence_map = { |
| 275 | + 0 : 'ABSOLUTE', |
| 276 | + 1 : 'RELATIVE', |
| 277 | + 2 : 'FROM_END', |
| 278 | + } |
| 279 | + _direction_map = { |
| 280 | + True : 'FORWARD', |
| 281 | + False : 'BACKWARD', |
| 282 | + } |
| 283 | + |
| 284 | + def __iter__(self): |
| 285 | + return self |
| 286 | + |
264 | 287 | @propertydoc |
265 | 288 | @abstractproperty |
266 | 289 | def direction(self) -> bool: |
|
0 commit comments