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

n8n-nodes-sql-chat-memory

v0.4.5

Published

Read-only AI Chat Memory for n8n that loads conversation history from PostgreSQL via table mapping or custom SQL.

Readme

n8n-nodes-sql-chat-memory

Read-only AI Chat Memory for n8n. Loads conversation history from PostgreSQL — either by pointing at a table in the UI or with your own SQL — and hands it to the AI Agent as ordered chat messages.

What it does

Table/SQL → rows → LangChain chat messages → AI Agent memory

  • A pure AI sub-node: connect its Memory output to an AI Agent's Memory input. It receives its data context (e.g. previous nodes' items for expressions like {{ $json.sessionId }}) through that connection — no Main input/output.
  • Uses the standard n8n Postgres credential.
  • Runs during AI Agent execution; converts rows in order:
    • user → HumanMessage
    • assistant → AIMessage
    • system → SystemMessage
  • Strictly read-only: never saves, updates, inserts, caches, or auto-persists. No polling, session management, or schema creation.

Table Mapping mode (direct mapping, no SQL)

Six fields, top to bottom:

  1. Schema / 2. Table — pick from the lists, or type a name.
  2. Session Column + Session ID — the column that groups messages into one conversation, and the value for the current one (or an expression like {{ $json.sessionId }}). Leave the column empty if the table holds a single conversation.
  3. Order Column — the date or number column that puts messages in order. Leave empty to detect it automatically. The newest messages are always loaded.
  4. Role Column (required) + Role Mappings — the column that says who wrote each message, with every value matched to the person (user), the AI (assistant) or an instruction (system). Unmatched values stop the run and name the value — nothing is guessed.
  5. Max Messages — how many past messages to load (1–1000, default 50).

The lists only load while you set up the node — never during a run.

Custom Query mode (advanced)

Only the SQL Query field. Write whatever you need — filtering, JOINs, message text built in SQL — as long as each result row looks like this:

[
  { "role": "user", "content": "hello" },
  { "role": "assistant", "content": "Hi, how can I help?" }
]

role is one of user, assistant or system. Load the newest X messages, but return them oldest first. You can use expressions. Read-only: SELECT queries only.

Missing role/content or an unsupported role produces a clear node error.

Custom query format

The Custom Query page ends with a guidance box showing this same JSON output format. Write the query however you want around that.

Intended workflow

Incoming message
    ↓
SQL Chat Memory ──────┐
                      ↓
                   AI Agent
                      ↓
                 AI response
                      ↓
             normal workflow nodes
                      ↓
             application-controlled
             database INSERT

Persist new turns with your own downstream INSERT. This node only reads.

Debugging

After an AI Agent run, open the SQL Chat Memory sub-node (or the agent's execution log): the exact messages handed to the AI are recorded there as { role, content } rows — the same shape as the Custom Query output. The node stays a pure memory sub-node with no Main input/output.

Versions

  • v1 (npm 0.1.0): SQL-only sub-node, frozen unchanged.
  • v1.1 (npm 0.2.x–0.4.5): Table Mapping UI plus Custom Query. Existing v1 workflows keep working untouched. Any table/column naming works — identifiers are quoted, never judged against examples.

Development

npm install
npm run build
npm test

Releasing (publish to npm via GitHub Actions)

  1. Push to GitHub (main branch).
  2. Repo Settings → Secrets and variables → Actions holds NPM_TOKEN (npm Automation token).
  3. Bump version in package.json for every release (npm rejects re-publishing a version).
  4. Create a GitHub Release (tag like v0.4.0). Publishing runs automatically (npm publish --access public).
  5. Install in n8n via Settings → Community nodes → Install: n8n-nodes-sql-chat-memory.