Skip to content

Postgres: plugin-storage list/count fail with "operator does not exist: boolean = integer" when filtering #920

Closed

Description

@Muzzythinks

Summary

When EmDash runs against Postgres, PluginStorage.list() and PluginStorage.count() throw operator does not exist: boolean = integer whenever a where clause is supplied. SQLite is unaffected because it silently coerces booleans to integers.

In practice this surfaces as 500s on plugin admin pages that filter their own storage. The most visible victim is emdash-smtp (the Providers and Logs admin pages both filter), but the bug applies to any plugin that calls list/count with a filter on Postgres.

Reproduction

EmDash 0.9.0, Postgres (Supabase pooler, but any Postgres reproduces it):

const storage = ctx.storage<MyDoc>('my-collection');
await storage.put({ id: 'a', name: 'foo' });
await storage.list({ where: { name: 'foo' } }); // throws on Postgres
await storage.count({ name: 'foo' });            // throws on Postgres

Stack tail:

error: operator does not exist: boolean = integer
  at … kysely … select \"id\", \"data\", \"created_at\" from \"_plugin_storage\" where … = $N

The = $N (where $N binds '1') is the smoking gun.

Root cause

packages/core/src/database/repositories/plugin-storage.ts wraps the joined where SQL in an eb(..., '=', sql.raw('1')) call at two spots:

  • line ~226 (in list)
  • line ~305 (in count)
query = query.where(({ eb }) =>
  eb(sql.join(whereSqlParts, sql.raw('')), '=', sql.raw('1'))
);

whereSqlParts already builds a complete boolean SQL expression. Wrapping it in … = 1 works on SQLite (1 = 1 after boolean→int coercion) but Postgres rejects boolean = integer with no implicit cast.

Suggested fix

Drop the wrapper in both spots; pass the joined fragment to where() directly:

query = query.where(sql.join(whereSqlParts, sql.raw('')));

Kysely.where() accepts a raw SQL fragment that evaluates to boolean, so this is the idiomatic form and works on both dialects.

Happy to open a PR with the change plus a regression test in the existing dialect-parameterised plugin-storage suite — let me know if that'd be welcome.

Environment

  • EmDash 0.9.0
  • Astro 6, @astrojs/vercel, output: 'server'
  • Postgres via emdash/db postgres() driver, Supabase session pooler
  • Node 22

Workaround

Patch node_modules/emdash/dist/search-*.mjs via patch-package, dropping the same wrapper in both bundled occurrences. Rough but unblocks Postgres deploys until upstream lands.

Activity

  1. swissky commented on Jul 9, 2026

    @swissky
    Member

    Fix is up in #1898. Root cause was in core, not emdash-smtp: PluginStorageRepository.query()/count() wrapped the where-predicate in (...) = 1 to fit Kysely's binary expression builder — fine on SQLite (boolean coerces to integer), a hard type error on Postgres. The PR passes the predicate directly as a boolean expression and adds dialect-parity regression tests that run against real Postgres in CI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions