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
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
get connectionString(): string
Reads the value fron environment variable name that should hold the connection string.
Returns
string
Inherited from
connectionStringEnvVar
Get Signature
get connectionStringEnvVar(): string
Returns the unique environment variable name that should hold the connection string.
Returns
string
Inherited from
Database
.connectionStringEnvVar
databaseId
Get Signature
get databaseId(): string
Database ID
Note: Alias of ìd
.
Returns
string
Inherited from
Constructors
new PostgresDatabase()
new PostgresDatabase(databaseName): PostgresDatabase
Parameters
Parameter | Type | Description |
---|---|---|
|
| Database name. |
Returns
Inherited from
Properties
Property | Modifier | Type | Description |
---|---|---|---|
databaseName | readonly | string | Database name. |
id | readonly | string | Unique ID |