|
281 | 281 | Database Interface Points |
282 | 282 | ------------------------- |
283 | 283 |
|
284 | | -After a connection is established, the primary interface points are ready for |
285 | | -use. These entry points exist as properties and methods on the connection |
286 | | -object: |
| 284 | +After a connection is established:: |
287 | 285 |
|
288 | | - ``prepare(sql_statement_string)`` |
| 286 | + >>> import postgresql |
| 287 | + >>> db = postgresql.open(...) |
| 288 | +
|
| 289 | +The methods and properties on the connection object are ready for use: |
| 290 | +
|
| 291 | + ``db.prepare(sql_statement_string)`` |
289 | 292 | Create a `postgresql.api.PreparedStatement` object for querying the database. |
290 | 293 | This provides an "SQL statement template" that can be executed multiple times. |
291 | 294 | See `Prepared Statements`_ for more information. |
292 | 295 |
|
293 | | - ``proc(procedure_id)`` |
| 296 | + ``db.proc(procedure_id)`` |
294 | 297 | Create a `postgresql.api.StoredProcedure` object referring to a stored |
295 | 298 | procedure on the database. The returned object will provide a |
296 | 299 | `collections.Callable` interface to the stored procedure on the server. See |
297 | 300 | `Stored Procedures`_ for more information. |
298 | 301 |
|
299 | | - ``statement_from_id(statement_id)`` |
| 302 | + ``db.statement_from_id(statement_id)`` |
300 | 303 | Create a `postgresql.api.PreparedStatement` object from an existing statement |
301 | 304 | identifier. This is used in cases where the statement was prepared on the |
302 | 305 | server. See `Prepared Statements`_ for more information. |
303 | 306 |
|
304 | | - ``cursor_from_id(cursor_id)`` |
| 307 | + ``db.cursor_from_id(cursor_id)`` |
305 | 308 | Create a `postgresql.api.Cursor` object from an existing cursor identifier. |
306 | 309 | This is used in cases where the cursor was declared on the server. See |
307 | 310 | `Cursors`_ for more information. |
308 | 311 |
|
309 | | - ``execute(sql_statements_string)`` |
| 312 | + ``db.execute(sql_statements_string)`` |
310 | 313 | Run a block of SQL on the server. This method returns `None` unless an error |
311 | 314 | occurs. If errors occur, the processing of the statements will stop and the |
312 | 315 | the error will be raised. |
313 | 316 |
|
314 | | - ``xact(gid = None, isolation = None, mode = None)`` |
| 317 | + ``db.xact(gid = None, isolation = None, mode = None)`` |
315 | 318 | The `postgresql.api.Transaction` constructor for creating transactions. |
316 | 319 | This method creates a transaction reference. The transaction will not be |
317 | 320 | started until it's instructed to do so. See `Transactions`_ for more |
318 | 321 | information. |
319 | 322 |
|
320 | | - ``settings`` |
| 323 | + ``db.settings`` |
321 | 324 | A property providing a `collections.MutableMapping` interface to the |
322 | 325 | database's SQL settings. See `Settings`_ for more information. |
323 | 326 |
|
|
329 | 332 | the backend. The following are the attributes set on the connection object after |
330 | 333 | the connection is made: |
331 | 334 |
|
332 | | - ``version`` |
| 335 | + ``db.version`` |
333 | 336 | The results of ``SELECT version()``. |
334 | 337 |
|
335 | | - ``version_info`` |
| 338 | + ``db.version_info`` |
336 | 339 | A ``sys.version_info`` form of the ``server_version`` setting. eg. ``(8, 1, 2, |
337 | 340 | 'final', 0)``. |
338 | 341 |
|
339 | | - ``security`` |
| 342 | + ``db.security`` |
340 | 343 | `None` if no security. ``'ssl'`` if SSL is enabled. |
341 | 344 |
|
342 | | - ``backend_id`` |
| 345 | + ``db.backend_id`` |
343 | 346 | The process-id of the backend process. |
344 | 347 |
|
345 | | - ``backend_start`` |
| 348 | + ``db.backend_start`` |
346 | 349 | When backend was started. ``datetime.datetime`` instance. |
347 | 350 |
|
348 | | - ``client_address`` |
| 351 | + ``db.client_address`` |
349 | 352 | The address of the client that the backend is communicating with. |
350 | 353 |
|
351 | | - ``client_port`` |
| 354 | + ``db.client_port`` |
352 | 355 | The port of the client that the backend is communicating with. |
353 | 356 |
|
354 | 357 | The latter three are collected from pg_stat_activity. If this information is |
|
0 commit comments