This package contains a collection of components that are used in the Shared Node Architecture Component Kit (SNACK) to serve as more low-level building blocks for building applications.
PGDatabaseDriver is a class that is used to interact with a PostgreSQL database. It is a wrapper around the pg library that provides a more structured way to interact with the database. Additionally it operates in a singletons pattern to ensure that only one connection is made to the database regardless of how many times it is instantiated.
PGDatabaseDriver. This can be done by using the ConfigurationBuilder and setGlobalConfig functions. It is useful to have a setup file that is imported at the beginning of the application to set the configuration.
javascript
import { ConfigurationBuilder, setGlobalConfig } from '@timmons-group/snack-blocks';
const databaseConfigurationBuilder = new ConfigurationBuilder();
const databaseConfiguration = await(
databaseConfigurationBuilder
.withSSM( process.env.SSMPath + "connectionString")
.build()
);
setGlobalConfig(databaseConfiguration);
`
And in a file that uses the PGDatabaseDriver:
`javascript
import 'setup.js'; // Import the setup file to set the configuration
import { PGDatabaseDriver } from '@timmons-group/snack-blocks';
const databaseDriver = PGDatabaseDriver();
const result = await databaseDriver.query('SELECT * FROM table');
``