Skip to content

feat(core): support field-level and range filters in where clause#1064

Open
Glacier-Luo wants to merge 2 commits into
emdash-cms:mainfrom
Glacier-Luo:feat/where-field-and-range-filters
Open

feat(core): support field-level and range filters in where clause#1064
Glacier-Luo wants to merge 2 commits into
emdash-cms:mainfrom
Glacier-Luo:feat/where-field-and-range-filters

Conversation

@Glacier-Luo
Copy link
Copy Markdown
Contributor

@Glacier-Luo Glacier-Luo commented May 16, 2026

What does this PR do?

The loader's where option previously only processed taxonomy-based keys (via JOIN). Non-taxonomy field names were silently discarded, forcing sites with large content libraries to load entire collections into memory and filter in JavaScript.

This adds two capabilities to getEmDashCollection's where clause:

  • Exact/multi-value match on content table columns{ series: "main" } or { series: ["main", "side"] }
  • Range comparisons{ published_at: { gte: "2024-01-01T00:00:00Z", lt: "2025-01-01T00:00:00Z" } }

Both execute at the SQL layer with parameterized queries and validated identifiers. Taxonomy filtering remains unchanged (backward compatible).

Motivation: A fiction serialization site with ~4000 chapters spanning 10+ years. The timeline page needs to filter by year (published_at range) and by series (field exact match). Without SQL-level field filtering, the only options are wasteful full-table JS filtering or dropping to raw getDb() and losing preview, visual editing, byline hydration, and request caching.

Type of change

  • Bug fix
  • Feature (requires maintainer-approved Discussion)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: Claude Opus 4.6 (Claude Code)

Screenshots / test output

 Test Files  209 passed (209)
      Tests  3305 passed (3305)

Usage examples

// Exact match on a content field
const { entries } = await getEmDashCollection("posts", {
  where: { series: "main" },
});

// Date range filtering
const { entries } = await getEmDashCollection("posts", {
  where: { published_at: { gte: "2024-01-01T00:00:00Z", lt: "2025-01-01T00:00:00Z" } },
  orderBy: { published_at: "asc" },
});

// Combined: taxonomy + field + range
const { entries } = await getEmDashCollection("posts", {
  where: { category: "fiction", series: "main", published_at: { gte: "2024-01-01" } },
});

The loader's `where` option previously only processed taxonomy-based
keys (via JOIN). Non-taxonomy field names were silently discarded,
forcing sites with large content libraries to load entire collections
into memory and filter in JavaScript.

This adds two capabilities:
- Exact/multi-value match on content table columns (AND col = ? / IN)
- Range comparisons (gt, gte, lt, lte) for date and string fields

Both are executed at the SQL layer with parameterized queries and
validated identifiers. Taxonomy filtering remains unchanged.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 16, 2026

🦋 Changeset detected

Latest commit: b4f484a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
emdash Minor
@emdash-cms/cloudflare Minor
@emdash-cms/fixture-perf-site Patch
@emdash-cms/perf-demo-site Patch
@emdash-cms/cache-demo-site Patch
@emdash-cms/admin Minor
@emdash-cms/auth Minor
@emdash-cms/blocks Minor
@emdash-cms/gutenberg-to-portable-text Minor
@emdash-cms/x402 Minor
create-emdash Minor
@emdash-cms/auth-atproto Patch
@emdash-cms/plugin-embeds Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 16, 2026

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/@emdash-cms/admin@1064

@emdash-cms/auth

npm i https://pkg.pr.new/@emdash-cms/auth@1064

@emdash-cms/blocks

npm i https://pkg.pr.new/@emdash-cms/blocks@1064

@emdash-cms/cloudflare

npm i https://pkg.pr.new/@emdash-cms/cloudflare@1064

emdash

npm i https://pkg.pr.new/emdash@1064

create-emdash

npm i https://pkg.pr.new/create-emdash@1064

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/gutenberg-to-portable-text@1064

@emdash-cms/x402

npm i https://pkg.pr.new/@emdash-cms/x402@1064

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/@emdash-cms/plugin-ai-moderation@1064

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/@emdash-cms/plugin-atproto@1064

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/@emdash-cms/plugin-audit-log@1064

@emdash-cms/plugin-color

npm i https://pkg.pr.new/@emdash-cms/plugin-color@1064

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/@emdash-cms/plugin-embeds@1064

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/@emdash-cms/plugin-forms@1064

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/@emdash-cms/plugin-webhook-notifier@1064

commit: b4f484a

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant