Skip to content
Written with Claude
IMPORTANT

As you may notice, this page and pretty much the entire website were obviously created with the help of AI. I wonder how you could tell? Was it a big "Written With Claude" badge on every page? I moved it to the top now (with the help of AI of course) to make it even more obvious. There are a few blogposts that were written by me manually, the old-fashioned way, I hope there will be more in the future, and those have a similar "Human Written" badge. This project (not the website), on the other hand, is a very, very different story. It took me more than two years of painstaking and unpaid work in my own free time. A story that, hopefully, I will tell someday. But meanwhile, what would you like me to do? To create a complex documentation website with a bunch of highly technical articles with the help of AI and fake it, to give you an illusion that I also did that manually? Like the half of itnernet is doing at this point? How does that makes any sense? Is that even fair to you? Or maybe to create this website manually, the old-fashioned way, just for you? While working a paid job for a salary, most of you wouldn't even get up in the morning. Would you like me to sing you a song while we're at it? For your personal entertainment? Seriously, get a grip. Do you find this information less valuable because of the way this website was created? I give my best to fix it to keep the information as accurate as possible, and I think it is very accurate at this point. If you find some mistakes, inaccurancies or problems, there is a comment section at the bottom of every page, which I also made with the help of the AI. And I woould very much appreciate if you leave your feedback there. Look, I'm just a guy who likes SQL, that's all. If you don't approve of how this website was constructed and the use of AI tools, I suggest closing this page and never wever coming back. And good riddance. And I would ban your access if I could know how. Thank you for your attention to this matter.

CRUD Source

Configuration for automatic CRUD endpoint generation from PostgreSQL tables and views.

Overview

json
{
  "NpgsqlRest": {
    "CrudSource": {
      "Enabled": true,
      "SchemaSimilarTo": null,
      "SchemaNotSimilarTo": null,
      "IncludeSchemas": null,
      "ExcludeSchemas": null,
      "NameSimilarTo": null,
      "NameNotSimilarTo": null,
      "IncludeNames": null,
      "ExcludeNames": null,
      "CommentsMode": "OnlyWithHttpTag",
      "ReturningUrlPattern": "{0}/returning",
      "OnConflictDoNothingUrlPattern": "{0}/on-conflict-do-nothing",
      "OnConflictDoNothingReturningUrlPattern": "{0}/on-conflict-do-nothing/returning",
      "OnConflictDoUpdateUrlPattern": "{0}/on-conflict-do-update",
      "OnConflictDoUpdateReturningUrlPattern": "{0}/on-conflict-do-update/returning",
      "CrudTypes": ["All"]
    }
  }
}

General Settings

SettingTypeDefaultDescription
EnabledbooltrueEnable CRUD endpoint generation for tables and views.
CommentsModestring"OnlyWithHttpTag"How comment annotations affect endpoint creation.

Comments Mode

ModeDescription
IgnoreCreate all endpoints, ignore comment annotations.
ParseAllCreate all endpoints, parse comment annotations to modify them.
OnlyWithHttpTagOnly create endpoints for tables/views with HTTP tag in comments (default).

When using ParseAll, you can use the DISABLED, ENABLED, and TAGS annotations to control which CRUD operations are exposed for each table.

Schema and Name Filtering

Filter which tables and views are exposed as CRUD endpoints.

SettingTypeDefaultDescription
SchemaSimilarTostringnullInclude schemas matching this SQL SIMILAR TO pattern.
SchemaNotSimilarTostringnullExclude schemas matching this SQL SIMILAR TO pattern.
IncludeSchemasarraynullList of schema names to include.
ExcludeSchemasarraynullList of schema names to exclude.
NameSimilarTostringnullInclude table/view names matching this SQL SIMILAR TO pattern.
NameNotSimilarTostringnullExclude table/view names matching this SQL SIMILAR TO pattern.
IncludeNamesarraynullList of table/view names to include.
ExcludeNamesarraynullList of table/view names to exclude.

Filtering Examples

Include only specific schemas:

json
{
  "NpgsqlRest": {
    "CrudSource": {
      "IncludeSchemas": ["api", "public"]
    }
  }
}

Exclude system tables:

json
{
  "NpgsqlRest": {
    "CrudSource": {
      "ExcludeSchemas": ["pg_catalog", "information_schema"],
      "NameNotSimilarTo": "%_audit"
    }
  }
}

URL Patterns

Configure URL patterns for different CRUD operation variants. Use {0} as placeholder for the default URL.

SettingTypeDefaultDescription
ReturningUrlPatternstring"{0}/returning"URL pattern for INSERT/UPDATE/DELETE with RETURNING clause.
OnConflictDoNothingUrlPatternstring"{0}/on-conflict-do-nothing"URL pattern for INSERT ON CONFLICT DO NOTHING.
OnConflictDoNothingReturningUrlPatternstring"{0}/on-conflict-do-nothing/returning"URL pattern for INSERT ON CONFLICT DO NOTHING with RETURNING.
OnConflictDoUpdateUrlPatternstring"{0}/on-conflict-do-update"URL pattern for INSERT ON CONFLICT DO UPDATE (upsert).
OnConflictDoUpdateReturningUrlPatternstring"{0}/on-conflict-do-update/returning"URL pattern for INSERT ON CONFLICT DO UPDATE with RETURNING.

Custom URL Patterns

json
{
  "NpgsqlRest": {
    "CrudSource": {
      "ReturningUrlPattern": "{0}-returning",
      "OnConflictDoUpdateUrlPattern": "{0}-upsert"
    }
  }
}

CRUD Types

Enable or disable specific CRUD operations using the CrudTypes array.

TypeHTTP MethodDescription
SelectGETRead records from tables/views.
InsertPOSTCreate new records.
InsertReturningPOSTCreate records and return inserted data.
InsertOnConflictDoNothingPOSTInsert or ignore on conflict.
InsertOnConflictDoNothingReturningPOSTInsert or ignore with returning.
InsertOnConflictDoUpdatePOSTUpsert (insert or update on conflict).
InsertOnConflictDoUpdateReturningPOSTUpsert with returning.
UpdatePUTUpdate existing records.
UpdateReturningPUTUpdate and return modified data.
DeleteDELETERemove records.
DeleteReturningDELETERemove and return deleted data.
All-Enable all CRUD types.

Examples

Enable all operations:

json
{
  "NpgsqlRest": {
    "CrudSource": {
      "CrudTypes": ["All"]
    }
  }
}

Read-only access:

json
{
  "NpgsqlRest": {
    "CrudSource": {
      "CrudTypes": ["Select"]
    }
  }
}

Basic CRUD without conflict handling:

json
{
  "NpgsqlRest": {
    "CrudSource": {
      "CrudTypes": [
        "Select",
        "Insert",
        "InsertReturning",
        "Update",
        "UpdateReturning",
        "Delete",
        "DeleteReturning"
      ]
    }
  }
}

Complete Example

Production configuration with filtering and specific CRUD types:

json
{
  "NpgsqlRest": {
    "CrudSource": {
      "Enabled": true,
      "IncludeSchemas": ["api"],
      "ExcludeNames": ["audit_log", "system_config"],
      "CommentsMode": "OnlyWithHttpTag",
      "ReturningUrlPattern": "{0}/returning",
      "OnConflictDoUpdateUrlPattern": "{0}/upsert",
      "OnConflictDoUpdateReturningUrlPattern": "{0}/upsert/returning",
      "CrudTypes": [
        "Select",
        "Insert",
        "InsertReturning",
        "InsertOnConflictDoUpdate",
        "InsertOnConflictDoUpdateReturning",
        "Update",
        "UpdateReturning",
        "Delete"
      ]
    }
  }
}

Minimal read-only configuration:

json
{
  "NpgsqlRest": {
    "CrudSource": {
      "Enabled": true,
      "CommentsMode": "ParseAll",
      "CrudTypes": ["Select"]
    }
  }
}

Controlling CRUD Operations with Annotations

When using "CommentsMode": "ParseAll", table comments can control which CRUD operations are exposed.

Example: Read-Only Table

sql
comment on table audit_log is '
@disabled insert, update, delete
';

Example: Selective Operations

sql
comment on table users is '
@disabled
@enabled select, delete
';

Only SELECT and DELETE are enabled; INSERT and UPDATE return 405.

Example: Different Settings per Operation

sql
comment on table products is '
for select
@allow_anonymous
for update
@authorize admin
for returning
@disabled
';

See the annotation documentation for complete details on controlling CRUD operations.

Next Steps

Comments

Released under the MIT License.