pg-people is a Hapi plugin designed to manage 'people' and 'organisations' data within a PostgreSQL database. As of version 2.3.0, it provides a structured approach for user management, including adding users, updating passwords, retrieving user and organization details, and toggling account activity. It integrates with Hapi by exposing its functions via the `request.server.pg.people` and `request.server.pg.organisations` objects after registration. The plugin automatically creates necessary tables (`people`, `organisations`, `tags_organisations`) if they don't exist, and offers an option to reset tables with initial data. Its release cadence appears tied to the Hapi ecosystem, targeting older Node.js environments (engine `^6.5.0`). A key differentiator is its seamless integration with Hapi's request lifecycle, extending `request.pg` which implies a reliance on another Hapi plugin to establish the underlying PostgreSQL connection.
npm install pg-peopleVerified import paths — ran on the pinned version, not inferred.
Sets up a basic Hapi server, registers a mock PostgreSQL connector, then registers `pg-people` and defines a route to demonstrate fetching all people from the database. This example highlights the typical Hapi plugin registration and function access pattern.
Always set `reset: false` in production environments unless a full data reset is intentionally desired. Carefully review the initial data provided in the options.
Ensure a compatible Hapi PostgreSQL connection plugin is registered and configured *before* `pg-people` to expose the `request.pg` object.
Test thoroughly in your target Node.js and Hapi environment. Consider using a Node.js version closer to 6.x or carefully reviewing the package's dependencies and source for compatibility with newer environments. Migration to `@hapi/hapi` might require code adjustments.
Implement robust error handling and check for empty array responses when interacting with these functions to correctly manage scenarios where an entity is not found.
Verify that `server.register(PgPeople)` is called correctly and that a Hapi plugin providing `request.pg` (e.g., `hapi-pg`) is registered and configured *before* `pg-people`.
Ensure your PostgreSQL connection plugin (which populates `request.pg`) is configured with the correct username, password, host, and database name, and that the user has appropriate database privileges.
Check your database logs for table creation errors during Hapi server startup. If safe to do so (e.g., in a development environment), you might try running the plugin with `reset: true` (after backing up data) to force table recreation. Ensure no external process modifies the tables `people`, `organisations`, `tags_organisations`.
Before performing update or toggle operations, verify the existence of the `userId` or `orgId` using a retrieval method. Implement client-side validation or appropriate error handling for non-existent entities.