---
title: "Higher-level CRUD Abstraction for Postgres RLS"
description: "Postgres Row-Level Security requires separate USING and WITH CHECK policies per operation, which gets repetitive for CRUD apps."
url: "https://swe.quest/articles/higher-level-crud-abstraction-for-postgres-rls-90207e4bb081ead2"
canonical: "https://neon.com/blog/higher-level-crud-abstraction-for-postgres-rls"
source: "Neon"
published: "2024-11-13"
difficulty: "medium"
kind: "Announcement"
reading_minutes: 3
tags: ["postgres","identity-auth","typescript"]
---

# Higher-level CRUD Abstraction for Postgres RLS

A post on [Neon](https://swe.quest/sources/neon.md), published 2024-11-13, 3 min read, Announcement. Original: [https://neon.com/blog/higher-level-crud-abstraction-for-postgres-rls](https://neon.com/blog/higher-level-crud-abstraction-for-postgres-rls)

## Summary

Postgres Row-Level Security requires separate USING and WITH CHECK policies per operation, which gets repetitive for CRUD apps. Neon's Drizzle ORM helper \`crudPolicy\` takes a role plus \`read\` and \`modify\` expressions (true, false, a SQL expression, or null to skip) and generates the select, insert, update and delete policies. A companion \`authUid\` helper ties pg\_session\_jwt's \`auth.user\_id()\` to a table column. The post shows the raw SQL for a todos table next to the equivalent concise Drizzle schema. The functionality has since moved into the Neon Data API.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [Identity & auth](https://swe.quest/tags/identity-auth.md) (Security)
- [TypeScript](https://swe.quest/tags/typescript.md) (Languages)

## Prerequisites

- Postgres row-level security ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- Drizzle ORM schema definitions

## Keywords

Postgres RLS, Drizzle ORM, crudPolicy, pg\_session\_jwt, Neon Authorize, Neon Data API

## Related posts

- [Modelling Authorization for a Social Network with Postgres RLS and Drizzle ORM](https://swe.quest/articles/modelling-authorization-for-a-social-network-with-postgres-rls-and-drizzle-orm-6267eb437b8171e7.md): Neon · 2024-11-11 · Medium · 8 min read · PostgreSQL, Identity & auth, TypeScript, System design
  Postgres Row-Level Security can express the full authorization model for a Twitter-like social network, defined with Drizzle ORM's crudPolicy and pgPolicy helpers and the pg\_session\_jwt extension's auth.user\_id().
- [Introducing Neon RLS: Simplifying Row-Level Security For Postgres](https://swe.quest/articles/introducing-neon-rls-simplifying-row-level-security-for-postgres-4b66d76670bb402f.md): Neon · 2024-10-30 · Medium · 6 min read · PostgreSQL, Identity & auth, Multi-tenancy, TypeScript
  Neon RLS lets Postgres row-level security policies authenticate requests with JWTs from any auth provider that exposes a JWKS URL.
- [How to Set Up Row-Level Security in Postgres Using AWS Cognito](https://swe.quest/articles/how-to-set-up-row-level-security-in-postgres-using-aws-cognito-7cb6bed6c9694d22.md): Neon · 2024-12-04 · Medium · 5 min read · PostgreSQL, Identity & auth, JavaScript, Serverless
  Postgres row-level security can be driven by AWS Cognito JWTs: a Cognito User Pool issues tokens, and Neon Authorize validates them and maps claims like \`sub\` into Postgres session variables.
- [Is Postgres RLS for Everything and Everyone?](https://swe.quest/articles/is-postgres-rls-for-everything-and-everyone-1df08667813a2c82.md): Neon · 2024-11-15 · Medium · 4 min read · PostgreSQL, Identity & auth, Multi-tenancy, Security
  Postgres row-level security is a poor fit for expressing an entire app's authorization model.
- [Partial data dumps using Postgres Row Level Security](https://swe.quest/articles/partial-data-dumps-using-postgres-row-level-security-7b8cbab5206adee8.md): Supabase · 2022-06-28 · Medium · 4 min read · PostgreSQL, Privacy, Identity & auth, Testing
  Postgres Row Level Security can produce a seed.sql containing only safe, non-customer rows: create a restricted \`exporter\` role, attach RLS select policies that filter which rows it can see, then run \`pg\_dump --data-only --enable-row-security\` as that role.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
