Skip to main content

Class: MySqlEntityStorageConnector<T>

Class for performing entity storage operations using MySql.

Type Parameters

T

T = unknown

Implements

  • IEntityStorageMigrationConnector<T>

Constructors

Constructor

new MySqlEntityStorageConnector<T>(options): MySqlEntityStorageConnector<T>

Create a new instance of MySqlEntityStorageConnector.

Parameters

options

IMySqlEntityStorageConnectorConstructorOptions

The options for the connector.

Returns

MySqlEntityStorageConnector<T>

Properties

CLASS_NAME

readonly static CLASS_NAME: string

Runtime name for the class.

Methods

className()

className(): string

Returns the class name of the component.

Returns

string

The class name of the component.

Implementation of

IEntityStorageMigrationConnector.className


health()

health(): Promise<IHealth[]>

Get the health of the component.

Returns

Promise<IHealth[]>

The health of the component.

Implementation of

IEntityStorageMigrationConnector.health


getSchema()

getSchema(): IEntitySchema

Get the schema for the entities.

Returns

IEntitySchema

The schema for the entities.

Implementation of

IEntityStorageMigrationConnector.getSchema


bootstrap()

bootstrap(nodeLoggingComponentType?): Promise<boolean>

Initialize the MySql environment.

Parameters

nodeLoggingComponentType?

string

Optional type of the logging component.

Returns

Promise<boolean>

A promise that resolves to a boolean indicating success.

Implementation of

IEntityStorageMigrationConnector.bootstrap


stop()

stop(nodeLoggingComponentType?): Promise<void>

The component needs to be stopped when the node is closed.

Parameters

nodeLoggingComponentType?

string

The node logging component type.

Returns

Promise<void>

Nothing.

Implementation of

IEntityStorageMigrationConnector.stop


get()

get(id, secondaryIndex?, conditions?): Promise<T | undefined>

Get an entity from MySql.

Parameters

id

string

The id of the entity to get, or the index value if secondaryIndex is set.

secondaryIndex?

keyof T

Get the item using a secondary index.

conditions?

object[]

The optional conditions to match for the entities.

Returns

Promise<T | undefined>

The object if it can be found or undefined.

Implementation of

IEntityStorageMigrationConnector.get


set()

set(entity, conditions?): Promise<void>

Set an entity.

Parameters

entity

T

The entity to set.

conditions?

object[]

The optional conditions to match for the entities.

Returns

Promise<void>

The id of the entity.

Implementation of

IEntityStorageMigrationConnector.set


setBatch()

setBatch(entities): Promise<void>

Set multiple entities in a batch.

Parameters

entities

T[]

The entities to set.

Returns

Promise<void>

Nothing.

Implementation of

IEntityStorageMigrationConnector.setBatch


empty()

empty(): Promise<void>

Empty the entity storage.

Returns

Promise<void>

Nothing.

Implementation of

IEntityStorageMigrationConnector.empty


remove()

remove(id, conditions?): Promise<void>

Remove the entity.

Parameters

id

string

The id of the entity to remove.

conditions?

object[]

The optional conditions to match for the entities.

Returns

Promise<void>

Nothing.

Implementation of

IEntityStorageMigrationConnector.remove


teardown()

teardown(nodeLoggingComponentType?): Promise<boolean>

Teardown the entity storage by dropping the table.

Parameters

nodeLoggingComponentType?

string

The node logging component type.

Returns

Promise<boolean>

True if the teardown process was successful.

Implementation of

IEntityStorageMigrationConnector.teardown


removeBatch()

removeBatch(ids): Promise<void>

Remove multiple entities by their primary key IDs.

Parameters

ids

string[]

The ids of the entities to remove.

Returns

Promise<void>

Nothing.

Implementation of

IEntityStorageMigrationConnector.removeBatch


query()

query(conditions?, sortProperties?, properties?, cursor?, limit?): Promise<{ entities: Partial<T>[]; cursor?: string; }>

Find all the entities which match the conditions.

Parameters

conditions?

EntityCondition<T>

The conditions to match for the entities.

sortProperties?

object[]

The optional sort order.

properties?

keyof T[]

The optional properties to return, defaults to all.

cursor?

string

The cursor to request the next chunk of entities.

limit?

number

The suggested number of entities to return in each chunk, in some scenarios can return a different amount.

Returns

Promise<{ entities: Partial<T>[]; cursor?: string; }>

All the entities for the storage matching the conditions, and a cursor which can be used to request more entities.

Implementation of

IEntityStorageMigrationConnector.query


count()

count(conditions?): Promise<number>

Count all the entities which match the conditions.

Parameters

conditions?

EntityCondition<T>

The optional conditions to match for the entities.

Returns

Promise<number>

The total count of entities in the storage.

Implementation of

IEntityStorageMigrationConnector.count


getPartitionContextIds()

getPartitionContextIds(): Promise<IContextIds[]>

Get all unique partition context ids present in the table.

Returns

Promise<IContextIds[]>

An array of context id objects, one per unique partition.

Implementation of

IEntityStorageMigrationConnector.getPartitionContextIds


createTargetConnector()

createTargetConnector<U>(newEntitySchema): Promise<IEntityStorageConnector<U>>

Create the target connector for performing the migration using a temporary table.

Type Parameters

U

U

Parameters

newEntitySchema

string

The name of the new entity schema to create the connector for.

Returns

Promise<IEntityStorageConnector<U>>

Connector for performing the migration.

Implementation of

IEntityStorageMigrationConnector.createTargetConnector


finalizeMigration()

finalizeMigration<U>(targetConnector, options?, loggingComponentType?): Promise<MySqlEntityStorageConnector<U>>

Finalize the migration by dropping the source table and renaming the migration table to the original name.

Type Parameters

U

U

Parameters

targetConnector

MySqlEntityStorageConnector<U>

The connector holding the migrated data in a temporary table.

options?

IMigrationOptions

The options to control how the migration is finalized.

loggingComponentType?

string

The logging component type to use during finalization.

Returns

Promise<MySqlEntityStorageConnector<U>>

The final connector using the original table name with the new schema.

Implementation of

IEntityStorageMigrationConnector.finalizeMigration


cleanupMigration()

cleanupMigration<U>(targetConnector, options?, loggingComponentType?): Promise<void>

Cleanup a failed or aborted migration by dropping the temporary migration table.

Type Parameters

U

U

Parameters

targetConnector

IEntityStorageConnector<U> | undefined

The target connector to cleanup.

options?

IMigrationOptions

The options to control how the migration is cleaned up.

loggingComponentType?

string

The optional component type to use for logging.

Returns

Promise<void>

A promise that resolves when the cleanup is complete.

Implementation of

IEntityStorageMigrationConnector.cleanupMigration


databaseExists()

databaseExists(): Promise<boolean>

Check if the database exists.

Returns

Promise<boolean>

True if the database exists, false otherwise.


close()

close(): Promise<void>

Close the connection pool and release all connections. Should be called when the connector is no longer needed.

Returns

Promise<void>

Nothing.