Database Dialects

December 20, 2024 ยท View on GitHub

What are Database Dialects?

The AWS Advanced NodeJS Wrapper is a wrapper that requires an underlying driver. It is currently compatible with pg and mysql2. Database dialects help the AWS Advanced NodeJS Wrapper determine what kind of underlying database is being used. To function correctly, the AWS Advanced NodeJS Wrapper requires details unique to specific databases such as the default port number or the method to get the current host from the database. These details can be defined and provided to the AWS Advanced NodeJS Wrapper by using database dialects.

Configuration Parameters

NameRequiredDescriptionExample
dialectNo (see notes below)The dialect code of the desired database type.DialectCodes.AURORA_MYSQL or aurora-mysql

Note

The dialect parameter is not required. When it is not provided by the user, the AWS Advanced NodeJS Wrapper will attempt to determine which of the existing dialects to use based on other connection details. However, if the dialect is known by the user, it is preferable to set the dialect parameter because it will take time to resolve the dialect.

List of Available Dialect Codes

Dialect codes specify what kind of database any connections will be made to.

Dialect Code ReferenceValueDatabase
AURORA_MYSQLaurora-mysqlAurora MySQL
RDS_MULTI_AZ_MYSQLrds-multi-az-mysqlAmazon RDS MySQL Multi-AZ DB Cluster Deployments
RDS_MYSQLrds-mysqlAmazon RDS MySQL
MYSQLmysqlMySQL
AURORA_PGaurora-pgAurora PostgreSQL
RDS_MULTI_AZ_PGrds-multi-az-pgAmazon RDS PostgreSQL Multi-AZ DB Cluster Deployments
RDS_PGrds-pgAmazon RDS PostgreSQL
PGpgPostgreSQL
CUSTOMcustomSee custom dialects. This code is not required when using custom dialects.

Custom Dialects

If you are interested in using the AWS Advanced NodeJS Wrapper but your desired database type is not currently supported, it is possible to create a custom dialect.

To create a custom dialect, implement the DatabaseDialect interface. For databases clusters that are aware of their topology, the TopologyAwareDatabaseDialect interface should also be implemented. For database clusters that use an Aurora Limitless Database then LimitlessDatabaseDialect should be implemented.

See the following classes for examples:

  • PgDatabaseDialect
    • This is a generic dialect that should work with any PostgreSQL database.
  • AuroraPgDatabaseDialect
    • This dialect is an extension of PgDatabaseDialect, but also implements the TopologyAwareDatabaseDialect and LimitlessDatabaseDialect interface.
  • MySQLDatabaseDialect
    • This is a generic dialect that should work with any MySQL database.
  • AuroraMySQLDatabaseDialect
    • This dialect is an extension of MySQLDatabaseDialect, but also implements the TopologyAwareDatabaseDialect interface.

Once the custom dialect class has been created, tell the AWS Advanced NodeJS Wrapper to use it by setting the customDatabaseDialect parameter. It is not necessary to set the dialect parameter in this case. See below for an example:

myDialect: DatabaseDialect = new CustomDialect();

const client = new AwsPGClient({
  ...
  customDatabaseDialect: myDialect
  ...
});