Skip to content

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).

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"]
    }
  }
}

Next Steps

Released under the MIT License.