File: _pg.pyi

package info (click to toggle)
pygresql 1%3A6.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,944 kB
  • sloc: python: 15,052; ansic: 5,730; makefile: 16; sh: 10
file content (638 lines) | stat: -rw-r--r-- 16,678 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
"""Type hints for the PyGreSQL C extension."""

from __future__ import annotations

from typing import Any, Callable, Iterable, Sequence, TypeVar

try:
    AnyStr = TypeVar('AnyStr', str, bytes, str | bytes)
except TypeError:  # Python < 3.10
    AnyStr = Any  # type: ignore
SomeNamedTuple = Any  # alias for accessing arbitrary named tuples

version: str
__version__: str

RESULT_EMPTY: int
RESULT_DML: int
RESULT_DDL: int
RESULT_DQL: int

TRANS_IDLE: int
TRANS_ACTIVE: int
TRANS_INTRANS: int
TRANS_INERROR: int
TRANS_UNKNOWN: int

POLLING_OK: int
POLLING_FAILED: int
POLLING_READING: int
POLLING_WRITING: int

INV_READ: int
INV_WRITE: int

SEEK_SET: int
SEEK_CUR: int
SEEK_END: int


class Error(Exception):
    """Exception that is the base class of all other error exceptions."""


class Warning(Exception):  # noqa: N818
    """Exception raised for important warnings."""


class InterfaceError(Error):
    """Exception raised for errors related to the database interface."""


class DatabaseError(Error):
    """Exception raised for errors that are related to the database."""

    sqlstate: str | None


class InternalError(DatabaseError):
    """Exception raised when the database encounters an internal error."""


class OperationalError(DatabaseError):
    """Exception raised for errors related to the operation of the database."""


class ProgrammingError(DatabaseError):
    """Exception raised for programming errors."""


class IntegrityError(DatabaseError):
    """Exception raised when the relational integrity is affected."""


class DataError(DatabaseError):
    """Exception raised for errors  due to problems with the processed data."""


class NotSupportedError(DatabaseError):
    """Exception raised when a method or database API is not supported."""


class InvalidResultError(DataError):
    """Exception when a database operation produced an invalid result."""


class NoResultError(InvalidResultError):
    """Exception when a database operation did not produce any result."""


class MultipleResultsError(InvalidResultError):
    """Exception when a database operation produced multiple results."""


class Source:
    """Source object."""

    arraysize: int
    resulttype: int
    ntuples: int
    nfields: int

    def execute(self, sql: str) -> int | None:
        """Execute a SQL statement."""
        ...

    def fetch(self, num: int) -> list[tuple]:
        """Return the next num rows from the last result in a list."""
        ...

    def listinfo(self) -> tuple[tuple[int, str, int, int, int], ...]:
        """Get information for all fields."""
        ...

    def oidstatus(self) -> int | None:
        """Return oid of last inserted row (if available)."""
        ...

    def putdata(self, buffer: str | bytes | BaseException | None
                ) -> int | None:
        """Send data to server during copy from stdin."""
        ...

    def getdata(self, decode: bool | None = None) -> str | bytes | int:
        """Receive data to server during copy to stdout."""
        ...

    def close(self) -> None:
        """Close query object without deleting it."""
        ...


class LargeObject:
    """Large object."""

    oid: int
    pgcnx: Connection
    error: str

    def open(self, mode: int) -> None:
        """Open a large object.

        The valid values for 'mode' parameter are defined as the module level
        constants INV_READ and INV_WRITE.
        """
        ...

    def close(self) -> None:
        """Close a large object."""
        ...

    def read(self, size: int) -> bytes:
        """Read data from large object."""
        ...

    def write(self, data: bytes) -> None:
        """Write data to large object."""
        ...

    def seek(self, offset: int, whence: int) -> int:
        """Change current position in large object.

        The valid values for the 'whence' parameter are defined as the
        module level constants SEEK_SET, SEEK_CUR and SEEK_END.
        """
        ...

    def unlink(self) -> None:
        """Delete large object."""
        ...

    def size(self) -> int:
        """Return the large object size."""
        ...

    def export(self, filename: str) -> None:
        """Export a large object to a file."""
        ...


class Connection:
    """Connection object.

    This object handles a connection to a PostgreSQL database.
    It embeds and hides all the parameters that define this connection,
    thus just leaving really significant parameters in function calls.
    """

    host: str
    port: int
    db: str
    options: str
    error: str
    status: int
    user : str
    protocol_version: int
    server_version: int
    socket: int
    backend_pid: int
    ssl_in_use: bool
    ssl_attributes: dict[str, str | None]

    def source(self) -> Source:
        """Create a new source object for this connection."""
        ...

    def query(self, cmd: str, args: Sequence | None = None) -> Query:
        """Create a new query object for this connection.

        Note that if the command is something other than DQL, this method
        can return an int, str or None instead of a Query.
        """
        ...

    def send_query(self, cmd: str, args: Sequence | None = None) -> Query:
        """Create a new asynchronous query object for this connection."""
        ...

    def query_prepared(self, name: str, args: Sequence | None = None) -> Query:
        """Execute a prepared statement."""
        ...

    def prepare(self, name: str, cmd: str) -> None:
        """Create a prepared statement."""
        ...

    def describe_prepared(self, name: str) -> Query:
        """Describe a prepared statement."""
        ...

    def poll(self) -> int:
        """Complete an asynchronous connection and get its state."""
        ...

    def reset(self) -> None:
        """Reset the connection."""
        ...

    def cancel(self) -> None:
        """Abandon processing of current SQL command."""
        ...

    def close(self) -> None:
        """Close the database connection."""
        ...

    def fileno(self) -> int:
        """Get the socket used to connect to the database."""
        ...

    def get_cast_hook(self) -> Callable | None:
        """Get the function that handles all external typecasting."""
        ...

    def set_cast_hook(self, hook: Callable | None) -> None:
        """Set a function that will handle all external typecasting."""
        ...

    def get_notice_receiver(self) -> Callable | None:
        """Get the current notice receiver."""
        ...

    def set_notice_receiver(self, receiver: Callable | None) -> None:
        """Set a custom notice receiver."""
        ...

    def getnotify(self) -> tuple[str, int, str] | None:
        """Get the last notify from the server."""
        ...

    def inserttable(self, table: str, values: Sequence[list|tuple],
                    columns: list[str] | tuple[str, ...] | None = None) -> int:
        """Insert a Python iterable into a database table."""
        ...

    def transaction(self) -> int:
        """Get the current in-transaction status of the server.

        The status returned by this method can be TRANS_IDLE (currently idle),
        TRANS_ACTIVE (a command is in progress), TRANS_INTRANS (idle, in a
        valid transaction block), or TRANS_INERROR (idle, in a failed
        transaction block).  TRANS_UNKNOWN is reported if the connection is
        bad.  The status TRANS_ACTIVE is reported only when a query has been
        sent to the server and not yet completed.
        """
        ...

    def parameter(self, name: str) -> str | None:
        """Look up a current parameter setting of the server."""
        ...

    def date_format(self) -> str:
        """Look up the date format currently being used by the database."""
        ...

    def escape_literal(self, s: AnyStr) -> AnyStr:
        """Escape a literal constant for use within SQL."""
        ...

    def escape_identifier(self, s: AnyStr) -> AnyStr:
        """Escape an identifier for use within SQL."""
        ...

    def escape_string(self, s: AnyStr) -> AnyStr:
        """Escape a string for use within SQL."""
        ...

    def escape_bytea(self, s: AnyStr) -> AnyStr:
        """Escape binary data for use within SQL as type 'bytea'."""
        ...

    def putline(self, line: str) -> None:
        """Write a line to the server socket."""
        ...

    def getline(self) -> str:
        """Get a line from server socket."""
        ...

    def endcopy(self) -> None:
        """Synchronize client and server."""
        ...

    def set_non_blocking(self, nb: bool) -> None:
        """Set the non-blocking mode of the connection."""
        ...

    def is_non_blocking(self) -> bool:
        """Get the non-blocking mode of the connection."""
        ...

    def locreate(self, mode: int) -> LargeObject:
        """Create a large object in the database.

        The valid values for 'mode' parameter are defined as the module level
        constants INV_READ and INV_WRITE.
        """
        ...

    def getlo(self, oid: int) -> LargeObject:
        """Build a large object from given oid."""
        ...

    def loimport(self, filename: str) -> LargeObject:
        """Import a file to a large object."""
        ...


class Query:
    """Query object.

    The Query object returned by Connection.query and DB.query can be used
    as an iterable returning rows as tuples.  You can also directly access
    row tuples using their index, and get the number of rows with the
    len() function.  The Query class also provides the several methods
    for accessing the results of the query.
    """

    def __len__(self) -> int:
        ...

    def __getitem__(self, key: int) -> object:
        ...

    def __iter__(self) -> Query:
        ...

    def __next__(self) -> tuple:
        ...

    def getresult(self) -> list[tuple]:
        """Get query values as list of tuples."""
        ...

    def dictresult(self) -> list[dict[str, object]]:
        """Get query values as list of dictionaries."""
        ...

    def dictiter(self) -> Iterable[dict[str, object]]:
        """Get query values as iterable of dictionaries."""
        ...

    def namedresult(self) -> list[SomeNamedTuple]:
        """Get query values as list of named tuples."""
        ...

    def namediter(self) -> Iterable[SomeNamedTuple]:
        """Get query values as iterable of named tuples."""
        ...

    def one(self) -> tuple | None:
        """Get one row from the result of a query as a tuple."""
        ...

    def single(self) -> tuple:
        """Get single row from the result of a query as a tuple."""
        ...

    def onedict(self) -> dict[str, object] | None:
        """Get one row from the result of a query as a dictionary."""
        ...

    def singledict(self) -> dict[str, object]:
        """Get single row from the result of a query as a dictionary."""
        ...

    def onenamed(self) -> SomeNamedTuple | None:
        """Get one row from the result of a query as named tuple."""
        ...

    def singlenamed(self) -> SomeNamedTuple:
        """Get single row from the result of a query as named tuple."""
        ...

    def scalarresult(self) -> list:
        """Get first fields from query result as list of scalar values."""

    def scalariter(self) -> Iterable:
        """Get first fields from query result as iterable of scalar values."""
        ...

    def onescalar(self) -> object | None:
        """Get one row from the result of a query as scalar value."""
        ...

    def singlescalar(self) -> object:
        """Get single row from the result of a query as scalar value."""
        ...

    def fieldname(self, num: int) -> str:
        """Get field name from its number."""
        ...

    def fieldnum(self, name: str) -> int:
        """Get field number from its name."""
        ...

    def listfields(self) -> tuple[str, ...]:
        """List field names of query result."""
        ...

    def fieldinfo(self, column: int | str | None) -> tuple[str, int, int, int]:
        """Get information on one or all fields of the query.

        The four-tuples contain the following information:
        The field name, the internal OID number of the field type,
        the size in bytes of the column or a negative value if it is
        of variable size, and a type-specific modifier value.
        """
        ...

    def memsize(self) -> int:
        """Return number of bytes allocated by query result."""
        ...


def connect(dbname: str | None = None,
            host: str | None = None,
            port: int | None = None,
            opt: str | None = None,
            user: str | None = None,
            passwd: str | None = None,
            nowait: int | None = None) -> Connection:
    """Connect to a PostgreSQL database."""
    ...


def cast_array(s: str, cast: Callable | None = None,
               delim: bytes | None = None) -> list:
    """Cast a string representing a PostgreSQL array to a Python list."""
    ...


def cast_record(s: str,
                cast: Callable | list[Callable | None] |
                      tuple[Callable | None, ...] | None = None,
                delim: bytes | None = None) -> tuple:
    """Cast a string representing a PostgreSQL record to a Python tuple."""
    ...


def cast_hstore(s: str) -> dict[str, str | None]:
    """Cast a string as a hstore."""
    ...


def escape_bytea(s: AnyStr) -> AnyStr:
    """Escape binary data for use within SQL as type 'bytea'."""
    ...


def unescape_bytea(s: AnyStr) -> bytes:
    """Unescape 'bytea' data that has been retrieved as text."""
    ...


def escape_string(s: AnyStr) -> AnyStr:
    """Escape a string for use within SQL."""
    ...


def get_pqlib_version() -> int:
    """Get the version of libpq that is being used by PyGreSQL."""
    ...


def get_array() -> bool:
    """Check whether arrays are returned as list objects."""
    ...


def set_array(on: bool) -> None:
    """Set whether arrays are returned as list objects."""
    ...


def get_bool() -> bool:
    """Check whether boolean values are returned as bool objects."""
    ...


def set_bool(on: bool | int) -> None:
    """Set whether boolean values are returned as bool objects."""
    ...


def get_bytea_escaped() -> bool:
    """Check whether 'bytea' values are returned as escaped strings."""
    ...


def set_bytea_escaped(on: bool | int) -> None:
    """Set whether 'bytea' values are returned as escaped strings."""
    ...


def get_datestyle() -> str | None:
    """Get the assumed date style for typecasting."""
    ...


def set_datestyle(datestyle: str | None) -> None:
    """Set a fixed date style that shall be assumed when typecasting."""
    ...


def get_decimal() -> type:
    """Get the decimal type to be used for numeric values."""
    ...


def set_decimal(cls: type) -> None:
    """Set a fixed date style that shall be assumed when typecasting."""
    ...


def get_decimal_point() -> str | None:
    """Get the decimal mark used for monetary values."""
    ...


def set_decimal_point(mark: str | None) -> None:
    """Specify which decimal mark is used for interpreting monetary values."""
    ...


def get_jsondecode() -> Callable[[str], object] | None:
    """Get the function that deserializes JSON formatted strings."""
    ...


def set_jsondecode(decode: Callable[[str], object] | None) -> None:
    """Set a function that will deserialize JSON formatted strings."""
    ...


def get_defbase() -> str | None:
    """Get the default database name."""
    ...


def set_defbase(base: str | None) -> None:
    """Set the default database name."""
    ...


def get_defhost() -> str | None:
    """Get the default host."""
    ...


def set_defhost(host: str | None) -> None:
    """Set the default host."""
    ...


def get_defport() -> int | None:
    """Get the default host."""
    ...


def set_defport(port: int | None) -> None:
    """Set the default port."""
    ...


def get_defopt() -> str | None:
    """Get the default connection options."""
    ...


def set_defopt(opt: str | None) -> None:
    """Set the default connection options."""
    ...


def get_defuser() -> str | None:
    """Get the default database user."""
    ...


def set_defuser(user: str | None) -> None:
    """Set the default database user."""
    ...


def get_defpasswd() -> str | None:
    """Get the default database password."""
    ...


def set_defpasswd(passwd: str | None) -> None:
    """Set the default database password."""
    ...


def set_query_helpers(*helpers: Callable) -> None:
    """Set internal query helper functions."""
    ...