Skip to content

Commit

Permalink
Merge pull request #252 from adrien-berchet/doc/reflection
Browse files Browse the repository at this point in the history
Add reflection example in doc
  • Loading branch information
adrien-berchet committed Mar 17, 2020
2 parents fb300b0 + 0acd103 commit ecf2bb1
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion doc/core_tutorial.rst
Expand Up @@ -53,7 +53,7 @@ we create a ``lake_table`` object, which will correspond to the
This table is composed of three columns, ``id``, ``name`` and ``geom``. The
``geom`` column is a :class:`geoalchemy2.types.Geometry` column whose
``geometry_type`` is ``POLYGON``.

Any ``Table`` object is added to a ``MetaData`` object, which is a catalog of
``Table`` objects (and other related objects).

Expand All @@ -73,6 +73,21 @@ In that case every ``Table`` that's referenced to by ``metadata`` would be
created in the database. The ``metadata`` object includes one ``Table`` here,
our now well-known ``lake_table`` object.

Reflecting tables
-----------------

The `reflection system of SQLAlchemy
<http://docs.sqlalchemy.org/en/latest/core/schema.html#metadata-reflection>`_ can be
used on tables containing :class:`geoalchemy2.types.Geometry` or
:class:`geoalchemy2.types.Geography` columns. In this case, the type must be imported to
be registered into SQLAlchemy, even if it is not used explicitely.

>>> from geoalchemy2 import Geometry # <= not used but must be imported
>>> from sqlalchemy import create_engine, MetaData
>>> engine = create_engine("postgresql://myuser:mypass@mydb.host.tld/mydbname")
>>> meta = MetaData()
>>> meta.reflect(bind=engine)

Insertions
----------

Expand Down

0 comments on commit ecf2bb1

Please sign in to comment.