Freigeben über


add-Befehl

Fügen Sie einer vorhandenen Konfigurationsdatei des Daten-API-Generators eine neue Entitätsdefinition hinzu. Sie müssen bereits über eine Konfiguration verfügen, die mit dab init. Dient dab update zum Ändern von Entitäten nach der Erstellung.

Tipp

Wird dab add verwendet, um neue Entitäten zu erstellen und dab update zu entwickeln. Feldname-Neuzuordnung (--map) ist nur in update, nicht in add.

Syntax

dab add <entity-name> [options]

Schnellblick

Option Zusammenfassung
<entity-name> Erforderliches Positionsargument. Logischer Entitätsname.
-c, --config Konfigurationsdateipfad. Standard-dab-config.json.
--cache.enabled Aktivieren/Deaktivieren der Zwischenspeicherung für entität.
--cache.ttl Zwischenspeichern von Zeit-zu-Live-Zeit in Sekunden.
--description Beschreibung der Freiform für die Entität.
--fields.exclude Durch Trennzeichen getrennte ausgeschlossene Felder.
--fields.include Durch Trennzeichen getrennte zulässige Felder (* = alle).
--graphql GraphQL-Belichtung: false, , true, singularoder singular:plural.
--graphql.operation Nur gespeicherte Prozeduren. query oder mutation (Standardmutation).
--permissions Erforderlich. role:actions Mindestens ein Paar. Wiederholbar.
--policy-database OData-Formatfilter, der in der DB-Abfrage angewendet wird.
--policy-request Die Anforderungsrichtlinie wurde vor dem DB-Aufruf ausgewertet.
--rest REST-Belichtung: false, trueoder benutzerdefinierte Route.
--rest.methods Nur gespeicherte Prozeduren. Zulässige HTTP-Verben. Standard-POST.
-s, --source Erforderlich. Name des Datenbankobjekts (Tabelle, Ansicht oder gespeicherte Prozedur).
--source.key-fields Erforderlich für Ansichten oder wenn PK nicht abgeleitet wurde. Für Procs nicht zulässig.
--source.params Nur gespeicherte Prozeduren. Standardwerte.
--source.type Quelltyp: table, , stored-procedureview(Standardtabelle).

<entity-name>

Logischer Name der Entität in der Konfiguration. Groß-/Kleinschreibung wird beachtet.

Example

dab add Book --source dbo.Books --permissions "anonymous:read"

Resultierende Konfiguration

{
  "entities": {
    "Book": {
      "source": {
        "type": "table",
        "object": "dbo.Books"
      },
      "permissions": [
        {
          "role": "anonymous",
          "actions": [ "read" ]
        }
      ]
    }
  }
}

-c, --config

Konfigurationsdateipfad. Der Standardwert ist dab-config.json.

Example

dab add Book --config ./dab-config.mssql.json --source dbo.Books --permissions "anonymous:read"

--cache.enabled

Aktivieren oder Deaktivieren der Zwischenspeicherung.

Example

dab add Book --source dbo.Books --permissions "anonymous:read" --cache.enabled true

Resultierende Konfiguration

{
  "entities": {
    "Book": {
      "source": {
        "type": "table",
        "object": "dbo.Books"
      },
      "permissions": [
        { "role": "anonymous", "actions": [ "read" ] }
      ],
      "cache": {
        "enabled": true
      }
    }
  }
}

--cache.ttl

Zwischenspeichern von Zeit-zu-Live-Zeit in Sekunden.

Example

dab add Book --source dbo.Books --permissions "anonymous:read" --cache.ttl 300

Resultierende Konfiguration

{
  "entities": {
    "Book": {
      "source": {
        "type": "table",
        "object": "dbo.Books"
      },
      "permissions": [
        { "role": "anonymous", "actions": [ "read" ] }
      ],
      "cache": {
        "ttl-seconds": 300
      }
    }
  }
}

--description

Freitextbeschreibung der Entität.

Example

dab add Book --source dbo.Books --permissions "anonymous:read" --description "Entity for managing book inventory"

Resultierende Konfiguration

{
  "entities": {
    "Book": {
      "source": {
        "type": "table",
        "object": "dbo.Books"
      },
      "permissions": [
        { "role": "anonymous", "actions": [ "read" ] }
      ],
      "description": "Entity for managing book inventory"
    }
  }
}

--fields.exclude

Durch Trennzeichen getrennte Liste der auszuschließenden Felder.

Example

dab add Book --source dbo.Books --permissions "anonymous:read" --fields.exclude "internal_flag,secret_note"

Resultierende Konfiguration

{
  "entities": {
    "Book": {
      "source": { "type": "table", "object": "dbo.Books" },
      "permissions": [
        { "role": "anonymous", "actions": [ "read" ] }
      ],
      "graphql": {
        "fields": {
          "exclude": [ "internal_flag", "secret_note" ]
        }
      }
    }
  }
}

--fields.include

Durch Trennzeichen getrennte Liste von Feldern, die verfügbar gemacht werden sollen.

Example

dab add Book --source dbo.Books --permissions "anonymous:read" --fields.include "id,title,price"

Resultierende Konfiguration

{
  "entities": {
    "Book": {
      "source": { "type": "table", "object": "dbo.Books" },
      "permissions": [
        { "role": "anonymous", "actions": [ "read" ] }
      ],
      "graphql": {
        "fields": {
          "include": [ "id", "title", "price" ]
        }
      }
    }
  }
}

--graphql

Steuern der GraphQL-Belichtung.

Example

dab add Book --source dbo.Books --permissions "anonymous:read" --graphql book:books

Resultierende Konfiguration

{
  "entities": {
    "Book": {
      "source": { "type": "table", "object": "dbo.Books" },
      "permissions": [
        { "role": "anonymous", "actions": [ "read" ] }
      ],
      "graphql": {
        "singular": "book",
        "plural": "books"
      }
    }
  }
}

--graphql.operation

Nur gespeicherte Prozeduren. GraphQL-Vorgangstyp. Der Standardwert ist mutation.

Example

dab add BookProc --source dbo.MyProc --source.type stored-procedure --permissions "admin:execute" --graphql.operation query

Resultierende Konfiguration

{
  "entities": {
    "BookProc": {
      "source": { "type": "stored-procedure", "object": "dbo.MyProc" },
      "permissions": [
        { "role": "admin", "actions": [ "execute" ] }
      ],
      "graphql": {
        "operation": "query"
      }
    }
  }
}

--permissions

Definiert Rollenpaare→aktionen. Verwenden Sie wiederholte Flags für mehrere Rollen.

Example

dab add Book --source dbo.Books --permissions "anonymous:read" --permissions "authenticated:create,read,update,delete"

Resultierende Konfiguration

{
  "entities": {
    "Book": {
      "source": { "type": "table", "object": "dbo.Books" },
      "permissions": [
        { "role": "anonymous", "actions": [ "read" ] },
        { "role": "authenticated", "actions": [ "create", "read", "update", "delete" ] }
      ]
    }
  }
}

--policy-database

Richtlinie auf Datenbankebene.

Example

dab add Book --source dbo.Books --permissions "anonymous:read" --policy-database "region eq 'US'"

Resultierende Konfiguration

{
  "entities": {
    "Book": {
      "source": { "type": "table", "object": "dbo.Books" },
      "permissions": [
        { "role": "anonymous", "actions": [ "read" ] }
      ],
      "policies": {
        "database": "region eq 'US'"
      }
    }
  }
}

--policy-request

Richtlinie auf Anforderungsebene.

Example

dab add Book --source dbo.Books --permissions "anonymous:read" --policy-request "@claims.role == 'admin'"

Resultierende Konfiguration

{
  "entities": {
    "Book": {
      "source": { "type": "table", "object": "dbo.Books" },
      "permissions": [
        { "role": "anonymous", "actions": [ "read" ] }
      ],
      "policies": {
        "request": "@claims.role == 'admin'"
      }
    }
  }
}

--rest

Steuern der REST-Belichtung.

Example

dab add Book --source dbo.Books --permissions "anonymous:read" --rest BooksApi

Resultierende Konfiguration

{
  "entities": {
    "Book": {
      "source": { "type": "table", "object": "dbo.Books" },
      "permissions": [
        { "role": "anonymous", "actions": [ "read" ] }
      ],
      "rest": {
        "path": "BooksApi"
      }
    }
  }
}

--rest.methods

Nur gespeicherte Prozeduren. HTTP-Verben, die für die Ausführung zulässig sind. Standardmäßig wird POST verwendet. Wird für Tabellen/Ansichten ignoriert.

Example

dab add BookProc --source dbo.MyProc --source.type stored-procedure --permissions "admin:execute" --rest true --rest.methods GET,POST

Resultierende Konfiguration

{
  "entities": {
    "BookProc": {
      "source": { "type": "stored-procedure", "object": "dbo.MyProc" },
      "permissions": [
        { "role": "admin", "actions": [ "execute" ] }
      ],
      "rest": {
        "path": "BookProc",
        "methods": [ "GET", "POST" ]
      }
    }
  }
}

-s, --source

Erforderlich. Name des Datenbankobjekts: Tabelle, Ansicht oder gespeicherte Prozedur.

Example

dab add Book --source dbo.Books --permissions "anonymous:read"

Resultierende Konfiguration

{
  "entities": {
    "Book": {
      "source": {
        "type": "table",
        "object": "dbo.Books"
      },
      "permissions": [
        { "role": "anonymous", "actions": [ "read" ] }
      ]
    }
  }
}

--source.key-fields

Erforderlich für Ansichten. Auch erforderlich für Tabellen ohne eine zu leitende PK. Für gespeicherte Prozeduren nicht zulässig.

Example

dab add BookView --source dbo.MyView --source.type view --source.key-fields "id,region" --permissions "anonymous:read"

Resultierende Konfiguration

{
  "entities": {
    "BookView": {
      "source": {
        "type": "view",
        "object": "dbo.MyView",
        "keyFields": [ "id", "region" ]
      },
      "permissions": [
        { "role": "anonymous", "actions": [ "read" ] }
      ]
    }
  }
}

--source.params

Nur gespeicherte Prozeduren. Durch Trennzeichen getrennte name:value Paare. Für Tabellen oder Ansichten nicht zulässig.

Example

dab add BookProc --source dbo.MyProc --source.type stored-procedure --source.params "year:2024,active:true" --permissions "admin:execute"

Resultierende Konfiguration

{
  "entities": {
    "BookProc": {
      "source": {
        "type": "stored-procedure",
        "object": "dbo.MyProc",
        "params": {
          "year": 2024,
          "active": true
        }
      },
      "permissions": [
        { "role": "admin", "actions": [ "execute" ] }
      ]
    }
  }
}

--source.type

Typ des Datenbankobjekts. Standardwert: table.

Example

dab add Book --source dbo.Books --source.type table --permissions "anonymous:read"

Resultierende Konfiguration

{
  "entities": {
    "Book": {
      "source": {
        "type": "table",
        "object": "dbo.Books"
      },
      "permissions": [
        { "role": "anonymous", "actions": [ "read" ] }
      ]
    }
  }
}