Registry / database / pg-people

pg-people

JSON →
library2.3.0jsnpmunverified

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-people
INSTALL
IMPORT
SIG · PG-PEOPLE
P
pg-people
databasejavascriptv2.3.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

PgPeoplePlugin
const PgPeople = require('pg-people'); // then register with Hapi server.register({ plugin: PgPeople, options: ... })
import PgPeople from 'pg-people'; // Not directly compatible with Node 6.5 and CommonJS export
The package uses CommonJS `module.exports`, consistent with its Node.js 6.5.0 engine requirement. It exports the plugin definition directly.
getAllPeople
await request.server.pg.people.getAllPeople();
import { getAllPeople } from 'pg-people'; // Functions are exposed via Hapi's request/server object, not direct imports.
Functions are exposed on the Hapi `request` or `server` objects after the plugin is registered, usually under a `pg.people` or `pg.organisations` namespace.
add
await request.server.pg.people.add(userObj, cb);
const { add } = require('pg-people'); // Functions are not directly importable from the package.
As a Hapi plugin, its core functionality is accessed through the Hapi `request` or `server` context, specifically `request.server.pg.people` for user operations.

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.

const Hapi = require('@hapi/hapi'); const PgPeople = require('pg-people'); const init = async () => { const server = Hapi.server({ port: 3000, host: 'localhost' }); // In a real application, you would register a Hapi plugin for PostgreSQL // connectivity, e.g., hapi-pg or hapi-pg-promise, to provide `request.pg`. // For this quickstart, we'll mock `request.pg` to simulate its presence. await server.register({ plugin: { name: 'mock-pg-connector', version: '1.0.0', register: async function (serverInstance) { serverInstance.decorate('request', 'pg', { query: async (sql, params) => { console.log('Mock PG query:', sql, params); if (sql.includes('SELECT') && sql.includes('people')) { return { rows: [{ id: 1, first_name: 'Mock', last_name: 'Person', email: 'mock@example.com' }] }; } return { rows: [] }; } }); } } }); await server.register({ plugin: PgPeople, options: { // WARNING: `reset: true` will clear existing data in `people` and `organisations` tables. // Use with extreme caution, especially in production environments. reset: false, people: [] } }); server.route({ method: 'GET', path: '/people', handler: async (request, h) => { try { // Accessing functions via request.server.pg.people as shown in README const people = await request.server.pg.people.getAllPeople(); return h.response(people).code(200); } catch (error) { console.error('Error fetching people:', error.message); return h.response({ message: 'Failed to fetch people' }).code(500); } } }); await server.start(); console.log(`Server running on ${server.info.uri}`); }; process.on('unhandledRejection', (err) => { console.error(err); process.exit(1); }); init();
Debug
Known issues
breakingThe `reset: true` option in the plugin configuration will truncate and re-populate the `people`, `organisations`, and `tags_organisations` tables with the data provided in `people`, `organisations`, and `tags_orgs` options. This will lead to irreversible data loss if used carelessly.
fix
Always set `reset: false` in production environments unless a full data reset is intentionally desired. Carefully review the initial data provided in the options.
affects: >=2.0.0
gotchaThis plugin implicitly relies on an existing PostgreSQL client being exposed on the Hapi `request.pg` object. It does not provide its own database connection mechanism. Without another Hapi plugin (e.g., `hapi-pg` or `hapi-pg-promise`) that sets up `request.pg`, the plugin will fail.
fix
Ensure a compatible Hapi PostgreSQL connection plugin is registered and configured *before* `pg-people` to expose the `request.pg` object.
affects: >=2.0.0
gotchaThe `engines.node` specification (`^6.5.0`) in its `package.json` suggests that this package might not be fully compatible with recent Node.js versions (e.g., Node.js 14+ or 16+ which are LTS) or modern Hapi versions (@hapi/hapi v17+). This could lead to runtime errors or unexpected behavior.
fix
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.
affects: >=2.0.0
gotchaSeveral exposed functions, such as `edit`, `toggleActive` (for both people and organizations), and `getBy` for `id`, return a `Boom.notFound, 404 error` (or simply an empty array for `edit` under certain conditions) if the specified `userId` or `orgId` does not exist. Developers must handle these specific error types or empty array responses.
fix
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.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'people')
The `pg-people` plugin was either not registered with the Hapi server, or the `request.pg` object (from a separate PostgreSQL connection plugin) was not available when `pg-people` attempted to decorate it.
fix
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`.
Error: Role "your_user" does not exist
The PostgreSQL database credentials used by the underlying `request.pg` connection are incorrect, or the specified database user does not have the necessary permissions.
fix
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.
Error: Column 'column_name' does not exist
The plugin's automatic table creation might have failed, or the database schema expected by `pg-people` has been altered or is out of sync with the plugin's internal expectations.
fix
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`.
Boom.notFound, 404 error
An operation like `edit`, `toggleActive`, or `getBy(id, ...)` was attempted with a `userId` or `orgId` that does not exist in the database.
fix
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.
Upgrade
Version history
2.3.0latest on npm
Audit
Dependencies
hapirequiredPeer dependency for integration as a Hapi server plugin. The plugin decorates the Hapi server and request objects.
pgrequiredRuntime dependency for interacting with PostgreSQL. The plugin expects an underlying PostgreSQL connection, likely provided by another Hapi plugin that exposes a 'pg' client.
boomrequiredUsed internally for standardizing error responses, such as `Boom.notFound` for 404 errors.
Agent activity
19 hits · last 30 days
node
14
Amazon
1
OpenAI (training)
1
Resources