Skip to content

workloads / main / PostgresDatabase

Class: PostgresDatabase ​

Workload for PostgreSQL databases.

A PostgresDatabase workload is initialized with:

  • A valid database name.

The environment variable with the connection string for the database is named after the databaseName and the databaseId. See examples.

NOTES

When launching the development or test containers with npx monolayer start dev, the environment variable with the connection string for the workload's Docker container will be written to the corresponding dotenv file (.env.local or .env.local.test)

Example ​

ts
import { PostgreSQL } from "@monolayer/sdk";
import pg from "pg";

// Workloads on different database servers
export const producstDb = new PostgresDatabase("products");

export const analyticsDb = new PostgresDatabase("analytics");

Extends ​

Accessors ​

connectionString ​

Get Signature ​

ts
get connectionString(): string

Reads the value fron environment variable name that should hold the connection string.

Returns ​

string

Inherited from ​

Database.connectionString


connectionStringEnvVar ​

Get Signature ​

ts
get connectionStringEnvVar(): string

Returns the unique environment variable name that should hold the connection string.

Returns ​

string

Inherited from ​

Database.connectionStringEnvVar


databaseId ​

Get Signature ​

ts
get databaseId(): string

Database ID

Note: Alias of ìd.

Returns ​

string

Inherited from ​

Database.databaseId

Constructors ​

new PostgresDatabase() ​

ts
new PostgresDatabase(databaseName): PostgresDatabase

Parameters ​

ParameterTypeDescription

databaseName

string

Database name.

Returns ​

PostgresDatabase

Inherited from ​

Database.constructor

Properties ​

PropertyModifierTypeDescription
databaseNamereadonlystringDatabase name.
idreadonlystringUnique ID