From: Daniele Varrazzo Date: Sat, 1 Jun 2024 11:05:54 +0000 (+0200) Subject: docs: extend on the type info note X-Git-Tag: 3.2.0~21 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=a13f97b0176d0e7b020721773f69ce2fd7404a1b;p=thirdparty%2Fpsycopg.git docs: extend on the type info note --- diff --git a/docs/advanced/adapt.rst b/docs/advanced/adapt.rst index 4323b07de..66a8edbcf 100644 --- a/docs/advanced/adapt.rst +++ b/docs/advanced/adapt.rst @@ -119,10 +119,31 @@ you only need to implement the `~psycopg.abc.Dumper.dump()` method:: >>> conn.execute("SELECT xpath('//title/text()', %s)", [elem]).fetchone()[0] ['Manual'] -Note that it is possible to use a `~psycopg.types.TypesRegistry`, exposed by -any `~psycopg.abc.AdaptContext`, to obtain information on builtin types, or -extension types if they have been registered on that context using the -`~psycopg.types.TypeInfo`\.\ `~psycopg.types.TypeInfo.register()` method. +.. note:: + + You can use a `~psycopg.types.TypesRegistry`, exposed by + any `~psycopg.abc.AdaptContext`, to obtain information on builtin types, in + the form of a `TypeInfo` object:: + + # Global types registry + >>> psycopg.adapters.types["text"] + + + # Types registry on a connection + >>> conn.adapters.types["integer"] + + + The same method can be used to get information about extension types if + they have been registered on that context using the + `~psycopg.types.TypeInfo`\.\ `~psycopg.types.TypeInfo.register()` method:: + + >>> (t := psycopg.types.TypeInfo.fetch(conn, "hstore")) + + + >>> t.register() # globally + + >>> psycopg.adapters.types["hstore"] + .. _adapt-example-float: