Skip to content

@sourceloop/reporting-service / Exports / PsqlSequelizeStrategy

Class: PsqlSequelizeStrategy

Hierarchy

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new PsqlSequelizeStrategy(sequelizeObj, logger, queryUtility)

Parameters

Name Type
sequelizeObj Sequelize
logger ILogger
queryUtility QueryUtilityInterface

Overrides

BaseSequelize.constructor

Defined in

services/reporting-service/src/strategies/sequelize/psql-sequelize-strategy.ts:21

Properties

logger

logger: ILogger

Inherited from

BaseSequelize.logger

Defined in

services/reporting-service/src/strategies/sequelize/base-sequelize.ts:16


queryUtil

queryUtil: QueryUtilityInterface

Defined in

services/reporting-service/src/strategies/sequelize/psql-sequelize-strategy.ts:20


sequelize

sequelize: Sequelize

Defined in

services/reporting-service/src/strategies/sequelize/psql-sequelize-strategy.ts:19


sequilizeQuertUtility

sequilizeQuertUtility: QueryUtilityInterface

Inherited from

BaseSequelize.sequilizeQuertUtility

Defined in

services/reporting-service/src/strategies/sequelize/base-sequelize.ts:17

Methods

applyRowLevelFilter

applyRowLevelFilter(initialQuery): Promise<StructuredQueryInterface>

The function applies a row-level filter to a query and returns the modified query.

Parameters

Name Type Description
initialQuery StructuredQueryInterface The initialQuery parameter is an instance of the StructuredQueryInterface. It represents the initial query that you want to apply a row-level filter to.

Returns

Promise<StructuredQueryInterface>

The initialQuery is being returned.

Overrides

BaseSequelize.applyRowLevelFilter

Defined in

services/reporting-service/src/strategies/sequelize/psql-sequelize-strategy.ts:210


checkIfColumnsExists

checkIfColumnsExists(columnEntityPairs): Promise<boolean>

The function checkIfColumnsExists checks if a list of column-entity pairs exists in the database.

Parameters

Name Type Description
columnEntityPairs ColumnEntityPair[] An array of objects, where each object represents a pair of column and entity. Each object should have the following properties:

Returns

Promise<boolean>

The function checkIfColumnsExists returns a Promise that resolves to a boolean value.

Overrides

BaseSequelize.checkIfColumnsExists

Defined in

services/reporting-service/src/strategies/sequelize/psql-sequelize-strategy.ts:172


checkIfDataSourceExists

checkIfDataSourceExists(dataSourceNames): Promise<boolean>

The function checkIfDataSourceExists checks if a list of data source names exist in the database.

Parameters

Name Type Description
dataSourceNames string[] An array of strings representing the names of the data sources to check.

Returns

Promise<boolean>

The function checkIfDataSourceExists returns a Promise that resolves to a boolean value.

Overrides

BaseSequelize.checkIfDataSourceExists

Defined in

services/reporting-service/src/strategies/sequelize/psql-sequelize-strategy.ts:138


deleteRecord

Private deleteRecord(dataSource, data, identifier): Promise<AnyObject>

The deleteRecord function deletes a record from a specified data source using the provided identifier.

Parameters

Name Type Description
dataSource string The dataSource parameter is a string that represents the name of the table or data source from which the record needs to be deleted.
data IngestReportRecord The data parameter is an object that represents the change data capture (CDC) for a record. It contains the current value of the record being deleted.
identifier string The identifier parameter is a string that represents the column name in the database table that uniquely identifies a record. It is used in the WHERE clause of the delete query to specify which record(s) should be deleted.

Returns

Promise<AnyObject>

an object with a property "affectedRecords" which contains the result of the delete operation.

Defined in

services/reporting-service/src/strategies/sequelize/psql-sequelize-strategy.ts:315


generateColumnForTable

generateColumnForTable(result): Promise<ColumnForDataSourceModel[]>

The function generates columns for a table by converting the data types and mapping the column properties.

Parameters

Name Type Description
result AnyObject An array of objects representing the result of a database query. Each object in the array should have the following properties:

Returns

Promise<ColumnForDataSourceModel[]>

The function generateColumnForTable returns a promise that resolves to an array of ColumnForDataSourceModel objects.

Defined in

services/reporting-service/src/strategies/sequelize/psql-sequelize-strategy.ts:366


getSchemaAndTable

getSchemaAndTable(dataSourceName): Object

Parameters

Name Type
dataSourceName string

Returns

Object

Name Type
schema string
tableName string

Defined in

services/reporting-service/src/strategies/sequelize/psql-sequelize-strategy.ts:353


listDataSourceColumns

listDataSourceColumns(dataSource): Promise<ColumnForDataSourceModel[]>

The function listDataSourceColumns retrieves column information for a given data source using a SQL query.

Parameters

Name Type Description
dataSource string The dataSource parameter is a string that represents the name of the data source or table from which you want to fetch the columns.

Returns

Promise<ColumnForDataSourceModel[]>

a Promise that resolves to an array of objects of type ColumnForDataSourceModel.

Overrides

BaseSequelize.listDataSourceColumns

Defined in

services/reporting-service/src/strategies/sequelize/psql-sequelize-strategy.ts:106


listdataSources

listdataSources(): Promise<DataSourceList[]>

This function retrieves a list of data sources from a database and formats them into an array of DataSourceList objects.

Returns

Promise<DataSourceList[]>

The listdataSources function returns an array of objects with properties dataSourceName and displayName. Each object in the array represents a data source retrieved from the database query. The dataSourceName property is a combination of the table_schema and table_name values from the database query result, while the displayName property is also a combination of the table_schema

Overrides

BaseSequelize.listdataSources

Defined in

services/reporting-service/src/strategies/sequelize/psql-sequelize-strategy.ts:43


manageRecord

manageRecord(dataSource, data, identifier?): Promise<AnyObject>

The function manageRecord handles different operations (INSERT, UPDATE, DELETE) on a given data source using a specified identifier.

Parameters

Name Type Default value Description
dataSource string undefined A string representing the data source where the record will be managed. This could be a database table, a file, or any other source of data.
data IngestReportRecord undefined The data parameter is an object that represents a change in the data. It typically contains the following properties:
identifier? string 'id' The identifier parameter is a string that represents the unique identifier for the record in the data source. It is used to identify the record that needs to be updated or deleted.

Returns

Promise<AnyObject>

The manageRecord function returns a Promise that resolves to an AnyObject object.

Overrides

BaseSequelize.manageRecord

Defined in

services/reporting-service/src/strategies/sequelize/psql-sequelize-strategy.ts:227


query

query(queryObject): Promise<AnyObject[]>

This TypeScript function asynchronously executes a query based on a provided query object or SQL string using Sequelize and returns the result as an array of objects.

Parameters

Name Type Description
queryObject string | StructuredQueryInterface The queryObject parameter in the query function can be either a StructuredQueryInterface object or a string representing a query. If the queryObject is not a string, it is first translated into a SQL query using the translateQuery method before executing the query using

Returns

Promise<AnyObject[]>

The query function returns a Promise that resolves to an array of objects (AnyObject[]) representing the result of the executed query.

Overrides

BaseSequelize.query

Defined in

services/reporting-service/src/strategies/sequelize/psql-sequelize-strategy.ts:75


sanitizeValue

sanitizeValue(value): JSONValueType

Parameters

Name Type
value JSONValueType

Returns

JSONValueType

Inherited from

BaseSequelize.sanitizeValue

Defined in

services/reporting-service/src/strategies/sequelize/base-sequelize.ts:23


translateQuery

translateQuery(queryObject): Promise<{ bind: AnyObject ; query: string }>

Parameters

Name Type
queryObject StructuredQueryInterface

Returns

Promise<{ bind: AnyObject ; query: string }>

Inherited from

BaseSequelize.translateQuery

Defined in

services/reporting-service/src/strategies/sequelize/base-sequelize.ts:55


upsertRecord

Private upsertRecord(dataSource, data, identifier?): Promise<AnyObject>

The upsertRecord function inserts or updates a record in a specified data source using the provided data, with support for sanitization and conflict resolution.

Parameters

Name Type Default value Description
dataSource string undefined The dataSource parameter is a string that represents the name of the table or data source where the record will be inserted or updated.
data IngestReportRecord undefined The data parameter is an object that represents the data to be upserted into the database. It should have a property called currentValue which contains the actual data to be inserted or updated.
identifier? string 'id' The identifier parameter is a string that specifies the column name used as the identifier for upserting records. In the code, it is set to 'id' by default, but you can provide a different column name if needed.

Returns

Promise<AnyObject>

an object with a property "affectedRecords" which contains the result of the upsert operation.

Defined in

services/reporting-service/src/strategies/sequelize/psql-sequelize-strategy.ts:259