npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@astratra/store-postgres

v1.0.2

Published

PostgreSQL persistence adapters for Astratra SaaS stores.

Readme

@astratra/store-postgres

Adapters PostgreSQL réels pour les stores usersStore et settingsStore attendus par @astratra/saas-kit — même contrat que @astratra/store-mongo, moteur différent. Les deux packages sont indépendants ; un projet Astratra choisit celui qui correspond à sa base de données.

Le package ne change pas saas-kit : il fournit juste une implémentation persistante du même contrat que les stores mémoire de développement.

Installation

npm install @astratra/store-postgres pg

pg est une dépendance peer optionnelle du package. En pratique, une application qui gère déjà sa propre connexion Postgres garde son propre Pool.

Utilisateurs

const { Pool } = require('pg');
const { createPostgresUsersStore } = require('@astratra/store-postgres');

const pool = new Pool({ connectionString: process.env.DATABASE_URL });

const usersStore = createPostgresUsersStore({
  pool,
  usersTable: 'app_users'
});

La table est créée automatiquement au premier usage (CREATE TABLE IF NOT EXISTS) avec un schéma volontairement souple : email et role sont des colonnes indexées pour les requêtes rapides, mais l'objet utilisateur complet (y compris tout champ métier propre à l'application — name, avatar, tenantId...) est stocké tel quel dans une colonne data JSONB. Aucun schéma SQL rigide à maintenir côté application.

Par défaut, email a un index unique. Pour désactiver cette contrainte :

const usersStore = createPostgresUsersStore({
  pool,
  uniqueEmail: false
});

Paramètres

const { createPostgresSettingsStore } = require('@astratra/store-postgres');

const settingsStore = createPostgresSettingsStore({
  pool,
  settingsTable: 'app_settings'
});

await settingsStore.set('timezone', 'Europe/Paris');
const allSettings = await settingsStore.getAll();

settingsStore stocke chaque réglage sous forme { key, value JSONB }.

Avec @astratra/saas-kit

const { createSaasApp } = require('@astratra/saas-kit');
const {
  createPostgresSettingsStore,
  createPostgresUsersStore
} = require('@astratra/store-postgres');

const app = createSaasApp({
  usersStore: createPostgresUsersStore({ pool }),
  settingsStore: createPostgresSettingsStore({ pool }),
  notify,
  verifyPassword
});

Les méthodes retournent toujours des objets JavaScript simples (jamais une ligne pg brute) : { ...donnéesJSONB, id }.

Cycle de vie de connexion

Chemin recommandé : passer un pool déjà géré par l'application. Dans ce mode, l'adapter ne ferme jamais ce pool.

const usersStore = createPostgresUsersStore({ pool });
await usersStore.disconnect(); // no-op pour un pool injecté

Pour un script ou un petit service autonome, l'adapter peut créer et gérer son propre Pool via connectionString. Dans ce cas, disconnect() ferme réellement ce pool.

const usersStore = createPostgresUsersStore({
  connectionString: process.env.DATABASE_URL
});

// ...
await usersStore.disconnect();

Tests

npm test --workspace @astratra/store-postgres

Les tests utilisent pg-mem (moteur SQL compatible Postgres en mémoire), donc aucune instance PostgreSQL externe n'est requise.