Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion docs/configuration-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,38 @@ The `source` property tells Data API builder what is the underlying database obj
}
```

> **IMPORTANT**: A table or a view defined as the source must have a primary key to be usable by Data API Builder
> **NOTE**:
- A table or a view defined as the source must have a primary key to be usable by Data API Builder.
- Source can either be string or DatabaseSourceObject (with properties such as source-type, parameters, and key-fields).
- parameters is an optional property only for Stored-Procedure.
- key-fields is an optional property only for Table/view.
- By Default if `type` is not specified, it is inferred as Table.

- Examples:
1. **View**
```json
{
"object": "bookView",
"type": "view",
"key-fields":["id", "regNo"]
}
```

2. **Table with KeyFields**
```json
{
"object": "bookTable",
"type": "table",
"key-fields":["id", "regNo"]
}
```

3. **Table without KeyFields**
```json
{
"source": "bookTable"
}
```
### Relationships

The `relationships` section defines how an entity is related to other exposed entities and optionally provide details on what underlying database objects can be used to support such relationships. Objects defined in the `relationship` section will be exposed as GraphQL field in the related entity. The format is the following:
Expand Down
9 changes: 8 additions & 1 deletion docs/getting-started/getting-started-dab-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,21 @@ To add the entities to the config file with the GraphQL type and permissions def
dab add <entity> --source <source_db> --graphql <graphql_type> --permissions <roles:actions>
```

If `source.type` is not provided, it is inferred to be Table. Accepted values are: `table`,`view`, and `stored-procedure`.
Comment thread
abhishekkumams marked this conversation as resolved.
```dotnetcli
# dab add book --source dbo.books_composite_view --source.type view --source.key-fields "id,regNo" --graphql book --permissions "anonymous:*"

dab add <entity> --source <source_db> --source.type <source_type> --source.key-fields <key_columns> --graphql <graphql_type> --permissions <roles:actions>
```

### Update entities in config

To update entities which are already added to the config, run the following update command:

```dotnetcli
# dab update book --permissions "authenticate:create,update" --fields.include "id,title"

dab update <entity> --source <new_source_db> --graphql <new_graphql_type> --permissions <rules:actions> --fields.include <fields_to_include> --fields.exclude <fields_to_exclude>
dab update <entity> --source <new_source_db> --source.type <new_source_type> --source.key-fields <new_key_columns> --graphql <new_graphql_type> --permissions <rules:actions> --fields.include <fields_to_include> --fields.exclude <fields_to_exclude>
```

### Add entity relationship mappings
Expand Down
126 changes: 126 additions & 0 deletions docs/internals/UsingCliForAddingStored-proceduresAndViews.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Adding Views/Stored-Procedure to Runtime Config JSON

## New Options
- CLI supports some new command line options (for `add` and `update` command):
- `--source.type` -> To Specify the type of source (tables, views, and stored-procedure),
- `--source.params` -> To Specify parameters for Stored Procedure,
- `--source.key-fields` -> To Specify key-fields for Table/Views.

## Usage
### When `source.type` is not provided
`dab add MyEntity --source "dbo.my_entity" --permissions "anonymous:*"`
NOTE: By Default sourceType is inferred to be table.
> preview:
```json
"MyEntity": {
"source": "dbo.my_entity",
"permissions": [
{
"role": "anonymous",
"actions": [ "create", "read", "update" ]
}
]
}
```

### When `source.type` is stored-procedure
`dab add MyEntity --source "s001.book" --source.type "stored-procedure" --source.params "param1:123,param2:hello,param3:true" --permissions "anonymous:*"`
**NOTE**: source-params are optional if the procedure doesn't take any params.
> preview:
```json
"MyEntity": {
"source": {
"type": "stored-procedure",
"object": "s001.book",
"parameters": {
"param1": 123,
"param2": "hello",
"param3": true
}
},
"permissions": [
{
"role": "anonymous",
"actions": [ "read" ]
}
]
}
```

### When `source.type` is view
`dab add MyEntity --source "s001.book" --source.type "view" --source.key-fields "col1,col2" --permissions "anonymous:*"`
Comment thread
abhishekkumams marked this conversation as resolved.

**NOTE**: key-fields are optional if the view is simple and keys are inferable
> preview:
```json
"MyEntity": {
"source": {
"type": "view",
"object": "s001.book",
"key-fields": [ "col1", "col2" ]
},
"permissions": [
{
"role": "anonymous",
"actions": [ "read" ]
}
]
}
```

## Some unique Cases:
### Conversion from one DatabaseObjectSource to another.
If the source object looks like this:
```json
{
"object": "bookSp",
"type": "stored-procedure",
"parameters": {
"param1": "hello",
"param2": 123
}
}
```

and suppose we want to make it a table, then we need to run this command:
`dab update Book --bookTable --source.type table --source.key-fields "col1,col2"`

Result:
```json
{
"object": "bookTable",
"type": "table",
"key-fields":["col1", "col2"]
}
```
We can convert it back to the original one by the below command:
`dab update Book --source bookSp --source.type stored-procedure --source.parameters "param1:hello,param2:123"`

**NOTE:**
The CLI recognizes redundant fields, i.e., Parameters for table/view, and keyFields for Stored Procedures.
When a user converts a table to a stored procedure, the CLI automatically sets the keyFields property to `null`. Similarly, the CLI sets the Parameters property to `null` when converting from a stored procedure to a table or view.
When a user explicitly sets the Parameters option while converting from stored-procedure to table/view, the CLI will return an error. The CLI will similarly return an error when a user sets the keyFields option when converting from a table/view to a stored procedure.

### Conversion from object to String.
suppose we want to change the initial storedProcedure object to just a string object.
`dab update Book --source bookTable --source.type table`

Result:
Comment thread
abhishekkumams marked this conversation as resolved.
```json
{
"source": "bookTable"
}
```
**NOTE:**
If the user changes from stored-procedure to table without adding keyfields then it automatically converts the value of `source` to string object from `DatabaseObjectSource` to represent the default source type of table.

When we run the following command to update the above stored-procedure:
`dab update Book --source bookView --source.type view`

Result:
```json
{
"object": "bookView",
"type": "view"
}
```