Skip to content

feat(data-access): expose postgrestClient for direct PostgREST queries#1396

Merged
ekremney merged 1 commit intomainfrom
feat/expose-postgrest-client
Mar 2, 2026
Merged

feat(data-access): expose postgrestClient for direct PostgREST queries#1396
ekremney merged 1 commit intomainfrom
feat/expose-postgrest-client

Conversation

@ekremney
Copy link
Member

@ekremney ekremney commented Mar 2, 2026

Summary

  • Exposes the underlying PostgrestClient instance under a services namespace on the object returned by createDataAccess(), enabling direct PostgREST queries against tables that are not modeled as entities (e.g. analytics views, brand presence tables)
  • Adds full TypeScript typings for all 32 entity collections on the DataAccess interface (previously typed as object)
  • Re-exports 5 previously missing collection types from models/index.d.ts (ApiKey, AuditUrl, PageCitability, PageIntent, Project)

Motivation

Some API endpoints need to query PostgREST tables that don't have corresponding entity models in the data-access layer (e.g. brand_presence_executions, brand_metrics_weekly). Previously, developers resorted to reaching into collection internals like Site.postgrestService to get the raw client. This change makes it a first-class, typed API under a services namespace that cleanly separates infrastructure from entity collections.

Usage

// Entity collections stay top-level
const { Site, Organization } = context.dataAccess;
const site = await Site.findById(siteId);

// Infrastructure services live under the services namespace
const { postgrestClient } = context.dataAccess.services;

// Direct queries against non-entity tables
const { data, error } = await postgrestClient
  .from('brand_presence_executions')
  .select('execution_date, visibility_score, sentiment')
  .eq('site_id', siteId)
  .gte('execution_date', '2025-01-01')
  .order('execution_date', { ascending: false })
  .limit(100);

Full IDE autocomplete is available for the entire PostgREST query builder chain (.from(), .select(), .eq(), .gte(), .order(), .range(), .rpc(), etc.).

Test plan

  • Existing unit tests updated to verify services.postgrestClient is present and is the correct instance
  • All 1522 unit tests passing
  • Lint passing

🤖 Generated with Claude Code

@ekremney ekremney requested review from solaris007 and vivesing March 2, 2026 14:02
…r direct PostgREST queries

Adds the underlying PostgrestClient instance under a `services` namespace on the object
returned by createDataAccess(), enabling controllers to perform direct PostgREST queries
against tables that are not modeled as entities (e.g. analytics views, brand presence tables).

Also adds full TypeScript typings for all 32 entity collections on the DataAccess interface
and re-exports 5 previously missing collection types from models/index.d.ts.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ekremney ekremney force-pushed the feat/expose-postgrest-client branch from 21672e2 to b8c1747 Compare March 2, 2026 14:28
@github-actions
Copy link

github-actions bot commented Mar 2, 2026

This PR will trigger a minor release when merged.

@ekremney ekremney merged commit 307711c into main Mar 2, 2026
7 checks passed
@ekremney ekremney deleted the feat/expose-postgrest-client branch March 2, 2026 14:36
solaris007 pushed a commit that referenced this pull request Mar 2, 2026
## [@adobe/spacecat-shared-data-access-v3.6.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-data-access-v3.5.0...@adobe/spacecat-shared-data-access-v3.6.0) (2026-03-02)

### Features

* **data-access:** expose postgrestClient for direct PostgREST queries ([#1396](#1396)) ([307711c](307711c))
@solaris007
Copy link
Member

🎉 This PR is included in version @adobe/spacecat-shared-data-access-v3.6.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

ekremney added a commit that referenced this pull request Mar 2, 2026
## Summary
- Documents the `services.postgrestClient` API added in #1396 in both
README.md and CLAUDE.md
- Updates the "What You Get" and "TypeScript" sections in README.md
- Adds "Direct PostgREST Queries" section with usage examples to both
docs
- Adds `src/service/index.d.ts` to the Key Files table in CLAUDE.md

Follow-up to #1396 which was merged before docs were updated.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants