repositories

Implement raw SQL reads with Prisma writes for Node.js PostgreSQL services.

Updated Apr 16, 2025
One-click install
npx skills add https://github.com/teexiii/boilerplate-rest-bun-for-noob --skill repositories-teexiii
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: repositories
Source: https://github.com/teexiii/boilerplate-rest-bun-for-noob/tree/main/.agent/skills/repositories
Command: npx skills add https://github.com/teexiii/boilerplate-rest-bun-for-noob --skill repositories-teexiii

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Provides a consistent, high-performance repository layer that separates read and write patterns so backend services can run complex, optimized read queries while keeping mutations type-safe and rate-limited.

Core Features & Use Cases

  • Raw SQL for Reads: Use parameterized raw SQL queries for all find* methods to maximize performance and control, with column aliasing to convert snake_case to camelCase and nested relation mapping.
  • Prisma for Mutations: Perform create, update, and delete operations with Prisma's type-safe API while using a write queue to throttle concurrent writes.
  • Cache-aside and Invalidation: Integrate cache lookups for reads, populate caches after DB fallbacks, and invalidate relevant caches after mutations to maintain consistency.
  • Relation Loading Patterns: Load one-to-one and one-to-many relations with JOINs or separate queries and merge results using flat-to-nested mapping helpers.
  • Use Case: Implement a user repository that returns nested role and social relations via optimized read queries and performs secure, queued updates that clear caches on change.

Quick Start

Use this guide to implement a repository that performs raw SQL reads with camelCase aliasing and nested relation mapping while using Prisma and queueWrite for safe, rate-limited mutations.

Frequently Asked Questions about repositories

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I combine raw SQL reads with Prisma writes in a Node.js backend?

To combine raw SQL reads with Prisma writes, implement a repository layer that executes parameterized raw SQL for find operations while delegating create, update, and delete mutations to Prisma's type-safe API.

What is the best way to map snake_case database columns to camelCase in raw SQL queries?

Mapping snake_case database columns to camelCase in raw SQL queries is achieved by applying column aliasing within parameterized SQL statements, automatically converting flat query results into camelCase properties before returning them.

How do I load nested relations with raw SQL without the N+1 query problem?

Loading nested relations with raw SQL without the N+1 query problem involves using JOINs for one-to-one relations or separate queries for one-to-many relations, then merging flat results into nested structures using mapping helpers.

Does Prisma support a cache-aside pattern with automatic invalidation after mutations?

A cache-aside pattern with Prisma is supported by integrating cache lookups during reads, populating caches after database fallbacks, and invalidating relevant caches automatically after Prisma mutations to maintain data consistency.

How do I throttle concurrent database writes in a Node.js service using Prisma?

Throttling concurrent database writes in a Node.js service using Prisma is done by routing create, update, and delete operations through a queueWrite mechanism, which rate-limits mutations to prevent overwhelming the PostgreSQL database.

When should I separate read and write patterns in a PostgreSQL backend?

Separating read and write patterns in a PostgreSQL backend is necessary when complex read queries require optimized raw SQL for maximum performance, while mutations need type-safe operations with rate-limiting and cache invalidation.