View on GitHub

Library API Documentation

Documentation for Library API Packages

Library Core / src / CatalogDatabase

Class: CatalogDatabase

src.CatalogDatabase

Provides extra methods for running preset queries against a catalog.

Hierarchy

Table of contents

Constructors

Methods

Constructors

constructor

new CatalogDatabase(path)

Parameters

Name Type Description
path string The path to the database.

Overrides

Database.constructor

Defined in

src/classes/Database.ts:79

Methods

getMediaDetails

getMediaDetails(__namedParameters): Promise<null | MediaDetailsDTO>

deprecated These details are no longer found in the main catalog. Use getMediaCatalog instead and use the getMediaDetails method on the returned class.

Retrieves information about a video from the main catalog. The video details found within a publication’s database contain limited information about the video itself. Most of this information is contained within the main catalog but mapped completely differently.

This method allows passing in the video returned from the publication to get more details from the catalog. The returned image will be of the highest quality available (biggest size).

example

const video = publication.getVideo(...)
const details = await db.getMediaDetails(video)

Parameters

Name Type
__namedParameters Object
__namedParameters.doc string | number
__namedParameters.issue string | number
__namedParameters.languageId? number
__namedParameters.track string | number
__namedParameters.type "pub" | "doc"

Returns

Promise<null | MediaDetailsDTO>

MediaDetails if they exist, null if they are not found.

Defined in

src/classes/Database.ts:210


getMonthlyPublications

getMonthlyPublications(): Promise<PublicationRow[]>

deprecated This has a hardcoded date and returns unmapped data, use getPublication instead.

Returns

Promise<PublicationRow[]>

All the publications for the current month based on today.

Defined in

src/classes/Database.ts:94


getPublication

getPublication(date, downloadDir, type, languageId?): Promise<null | Publication>

Searches the database for the specified publication based on a date. If that publication is not yet downloaded, will download it to the specified directory.

todo Validate date.

Parameters

Name Type Default value Description
date string undefined The date to search for, must be formatted as yyyy-mm-dd.
downloadDir string undefined The directory to download the publication to if it does not exist.
type PublicationType undefined See PublicationType
languageId number 0 The Meps Language Id to search for. Defaults to 0 (English).

Returns

Promise<null | Publication>

A Publication class to help access the downloaded publication, or null if not found.

Defined in

src/classes/Database.ts:130


getPublicationByDocumentId

getPublicationByDocumentId(documentId, downloadDir, languageId?): Promise<null | Publication>

Searches the database for the specified publication based on a document id. If that publication is not yet downloaded, will download it to the specified directory.

Parameters

Name Type Default value Description
documentId string | number undefined The DocumentId (aka MepsDocumentId) to search for.
downloadDir string undefined The directory to download the publication to if it does not exist.
languageId number 0 The Meps Language Id to search for. Defaults to 0 (English).

Returns

Promise<null | Publication>

A Publication class to help access the downloaded publication, or null if not found.

Defined in

src/classes/Database.ts:157


getRelatedPublicationMedia

getRelatedPublicationMedia(relatedPublication, downloadDir, languageId?): Promise<null | { images: ImageDTO[] ; videos: VideoDTO[] }>

A convenience method that gets a publication using getPublicationByDocumentId and returns the media with getMediaByDocumentId.

Parameters

Name Type Default value Description
relatedPublication RelatedPublicationDTO undefined The related publication.
downloadDir string undefined The directory to download the publication to if it does not exist.
languageId number 0 The Meps Language Id to search for. Defaults to 0 (English).

Returns

Promise<null | { images: ImageDTO[] ; videos: VideoDTO[] }>

The media for a related publication, or null if the publication could not be found.

Defined in

src/classes/Database.ts:180


getRow

getRow<T>(query, params?): Promise<undefined | T>

Returns the first matched row of the provided query. The return type must be provided in TS as the row structure is unknown.

example

const db = new Database(path)
const row = await db.getRow<PublicationRow>(query)

Type parameters

Name
T

Parameters

Name Type Description
query string The SQL query to run.
params? QueryParams Query params to use.

Returns

Promise<undefined | T>

A single row if it exists, or undefined if not found.

Inherited from

Database.getRow

Defined in

src/classes/Database.ts:49


getRows

getRows<T>(query, params?): Promise<T[]>

Returns all matched rows of the provided query. The return type of a single row must be provided in TS as the row structure is unknown.

example

const db = new Database(path)
const rows = await db.getRows<PublicationRow>(query)

Type parameters

Name
T

Parameters

Name Type Description
query string The SQL query to run.
params? QueryParams Query params to use.

Returns

Promise<T[]>

An array of matched rows. If none were found an empty array will be returned.

Inherited from

Database.getRows

Defined in

src/classes/Database.ts:69


getSongDetails

getSongDetails(track, languageId?): Promise<null | MediaDetailsDTO>

deprecated These details may be removed from the main catalog in future. Use getMediaCatalog instead and use the getSongDetails method on the returned class.

Retrieves the video MediaDetails of a chosen song number.

Parameters

Name Type Default value Description
track number undefined The number of the track.
languageId number 0 The Meps Language Id to search for. Defaults to 0 (English).

Returns

Promise<null | MediaDetailsDTO>

MediaDetails if they exist, null if they are not found.

Defined in

src/classes/Database.ts:246