Skip to content

Commit

Permalink
Tests: Remove docs/by-example/sqlalchemy/internals.rst
Browse files Browse the repository at this point in the history
Add the corresponding documentation to `inspection-reflection.rst`
instead. This will save a whole CrateDB layer setup/teardown cycle
when running doctests on it.
  • Loading branch information
amotl committed Oct 14, 2022
1 parent 8c7400e commit 1b099bd
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 52 deletions.
50 changes: 43 additions & 7 deletions docs/by-example/sqlalchemy/inspection-reflection.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,21 @@ The `runtime inspection API`_ provides the ``inspect()`` function, which
delivers runtime information about a wide variety of SQLAlchemy objects, both
within SQLAlchemy Core and the SQLAlchemy ORM.

A low level interface which provides a backend-agnostic system of loading lists
of schema, table, column, and constraint descriptions from a given database is
available. This is known as the `SQLAlchemy inspector`_.
The ``CrateDialect`` instance provides metadata about the CrateDB cluster,
like version and schema information.

>>> import sqlalchemy as sa

>>> engine = sa.create_engine(f"crate://{crate_host}")
>>> inspector = sa.inspect(engine)


Inspector usage
===============
Inspector
=========

The `SQLAlchemy inspector`_ is a low level interface which provides a backend-
agnostic system of loading lists of schema, table, column, and constraint
descriptions from a given database is available.

>>> inspector = sa.inspect(engine)

List all schemas:

Expand Down Expand Up @@ -79,6 +82,39 @@ Reflect column data types from the table metadata:
PrimaryKeyConstraint(Column('id', String(), table=<characters>, primary_key=True...


CrateDialect
============

After initializing the dialect instance with a connection instance,

>>> from crate.client.sqlalchemy.dialect import CrateDialect
>>> dialect = CrateDialect()

>>> connection = engine.connect()
>>> dialect.initialize(connection)

the database server version and default schema name can be inquired.

>>> dialect.server_version_info >= (1, 0, 0)
True

Check if schema exists:

>>> dialect.has_schema(connection, 'doc')
True

Check if table exists:

>>> dialect.has_table(connection, 'locations')
True


.. Hidden: close connection
>>> connection.close()
>>> engine.dispose()
.. _reflecting database objects: https://docs.sqlalchemy.org/en/14/core/reflection.html#reflecting-database-objects
.. _runtime inspection API: https://docs.sqlalchemy.org/en/14/core/inspection.html
.. _SQLAlchemy inspector: https://docs.sqlalchemy.org/en/14/core/reflection.html#fine-grained-reflection-with-inspector
44 changes: 0 additions & 44 deletions docs/by-example/sqlalchemy/internals.rst

This file was deleted.

1 change: 0 additions & 1 deletion src/crate/client/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,6 @@ def test_suite():
'docs/by-example/sqlalchemy/getting-started.rst',
'docs/by-example/sqlalchemy/cru.rst',
'docs/by-example/sqlalchemy/inspection-reflection.rst',
'docs/by-example/sqlalchemy/internals.rst',
module_relative=False,
setUp=setUpCrateLayerAndSqlAlchemy,
tearDown=tearDownWithCrateLayer,
Expand Down

0 comments on commit 1b099bd

Please sign in to comment.