Catalogue#

class dscat.index.Catalogue(engine)[source]#

A connection to the SQLite catalogue index.

Wraps a SQLAlchemy engine and an open connection, and exposes typed write and read helpers over the declarative schema in this module. Open one with open(), then build the schema on a fresh database with init_schema().

classmethod open(path, create=False)[source]#

Open the catalogue at path.

Parameters:
  • path (pathlib.Path) – Path to the SQLite index file.

  • create (bool, default False) – When True, create a fresh database, replacing any existing file. When False, raise if the file does not exist.

Returns:

An open catalogue.

Return type:

dscat.index.Catalogue

Raises:

FileNotFoundError – When create is False and no index exists at path.

init_schema()[source]#

Create every table and the full-text index on a fresh database.

commit()[source]#

Commit the current transaction.

upsert_dataset(name, display_name)[source]#

Insert or replace a dataset row.

upsert_version(dataset, version, ship_folder, dictionary_path)[source]#

Insert or replace a version row, stamping the current ingest time.

clear_dataset(dataset)[source]#

Delete every version, table, feature, and document row for a dataset.

insert_features(rows)[source]#

Bulk-insert feature rows.

insert_tables(rows)[source]#

Bulk-insert table rows.

insert_synonyms(pairs)[source]#

Replace the synonym table with (term, expansion) pairs.

insert_documents(rows)[source]#

Bulk-insert document rows from (dataset, version, path, kind, title) tuples.

rebuild_fts()[source]#

Rebuild the full-text index from the feature table.

datasets()[source]#

Return each dataset with its version and feature counts.

versions(dataset=None)[source]#

Return versions, newest first, with table and feature counts.

Parameters:

dataset (str, optional) – Limit to one dataset; None returns versions for all.

latest_version(dataset)[source]#

Return the newest version id for a dataset, or None when none exist.