Skip to content

Fix Postgres compatibility for shipping methods queries - #31

Merged
cavewebs merged 1 commit into
mainfrom
cursor/fix-postgres-shipping-queries-a2ec
Sep 15, 2026
Merged

cavewebs merged 1 commit into
mainfrom
cursor/fix-postgres-shipping-queries-a2ec

Conversation

@cavewebs

Copy link
Copy Markdown
Contributor

Problem

Live Railway demo (EmDash storage on Neon Postgres) fails cart/shipping-methods API when attempting to query shipping methods with:

methodsStore.query({ where: { zoneId: zone.id, enabled: 1 }, limit: 50 })

Error: syntax error at or near "=" on Postgres

Root cause: EmDash's .query({ where: ... }) implementation builds SQLite-style SQL that doesn't translate correctly to Postgres syntax. The WHERE clause generation is broken for Postgres databases.

Solution

Replace all problematic .where queries with a fetch+filter pattern that works across both SQLite and Postgres:

const methods = (await methodsStore.query({ limit: 200 })).items
  .map((r) => ({ ...r.data, id: r.id }))
  .filter((m) => m.zoneId === zone.id && (m.enabled === true || (m.enabled as unknown) === 1));

Changes Made

  1. packages/core/src/routes/cart.ts

    • cart/shipping-methods route: Fetch all methods, filter by zoneId and enabled in JavaScript
    • cart/shipping-method route: Same fetch+filter pattern
    • Updated type signatures to make where optional in query options
  2. packages/core/src/routes/admin-api.ts

    • deleteShippingZone handler: Fetch all methods, check zoneId match in JavaScript instead of using .where

Cross-Database Compatibility

The enabled field is checked as both boolean (true) and numeric (1) because:

  • TypeScript types define it as boolean
  • Postgres JSONB storage may deserialize it as either value depending on how it was originally stored
  • This ensures compatibility across SQLite, Postgres, and any intermediate serialization layers

Verification

All tests pass: 85 pass, 0 fail
Typecheck clean: No TypeScript errors
Build succeeds: Package compiles without issues

Testing Steps

To verify the fix on Railway/Neon:

  1. Deploy this branch to the Railway demo environment
  2. Add products to cart with shipping
  3. Call POST /cart/shipping-methods with a valid shipping address
  4. Verify the response returns available shipping options without SQL errors
  5. Call POST /cart/shipping-method with a methodId to select a method
  6. Verify the cart updates with the chosen shipping method

Notes

  • This is not a fix to EmDash itself — the upstream .where clause building remains broken on Postgres
  • For DashCommerce, we work around it by avoiding .where clauses entirely in shipping-related queries
  • Other parts of the codebase may still use .where clauses; they should be audited if Postgres support is required
  • Future: Consider contributing an upstream fix to EmDash's query builder

Related

  • Live hot-patch that validated this approach is already running in production
  • No behavior changes for SQLite deployments (existing tests continue to pass)
Open in Web Open in Cursor 

…patibility

EmDash's .query({ where: ... }) builds SQLite-style SQL that fails on
Postgres with 'syntax error at or near "="'. This affects live Railway
demo on Neon (Postgres).

Changes:
- cart/shipping-methods: Fetch all methods, filter by zoneId + enabled in JS
- cart/shipping-method: Same fetch+filter pattern
- admin-api deleteShippingZone: Fetch all methods, check zoneId match in JS

All queries now fetch with limit and filter in JavaScript, working across
both SQLite and Postgres. Handles enabled field as both boolean (true) and
numeric (1) for cross-database compatibility.

Verified:
- All tests pass (85 pass, 0 fail)
- Typecheck clean
- Build succeeds

Co-authored-by: Timchosen Uzua <timchosen@gmail.com>

@cavewebs cavewebs left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eng review — APPROVE

Matches the validated live hot-patch: drop EmDash storage where on shipping_methods (Postgres syntax error near =), fetch+JS filter on zoneId + enabled (true or 1). Also correctly fixes deleteShippingZone the same way.

CI still running on this SHA. Non-blocking: no new unit test for the filter path (live QA already PASS $5 / Stripe). Indent in cart.ts looks a bit shifted in the diff — worth a format pass if prettier complains.

Ready to merge after CI green + your call (Railway still needs upgrade past hot-patch/0.1.3 for durable deploy).

@cavewebs
cavewebs marked this pull request as ready for review September 15, 2026 13:41
@cavewebs
cavewebs merged commit 411b3cb into main Sep 15, 2026
2 checks passed
@cavewebs
cavewebs deleted the cursor/fix-postgres-shipping-queries-a2ec branch September 15, 2026 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants