.. _sqlite-export: ###################### SQLite database export ###################### ***** About ***** You can use the ``phenodata export-observations`` subcommand to export observations including metadata into an `SQLite`_ database. The database will contain the data table ``dwd_observation``, and the metadata tables ``dwd_station``, ``dwd_species``, ``dwd_phase``, ``dwd_quality_byte``, and ``dwd_quality_level``. There is also a `database view`_ called ``dwd_phenology``, which will join those tables together properly, and present a `denormalized`_ variant of the data, ready for convenient querying. If you want to create SQLite database archive files, containing **all datasets**, or just download and use them, please follow up reading the :ref:`dwd-archive` documentation section. .. _sqlite-usage: ***** Usage ***** .. _sqlite-usage-produce: Produce ======= This example walks you through the steps needed to store a subset of the phenology observation data available on DWD CDC into an SQLite database file on your machine. Let's start by defining the database name. .. code-block:: bash export DBPATH=phenodata-dwd-annual-recent-hasel.sqlite Now, export a few selected data points to keep the database size small. .. code-block:: bash phenodata export-observations \ --source=dwd --dataset=annual --partition=recent \ --station=münchen \ --year=2021,2022,2023 \ --filename=Hasel \ --target=sqlite:///${DBPATH} .. attention:: Please note that each invocation will **overwrite (replace)** all tables within the given database without confirmation. .. _sqlite-usage-consume: Consume ======= sqlite3 ------- Inquire the database schema and metadata information. .. code-block:: bash # Display all tables and views. sqlite3 "${DBPATH}" '.tables' # Display schema of all tables and views. sqlite3 "${DBPATH}" '.fullschema --indent' # Display database metadata information. sqlite3 "${DBPATH}" -csv -header 'SELECT * FROM dwd_about' Run a query on the ``dwd_phenology`` view. .. code-block:: bash sqlite3 -csv -header "${DBPATH}" 'SELECT * FROM dwd_phenology ORDER BY date;' .. code-block:: bash sqlite3 -csv -header "${DBPATH}" <`. ******* Details ******* You can always inspect the database schema using ``sqlite3 "${DBPATH}" '.fullschema --indent'``. In order to learn about how the ``dwd_phenology`` `database view`_ looks like, this SQL example can be helpful. .. code-block:: sql sqlite3 -csv -header "${DBPATH}" <