database for custom data types: this allows for instance to load automatically
arrays of a custom type, once a loader for the base type has been registered.
-The `!TypeInfo` object doesn't instruct Psycopg to convert a PostgreSQL
-type into a Python type: this is the role of a `Loader`. However it can extend
-the behaviour of the adapters: if you create a loader for `!MyType`, using
-`TypeInfo` you will be able to manage seamlessly arrays of `!MyType` or ranges
-and composite types using it as a subtypes.
+The `!TypeInfo` object doesn't instruct Psycopg to convert a PostgreSQL type
+into a Python type: this is the role of a `~psycopg.abc.Loader`. However it
+can extend the behaviour of the adapters: if you create a loader for
+`!MyType`, using `TypeInfo` you will be able to manage seamlessly arrays of
+`!MyType` or ranges and composite types using it as a subtype.
.. seealso:: :ref:`adaptation` describes about how to convert from Python
types to PostgreSQL types and back.
def load(self, data):
# parse the data and return a MyType instance
- MyTypeLoader.register(conn)
+ conn.adapters.register_loader("mytype", MyTypeLoader)
for record in conn.execute("select mytypearray from mytable"):
# records will return lists of MyType instances
:param conn: the connection to query
:param name: the name of the type to query. It can include a schema
name.
+ :type name: `!str` or `~psycopg.sql.Identifier`
:return: a `!TypeInfo` object populated with the type information,
`!None` if not found.
"""