summaryrefslogtreecommitdiffstats
path: root/docs/api/adapt.rst
blob: e47816ce03189770e48d3ad982e31d9a51cc4f12 (plain)
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
`adapt` -- Types adaptation
===========================

.. module:: psycopg.adapt

The `!psycopg.adapt` module exposes a set of objects useful for the
configuration of *data adaptation*, which is the conversion of Python objects
to PostgreSQL data types and back.

These objects are useful if you need to configure data adaptation, i.e.
if you need to change the default way that Psycopg converts between types or
if you want to adapt custom data types and objects. You don't need this object
in the normal use of Psycopg.

See :ref:`adaptation` for an overview of the Psycopg adaptation system.

.. _abstract base class: https://docs.python.org/glossary.html#term-abstract-base-class


Dumpers and loaders
-------------------

.. autoclass:: Dumper(cls, context=None)

    This is an `abstract base class`_, partially implementing the
    `~psycopg.abc.Dumper` protocol. Subclasses *must* at least implement the
    `.dump()` method and optionally override other members.

    .. automethod:: dump

    .. attribute:: format
        :type: psycopg.pq.Format
        :value: TEXT

        Class attribute. Set it to `~psycopg.pq.Format.BINARY` if the class
        `dump()` methods converts the object to binary format.

    .. automethod:: quote

    .. automethod:: get_key

    .. automethod:: upgrade


.. autoclass:: Loader(oid, context=None)

    This is an `abstract base class`_, partially implementing the
    `~psycopg.abc.Loader` protocol. Subclasses *must* at least implement the
    `.load()` method and optionally override other members.

    .. automethod:: load

    .. attribute:: format
        :type: psycopg.pq.Format
        :value: TEXT

        Class attribute. Set it to `~psycopg.pq.Format.BINARY` if the class
        `load()` methods converts the object from binary format.


Other objects used in adaptations
---------------------------------

.. autoclass:: PyFormat
    :members:


.. autoclass:: AdaptersMap

   .. seealso:: :ref:`adaptation` for an explanation about how contexts are
       connected.

   .. automethod:: register_dumper
   .. automethod:: register_loader

   .. attribute:: types

       The object where to look up for types information (such as the mapping
       between type names and oids in the specified context).

       :type: `~psycopg.types.TypesRegistry`

   .. automethod:: get_dumper
   .. automethod:: get_dumper_by_oid
   .. automethod:: get_loader


.. autoclass:: Transformer(context=None)

    :param context: The context where the transformer should operate.
    :type context: `~psycopg.abc.AdaptContext`