mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-10-26 10:20:54 +03:00
docs: Add CLI instructions for Logical Models and friends.
Resolves [NDAT-732](https://hasurahq.atlassian.net/browse/NDAT-732). We were missing CLI instructions for Logical Models, Native Queries, and Stored Procedures. Now we are not. Removes the "beta" label for Native Queries too. [NDAT-732]: https://hasurahq.atlassian.net/browse/NDAT-732?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ PR-URL: https://github.com/hasura/graphql-engine-mono/pull/9627 GitOrigin-RevId: c132c1b4a8de5626da6b403d263a946b648c0259
This commit is contained in:
parent
8a5dffb585
commit
bf0afdfc0c
@ -36,21 +36,35 @@ Logical Models themselves, read on.
|
||||
|
||||
## Tracking a Logical Model
|
||||
|
||||
:::info Only creatable via the Console and API
|
||||
|
||||
Currently, Logical Models can only be created via the API and the Console. CLI support will be added in a future
|
||||
release.
|
||||
|
||||
:::
|
||||
|
||||
<Tabs groupId="user-preference" className="api-tabs">
|
||||
<TabItem value="console" label="Console">
|
||||
|
||||
<Thumbnail
|
||||
src="/img/native-queries/create-logical-model-excerpt-example.png"
|
||||
alt="Create Logical Model"
|
||||
width="800px"
|
||||
/>
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="cli" label="CLI">
|
||||
|
||||
You can create a logical model by adding it to the appropriate database definition in the `metadata > databases.yaml`
|
||||
file:
|
||||
|
||||
```yaml
|
||||
logical_models:
|
||||
- name: "<name>"
|
||||
fields:
|
||||
"<field name>":
|
||||
type: "<BigQuery field type>"
|
||||
nullable: false | true
|
||||
description: "<optional field description>"
|
||||
...
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="api" label="API">
|
||||
|
||||
You create a logical model through the metadata API:
|
||||
@ -68,7 +82,7 @@ X-Hasura-Role: admin
|
||||
"fields": [
|
||||
{
|
||||
"name": "<field name>",
|
||||
"type": "<BigQuery Logical Model type>",
|
||||
"type": "<BigQuery field type>",
|
||||
"nullable": false | true,
|
||||
"description": "<optional field description>"
|
||||
},
|
||||
@ -89,12 +103,42 @@ For example, we could track a representation of an article as follows:
|
||||
|
||||
<Tabs groupId="user-preference" className="api-tabs">
|
||||
<TabItem value="console" label="Console">
|
||||
|
||||
<Thumbnail
|
||||
src="/img/native-queries/create-logical-model-excerpt-example.png"
|
||||
alt="Create Logical Model"
|
||||
width="800px"
|
||||
/>
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="cli" label="CLI">
|
||||
|
||||
Add the following to the `default` database definition in the `metadata > databases.yaml` file:
|
||||
|
||||
```yaml
|
||||
logical_models:
|
||||
- name: article
|
||||
fields:
|
||||
id:
|
||||
type: integer
|
||||
nullable: false
|
||||
title:
|
||||
type: text
|
||||
nullable: false
|
||||
contents:
|
||||
type: text
|
||||
nullable: false
|
||||
published_date:
|
||||
type: date
|
||||
nullable: true
|
||||
is_published:
|
||||
type: boolean
|
||||
nullable: false
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="api" label="API">
|
||||
|
||||
```http
|
||||
@ -156,12 +200,21 @@ X-Hasura-Role: admin
|
||||
|
||||
<Tabs groupId="user-preference" className="api-tabs">
|
||||
<TabItem value="console" label="Console">
|
||||
|
||||
<Thumbnail
|
||||
src="/img/native-queries/delete-logical-model.png"
|
||||
alt="Delete Logical Model"
|
||||
width="800px"
|
||||
/>
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="cli" label="CLI">
|
||||
|
||||
You can remove a Logical Model by removing it from the `metadata > databases.yaml` file.
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="api" label="API">
|
||||
|
||||
You can remove a Logical Model the same way:
|
||||
@ -193,15 +246,21 @@ will fail. You must remove the Native Query first.
|
||||
To untrack the above "article" Logical Model, we would run the following:
|
||||
|
||||
<Tabs groupId="user-preference" className="api-tabs">
|
||||
|
||||
|
||||
<TabItem value="console" label="Console">
|
||||
|
||||
<Thumbnail
|
||||
src="/img/native-queries/delete-logical-model.png"
|
||||
alt="Delete Logical Model"
|
||||
width="800px"
|
||||
/>
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="cli" label="CLI">
|
||||
|
||||
Remove the above metadata from the `metadata > databases.yaml` file.
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="api" label="API">
|
||||
|
||||
```http
|
||||
@ -350,6 +409,35 @@ can receive.
|
||||
<Thumbnail src="/img/native-queries/create-permissions.png" alt="Create Logical Model Permissions" width="800px" />
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="cli" label="CLI">
|
||||
|
||||
Columns must be specified, though you can use `"*"` to specify that you want to allow all columns.
|
||||
|
||||
The filter is the same boolean expression syntax as [query filters](/queries/ms-sql-server/query-filters.mdx). To allow
|
||||
all rows to be passed through to the response, you can specify an empty filter, `{}`.
|
||||
|
||||
Add the required permissions to the relevant logical model in `metadata > databases.yaml`:
|
||||
|
||||
```yaml
|
||||
logical_models:
|
||||
- name: "<name>"
|
||||
fields:
|
||||
...
|
||||
select_permissions:
|
||||
- role: "<role name>"
|
||||
permission:
|
||||
columns: "*" | [
|
||||
"column 1",
|
||||
"column 2",
|
||||
...
|
||||
]
|
||||
filter: "<boolean expression>"
|
||||
- ...
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="api" label="API">
|
||||
|
||||
Columns must be specified, though you can use `"*"` to specify that you want to allow all columns.
|
||||
@ -393,6 +481,32 @@ that column from the list (by specifying all other columns).
|
||||
<Thumbnail src="/img/native-queries/permissions-with-check.png" alt="Permissions with check" width="800px" />
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="cli" label="CLI">
|
||||
|
||||
Add the required permissions to the relevant logical model in `metadata > databases.yaml`:
|
||||
|
||||
```yaml
|
||||
logical_models:
|
||||
- name: "<name>"
|
||||
fields:
|
||||
...
|
||||
select_permissions:
|
||||
- role: reader
|
||||
permission:
|
||||
columns:
|
||||
- id
|
||||
- title
|
||||
- contents
|
||||
- date
|
||||
filter:
|
||||
is_published:
|
||||
_eq: true
|
||||
- ...
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="api" label="API">
|
||||
|
||||
```http
|
||||
@ -428,8 +542,17 @@ You can also drop permissions:
|
||||
|
||||
<Tabs groupId="user-preference" className="api-tabs">
|
||||
<TabItem value="console" label="Console">
|
||||
<Thumbnail src="/img/native-queries/delete-permissions.png" alt="Delete Permissions" width="800px" />
|
||||
|
||||
<Thumbnail src="/img/native-queries/delete-permissions.png" alt="Delete Permissions" width="800px" />
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="cli" label="CLI">
|
||||
|
||||
Remove the relevant permission from `metadata > databases.yaml`.
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="api" label="API">
|
||||
|
||||
```http
|
||||
|
@ -9,7 +9,6 @@ keywords:
|
||||
- schema
|
||||
- Logical Models
|
||||
- Native Queries
|
||||
sidebar_class_name: beta-tag
|
||||
---
|
||||
|
||||
import ProductBadge from '@site/src/components/ProductBadge';
|
||||
@ -21,7 +20,6 @@ import Thumbnail from '@site/src/components/Thumbnail';
|
||||
|
||||
<div className="badge-container">
|
||||
<ProductBadge standard pro ee self />
|
||||
<div className="badge badge-gray heading-badge">Beta</div>
|
||||
</div>
|
||||
|
||||
## What are Native Queries?
|
||||
@ -88,13 +86,6 @@ INSERT INTO article(title, date, content) VALUES
|
||||
When listing these articles in an index, we probably want to truncate the text to, let’s say, 20 characters. So let’s
|
||||
create a Logical Model representing the excerpted article:
|
||||
|
||||
:::info Only creatable via the Console and API
|
||||
|
||||
Currently, Native Queries can be created using the Console and the API. CLI support will be added in a future
|
||||
release.
|
||||
|
||||
:::
|
||||
|
||||
<Tabs groupId="user-preference" className="api-tabs">
|
||||
<TabItem value="console" label="Console">
|
||||
|
||||
@ -111,6 +102,27 @@ Once the modal is open, fill in the form.
|
||||
/>
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="cli" label="CLI">
|
||||
|
||||
Add the following to the `default` database definition in the `metadata > databases.yaml` file:
|
||||
|
||||
```yaml
|
||||
logical_models:
|
||||
- name: article_excerpt
|
||||
fields:
|
||||
id:
|
||||
type: integer
|
||||
title:
|
||||
type: text
|
||||
date:
|
||||
type: date
|
||||
excerpt:
|
||||
type: text
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="api" label="API">
|
||||
|
||||
```http
|
||||
@ -182,6 +194,23 @@ FROM article
|
||||
/>
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="cli" label="CLI">
|
||||
|
||||
Add the following to the `default` database definition in the `metadata > databases.yaml` file:
|
||||
|
||||
```yaml
|
||||
native_queries:
|
||||
- root_field_name: article_with_excerpt
|
||||
arguments:
|
||||
max_length:
|
||||
type: integer
|
||||
code: SELECT id, title, (substring(content, 1, {{max_length}}) || (CASE WHEN length(content) < {{max_length}} THEN '' else '...' END)) AS excerpt, date FROM article
|
||||
returns: article_excerpt
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="api" label="API">
|
||||
|
||||
```http
|
||||
@ -285,6 +314,25 @@ Once the modal is open, fill in the forms with:
|
||||
<Thumbnail src="/img/native-queries/logical-model-modal.png" alt="Create Logical Model" width="800px" />
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="cli" label="CLI">
|
||||
|
||||
You can create a logical model by adding it to the appropriate database definition in the `metadata > databases.yaml`
|
||||
file:
|
||||
|
||||
```yaml
|
||||
logical_models:
|
||||
- name: "<name>"
|
||||
fields:
|
||||
"<field name>":
|
||||
type: "<BigQuery field type>"
|
||||
nullable: false | true
|
||||
description: "<optional field description>"
|
||||
...
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="api" label="API">
|
||||
|
||||
```http
|
||||
@ -336,6 +384,33 @@ Fill in the form with the data required:
|
||||
<Thumbnail src="/img/native-queries/create-native-query.png" alt="Create Native Query Form" width="1146px" />
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="cli" label="CLI">
|
||||
|
||||
Add the following to the relevant database definition in the `metadata > databases.yaml` file:
|
||||
|
||||
```yaml
|
||||
native_queries:
|
||||
- root_field_name: "<root field name>"
|
||||
arguments:
|
||||
"<argument name>":
|
||||
type: "<PostgreSQL field type>"
|
||||
nullable: false | true
|
||||
description: "<optional field description>"
|
||||
array_relationships:
|
||||
- name: "<relationship name>"
|
||||
using:
|
||||
column_mapping:
|
||||
"<local column>": "<remote column>"
|
||||
remote_native_query: <remote native query name>"
|
||||
object_relationships: <same as array_relationships>
|
||||
description: "<text>"
|
||||
code: "<SQL query>"
|
||||
returns: "<logical model name>"
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="api" label="API">
|
||||
|
||||
```http
|
||||
|
@ -37,21 +37,35 @@ of Logical Models themselves, read on.
|
||||
|
||||
## Tracking a Logical Model
|
||||
|
||||
:::info Only creatable via the Console and API
|
||||
|
||||
Currently, Logical Models can only be created via the API and the Console. CLI support will be added in a future
|
||||
release.
|
||||
|
||||
:::
|
||||
|
||||
<Tabs groupId="user-preference" className="api-tabs">
|
||||
<TabItem value="console" label="Console">
|
||||
|
||||
<Thumbnail
|
||||
src="/img/native-queries/create-logical-model-excerpt-example.png"
|
||||
alt="Create Logical Model"
|
||||
width="800px"
|
||||
/>
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="cli" label="CLI">
|
||||
|
||||
You can create a logical model by adding it to the appropriate database definition in the `metadata > databases.yaml`
|
||||
file:
|
||||
|
||||
```yaml
|
||||
logical_models:
|
||||
- name: "<name>"
|
||||
fields:
|
||||
"<field name>":
|
||||
type: "<SQL Server field type>"
|
||||
nullable: false | true
|
||||
description: "<optional field description>"
|
||||
...
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="api" label="API">
|
||||
|
||||
You create a logical model through the metadata API:
|
||||
@ -69,7 +83,7 @@ X-Hasura-Role: admin
|
||||
"fields": [
|
||||
{
|
||||
"name": "<field name>",
|
||||
"type": "<SQL Server Logical Model type>",
|
||||
"type": "<SQL Server field type>",
|
||||
"nullable": false | true,
|
||||
"description": "<optional field description>"
|
||||
},
|
||||
@ -90,12 +104,42 @@ For example, we could track a representation of an article as follows:
|
||||
|
||||
<Tabs groupId="user-preference" className="api-tabs">
|
||||
<TabItem value="console" label="Console">
|
||||
|
||||
<Thumbnail
|
||||
src="/img/native-queries/create-logical-model-excerpt-example.png"
|
||||
alt="Create Logical Model"
|
||||
width="800px"
|
||||
/>
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="cli" label="CLI">
|
||||
|
||||
Add the following to the `default` database definition in the `metadata > databases.yaml` file:
|
||||
|
||||
```yaml
|
||||
logical_models:
|
||||
- name: article
|
||||
fields:
|
||||
id:
|
||||
type: integer
|
||||
nullable: false
|
||||
title:
|
||||
type: text
|
||||
nullable: false
|
||||
contents:
|
||||
type: text
|
||||
nullable: false
|
||||
published_date:
|
||||
type: date
|
||||
nullable: true
|
||||
is_published:
|
||||
type: bit
|
||||
nullable: false
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="api" label="API">
|
||||
|
||||
```http
|
||||
@ -157,12 +201,21 @@ X-Hasura-Role: admin
|
||||
|
||||
<Tabs groupId="user-preference" className="api-tabs">
|
||||
<TabItem value="console" label="Console">
|
||||
|
||||
<Thumbnail
|
||||
src="/img/native-queries/delete-logical-model.png"
|
||||
alt="Delete Logical Model"
|
||||
width="800px"
|
||||
/>
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="cli" label="CLI">
|
||||
|
||||
You can remove a Logical Model by removing it from the `metadata > databases.yaml` file.
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="api" label="API">
|
||||
|
||||
You can remove a Logical Model the same way:
|
||||
@ -195,12 +248,21 @@ To untrack the above "article" Logical Model, we would run the following:
|
||||
|
||||
<Tabs groupId="user-preference" className="api-tabs">
|
||||
<TabItem value="console" label="Console">
|
||||
|
||||
<Thumbnail
|
||||
src="/img/native-queries/delete-logical-model.png"
|
||||
alt="Delete Logical Model"
|
||||
width="800px"
|
||||
/>
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="cli" label="CLI">
|
||||
|
||||
Remove the above metadata from the `metadata > databases.yaml` file.
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="api" label="API">
|
||||
|
||||
```http
|
||||
@ -349,6 +411,35 @@ can receive.
|
||||
<Thumbnail src="/img/native-queries/create-permissions.png" alt="Create Logical Model Permissions" width="800px" />
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="cli" label="CLI">
|
||||
|
||||
Columns must be specified, though you can use `"*"` to specify that you want to allow all columns.
|
||||
|
||||
The filter is the same boolean expression syntax as [query filters](/queries/ms-sql-server/query-filters.mdx). To allow
|
||||
all rows to be passed through to the response, you can specify an empty filter, `{}`.
|
||||
|
||||
Add the required permissions to the relevant logical model in `metadata > databases.yaml`:
|
||||
|
||||
```yaml
|
||||
logical_models:
|
||||
- name: "<name>"
|
||||
fields:
|
||||
...
|
||||
select_permissions:
|
||||
- role: "<role name>"
|
||||
permission:
|
||||
columns: "*" | [
|
||||
"column 1",
|
||||
"column 2",
|
||||
...
|
||||
]
|
||||
filter: "<boolean expression>"
|
||||
- ...
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="api" label="API">
|
||||
|
||||
Columns must be specified, though you can use `"*"` to specify that you want to allow all columns.
|
||||
@ -392,6 +483,32 @@ that column from the list (by specifying all other columns).
|
||||
<Thumbnail src="/img/native-queries/permissions-with-check.png" alt="Permissions with check" width="800px" />
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="cli" label="CLI">
|
||||
|
||||
Add the required permissions to the relevant logical model in `metadata > databases.yaml`:
|
||||
|
||||
```yaml
|
||||
logical_models:
|
||||
- name: "<name>"
|
||||
fields:
|
||||
...
|
||||
select_permissions:
|
||||
- role: reader
|
||||
permission:
|
||||
columns:
|
||||
- id
|
||||
- title
|
||||
- contents
|
||||
- date
|
||||
filter:
|
||||
is_published:
|
||||
_eq: true
|
||||
- ...
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="api" label="API">
|
||||
|
||||
```http
|
||||
@ -427,8 +544,17 @@ You can also drop permissions:
|
||||
|
||||
<Tabs groupId="user-preference" className="api-tabs">
|
||||
<TabItem value="console" label="Console">
|
||||
<Thumbnail src="/img/native-queries/delete-permissions.png" alt="Delete Permissions" width="800px" />
|
||||
|
||||
<Thumbnail src="/img/native-queries/delete-permissions.png" alt="Delete Permissions" width="800px" />
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="cli" label="CLI">
|
||||
|
||||
Remove the relevant permission from `metadata > databases.yaml`.
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="api" label="API">
|
||||
|
||||
```http
|
||||
@ -447,5 +573,4 @@ X-Hasura-Role: admin
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
</Tabs>
|
||||
|
@ -9,7 +9,6 @@ keywords:
|
||||
- schema
|
||||
- Logical Models
|
||||
- Native Queries
|
||||
sidebar_class_name: beta-tag
|
||||
---
|
||||
|
||||
import ProductBadge from '@site/src/components/ProductBadge';
|
||||
@ -21,7 +20,6 @@ import Thumbnail from '@site/src/components/Thumbnail';
|
||||
|
||||
<div className="badge-container">
|
||||
<ProductBadge standard pro ee self />
|
||||
<div className="badge badge-gray heading-badge">Beta</div>
|
||||
</div>
|
||||
|
||||
## What are Native Queries?
|
||||
@ -88,13 +86,6 @@ INSERT INTO article(title, date, content) VALUES
|
||||
When listing these articles in an index, we probably want to truncate the text to, let’s say, 20 characters. So let’s
|
||||
create a Logical Model representing the excerpted article:
|
||||
|
||||
:::info Only creatable via the Console and API
|
||||
|
||||
Currently, Native Queries can be created using the Console and the API. CLI support will be added in a future
|
||||
release.
|
||||
|
||||
:::
|
||||
|
||||
<Tabs groupId="user-preference" className="api-tabs">
|
||||
<TabItem value="console" label="Console">
|
||||
|
||||
@ -111,6 +102,27 @@ Once the modal is open, fill in the form.
|
||||
/>
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="cli" label="CLI">
|
||||
|
||||
Add the following to the `default` database definition in the `metadata > databases.yaml` file:
|
||||
|
||||
```yaml
|
||||
logical_models:
|
||||
- name: article_excerpt
|
||||
fields:
|
||||
id:
|
||||
type: integer
|
||||
title:
|
||||
type: text
|
||||
date:
|
||||
type: date
|
||||
excerpt:
|
||||
type: text
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="api" label="API">
|
||||
|
||||
```http
|
||||
@ -184,6 +196,23 @@ FROM article
|
||||
/>
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="cli" label="CLI">
|
||||
|
||||
Add the following to the `default` database definition in the `metadata > databases.yaml` file:
|
||||
|
||||
```yaml
|
||||
native_queries:
|
||||
- root_field_name: article_with_excerpt
|
||||
arguments:
|
||||
max_length:
|
||||
type: integer
|
||||
code: SELECT id, title, (substring(content, 1, {{max_length}}) || (CASE WHEN length(content) < {{max_length}} THEN '' else '...' END)) AS excerpt, date FROM article
|
||||
returns: article_excerpt
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="api" label="API">
|
||||
|
||||
```http
|
||||
@ -288,6 +317,25 @@ Once the modal is open, fill in the forms with:
|
||||
<Thumbnail src="/img/native-queries/logical-model-modal.png" alt="Create Logical Model" width="800px" />
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="cli" label="CLI">
|
||||
|
||||
You can create a logical model by adding it to the appropriate database definition in the `metadata > databases.yaml`
|
||||
file:
|
||||
|
||||
```yaml
|
||||
logical_models:
|
||||
- name: "<name>"
|
||||
fields:
|
||||
"<field name>":
|
||||
type: "<SQL Server field type>"
|
||||
nullable: false | true
|
||||
description: "<optional field description>"
|
||||
...
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="api" label="API">
|
||||
|
||||
```http
|
||||
@ -339,6 +387,33 @@ Fill in the form with the data required:
|
||||
<Thumbnail src="/img/native-queries/create-native-query.png" alt="Create Native Query Form" width="1146px" />
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="cli" label="CLI">
|
||||
|
||||
Add the following to the relevant database definition in the `metadata > databases.yaml` file:
|
||||
|
||||
```yaml
|
||||
native_queries:
|
||||
- root_field_name: "<root field name>"
|
||||
arguments:
|
||||
"<argument name>":
|
||||
type: "<PostgreSQL field type>"
|
||||
nullable: false | true
|
||||
description: "<optional field description>"
|
||||
array_relationships:
|
||||
- name: "<relationship name>"
|
||||
using:
|
||||
column_mapping:
|
||||
"<local column>": "<remote column>"
|
||||
remote_native_query: <remote native query name>"
|
||||
object_relationships: <same as array_relationships>
|
||||
description: "<text>"
|
||||
code: "<SQL query>"
|
||||
returns: "<logical model name>"
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="api" label="API">
|
||||
|
||||
```http
|
||||
|
@ -7,7 +7,7 @@ keywords:
|
||||
- docs
|
||||
- ms sql server
|
||||
- schema
|
||||
- Logical Models
|
||||
- logical models
|
||||
- stored procedures
|
||||
sidebar_class_name: alpha-tag
|
||||
---
|
||||
@ -16,7 +16,7 @@ import ProductBadge from '@site/src/components/ProductBadge';
|
||||
import Tabs from '@theme/Tabs';
|
||||
import TabItem from '@theme/TabItem';
|
||||
|
||||
# MS SQL Server: stored procedures
|
||||
# MS SQL Server: Stored Procedures
|
||||
|
||||
<div className="badge-container">
|
||||
<ProductBadge standard pro ee self />
|
||||
@ -27,11 +27,11 @@ import TabItem from '@theme/TabItem';
|
||||
|
||||
:::tip Supported from
|
||||
|
||||
stored procedures are supported from `v2.26.0`.
|
||||
Stored procedures are supported from `v2.26.0`.
|
||||
|
||||
:::
|
||||
|
||||
stored procedures can be used to track MS SQL Server
|
||||
Stored procedures can be used to track MS SQL Server
|
||||
[stored procedures](https://learn.microsoft.com/en-us/sql/relational-databases/stored-procedures/stored-procedures-database-engine)
|
||||
and execute them via the Hasura GraphQL Engine.
|
||||
|
||||
@ -60,14 +60,41 @@ stored procedure.
|
||||
|
||||
We can create a Logical Model representing the results set:
|
||||
|
||||
:::info Only creatable via the API
|
||||
:::info Only creatable via the CLI oand API
|
||||
|
||||
Currently, stored procedures can only be created using the API. Console and CLI support will be added in a future
|
||||
Currently, stored procedures can only be created using the CLI or API. Console support will be added in a future
|
||||
release.
|
||||
|
||||
:::
|
||||
|
||||
<Tabs groupId="user-preference" className="api-tabs">
|
||||
<TabItem value="cli" label="CLI">
|
||||
|
||||
Add the following to the relevant database definition in the `metadata > databases.yaml` file:
|
||||
|
||||
```yaml
|
||||
logical_models:
|
||||
- name: tables
|
||||
fields:
|
||||
TABLE_QUALIFIER:
|
||||
type: sysname
|
||||
nullable: true
|
||||
TABLE_OWNER:
|
||||
type: sysname
|
||||
nullable: true
|
||||
TABLE_NAME:
|
||||
type: sysname
|
||||
nullable: true
|
||||
TABLE_TYPE:
|
||||
type: "varchar(32)"
|
||||
nullable: true
|
||||
REMARKS:
|
||||
type: "varchar(254)"
|
||||
nullable: true
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="api" label="API">
|
||||
|
||||
```http
|
||||
@ -127,6 +154,25 @@ database stored procedure and the Logical Model or the arguments, an error will
|
||||
:::
|
||||
|
||||
<Tabs groupId="user-preference" className="api-tabs">
|
||||
<TabItem value="cli" label="CLI">
|
||||
|
||||
Add the following to the relevant database definition in the `metadata > databases.yaml` file:
|
||||
|
||||
```yaml
|
||||
stored_procedures:
|
||||
- stored_procedure:
|
||||
schema: public
|
||||
name: sp_tables
|
||||
configuration:
|
||||
exposed_as: query
|
||||
arguments:
|
||||
table_type:
|
||||
type: varchar
|
||||
returns: tables
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="api" label="API">
|
||||
|
||||
```http
|
||||
@ -213,6 +259,24 @@ Note that this Logical Model has no attached permissions and therefore will only
|
||||
:::
|
||||
|
||||
<Tabs groupId="user-preference" className="api-tabs">
|
||||
<TabItem value="cli" label="CLI">
|
||||
|
||||
You can create a logical model by adding it to the appropriate database definition in the `metadata > databases.yaml`
|
||||
file:
|
||||
|
||||
```yaml
|
||||
logical_models:
|
||||
- name: "<name>"
|
||||
fields:
|
||||
"<field name>":
|
||||
type: "<SQL Server field type>"
|
||||
nullable: false | true
|
||||
description: "<optional field description>"
|
||||
...
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="api" label="API">
|
||||
|
||||
```http
|
||||
@ -246,6 +310,28 @@ X-Hasura-Role: admin
|
||||
Once the Logical Model is defined, we can use it to define the query:
|
||||
|
||||
<Tabs groupId="user-preference" className="api-tabs">
|
||||
<TabItem value="cli" label="CLI">
|
||||
|
||||
Add the following to the relevant database definition in the `metadata > databases.yaml` file:
|
||||
|
||||
```yaml
|
||||
stored_procedures:
|
||||
- stored_procedure:
|
||||
schema: "<schema name>"
|
||||
name: "<procedure name>"
|
||||
configuration:
|
||||
exposed_as: query
|
||||
custom_name: "<custom name>"
|
||||
arguments:
|
||||
"<argument name>":
|
||||
type: "<SQL Server field type>"
|
||||
nullable: false | true
|
||||
description: "<optional argument description>"
|
||||
returns: "<logical model name>"
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="api" label="API">
|
||||
|
||||
```http
|
||||
@ -256,20 +342,20 @@ X-Hasura-Role: admin
|
||||
{
|
||||
"type": "mssql_track_stored_procedure",
|
||||
"args": {
|
||||
"source": <source-name>,
|
||||
"stored_procedure": <name> | { "schema": <schema-name>, "name": <procedure-name> },
|
||||
"source": <source name>,
|
||||
"stored_procedure": <procedure name> | { "schema": <schema name>, "name": <procedure name> },
|
||||
"arguments": {
|
||||
<name>: {
|
||||
"type": "<type>",
|
||||
"<argument name>": {
|
||||
"type": "<SQL Server field type>",
|
||||
"nullable": false | true,
|
||||
"description": <string>
|
||||
"description": "<optional argument description>"
|
||||
}
|
||||
},
|
||||
"configuration": {
|
||||
"exposed_as": "query",
|
||||
"custom_name": <custom-name>
|
||||
"custom_name": <custom name>
|
||||
},
|
||||
"returns": <logical-model-name>
|
||||
"returns": <logical model name>
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -38,21 +38,35 @@ Logical Models themselves, read on.
|
||||
|
||||
## Tracking a Logical Model
|
||||
|
||||
:::info Only creatable via the Console and API
|
||||
|
||||
Currently, Logical Models can only be created via the API and the Console. CLI support will be added in a future
|
||||
release.
|
||||
|
||||
:::
|
||||
|
||||
<Tabs groupId="user-preference" className="api-tabs">
|
||||
<TabItem value="console" label="Console">
|
||||
|
||||
<Thumbnail
|
||||
src="/img/native-queries/create-logical-model-excerpt-example.png"
|
||||
alt="Create Logical Model"
|
||||
width="800px"
|
||||
/>
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="cli" label="CLI">
|
||||
|
||||
You can create a logical model by adding it to the appropriate database definition in the `metadata > databases.yaml`
|
||||
file:
|
||||
|
||||
```yaml
|
||||
logical_models:
|
||||
- name: "<name>"
|
||||
fields:
|
||||
"<field name>":
|
||||
type: "<PostgreSQL field type>"
|
||||
nullable: false | true
|
||||
description: "<optional field description>"
|
||||
...
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="api" label="API">
|
||||
|
||||
You create a logical model through the metadata API:
|
||||
@ -70,7 +84,7 @@ X-Hasura-Role: admin
|
||||
"fields": [
|
||||
{
|
||||
"name": "<field name>",
|
||||
"type": "<PostgreSQL Logical Model type>",
|
||||
"type": "<PostgreSQL field type>",
|
||||
"nullable": false | true,
|
||||
"description": "<optional field description>"
|
||||
},
|
||||
@ -91,12 +105,42 @@ For example, we could track a representation of an article as follows:
|
||||
|
||||
<Tabs groupId="user-preference" className="api-tabs">
|
||||
<TabItem value="console" label="Console">
|
||||
|
||||
<Thumbnail
|
||||
src="/img/native-queries/create-logical-model-excerpt-example.png"
|
||||
alt="Create Logical Model"
|
||||
width="800px"
|
||||
/>
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="cli" label="CLI">
|
||||
|
||||
Add the following to the `default` database definition in the `metadata > databases.yaml` file:
|
||||
|
||||
```yaml
|
||||
logical_models:
|
||||
- name: article
|
||||
fields:
|
||||
id:
|
||||
type: integer
|
||||
nullable: false
|
||||
title:
|
||||
type: text
|
||||
nullable: false
|
||||
contents:
|
||||
type: text
|
||||
nullable: false
|
||||
published_date:
|
||||
type: date
|
||||
nullable: true
|
||||
is_published:
|
||||
type: boolean
|
||||
nullable: false
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="api" label="API">
|
||||
|
||||
```http
|
||||
@ -158,12 +202,21 @@ X-Hasura-Role: admin
|
||||
|
||||
<Tabs groupId="user-preference" className="api-tabs">
|
||||
<TabItem value="console" label="Console">
|
||||
|
||||
<Thumbnail
|
||||
src="/img/native-queries/delete-logical-model.png"
|
||||
alt="Delete Logical Model"
|
||||
width="800px"
|
||||
/>
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="cli" label="CLI">
|
||||
|
||||
You can remove a Logical Model by removing it from the `metadata > databases.yaml` file.
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="api" label="API">
|
||||
|
||||
You can remove a Logical Model the same way:
|
||||
@ -195,6 +248,22 @@ will fail. You must remove the Native Query first.
|
||||
To untrack the above "article" Logical Model, we would run the following:
|
||||
|
||||
<Tabs groupId="user-preference" className="api-tabs">
|
||||
<TabItem value="console" label="Console">
|
||||
|
||||
<Thumbnail
|
||||
src="/img/native-queries/delete-logical-model.png"
|
||||
alt="Delete Logical Model"
|
||||
width="800px"
|
||||
/>
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="cli" label="CLI">
|
||||
|
||||
Remove the above metadata from the `metadata > databases.yaml` file.
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="api" label="API">
|
||||
|
||||
```http
|
||||
@ -211,14 +280,6 @@ X-Hasura-Role: admin
|
||||
}
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="console" label="Console">
|
||||
<Thumbnail
|
||||
src="/img/native-queries/delete-logical-model.png"
|
||||
alt="Delete Logical Model"
|
||||
width="800px"
|
||||
/>
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
@ -351,6 +412,35 @@ can receive.
|
||||
<Thumbnail src="/img/native-queries/create-permissions.png" alt="Create Logical Model Permissions" width="800px" />
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="cli" label="CLI">
|
||||
|
||||
Columns must be specified, though you can use `"*"` to specify that you want to allow all columns.
|
||||
|
||||
The filter is the same boolean expression syntax as [query filters](/queries/ms-sql-server/query-filters.mdx). To allow
|
||||
all rows to be passed through to the response, you can specify an empty filter, `{}`.
|
||||
|
||||
Add the required permissions to the relevant logical model in `metadata > databases.yaml`:
|
||||
|
||||
```yaml
|
||||
logical_models:
|
||||
- name: "<name>"
|
||||
fields:
|
||||
...
|
||||
select_permissions:
|
||||
- role: "<role name>"
|
||||
permission:
|
||||
columns: "*" | [
|
||||
"column 1",
|
||||
"column 2",
|
||||
...
|
||||
]
|
||||
filter: "<boolean expression>"
|
||||
- ...
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="api" label="API">
|
||||
|
||||
Columns must be specified, though you can use `"*"` to specify that you want to allow all columns.
|
||||
@ -394,6 +484,32 @@ that column from the list (by specifying all other columns).
|
||||
<Thumbnail src="/img/native-queries/permissions-with-check.png" alt="Permissions with check" width="800px" />
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="cli" label="CLI">
|
||||
|
||||
Add the required permissions to the relevant logical model in `metadata > databases.yaml`:
|
||||
|
||||
```yaml
|
||||
logical_models:
|
||||
- name: "<name>"
|
||||
fields:
|
||||
...
|
||||
select_permissions:
|
||||
- role: reader
|
||||
permission:
|
||||
columns:
|
||||
- id
|
||||
- title
|
||||
- contents
|
||||
- date
|
||||
filter:
|
||||
is_published:
|
||||
_eq: true
|
||||
- ...
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="api" label="API">
|
||||
|
||||
```http
|
||||
@ -431,6 +547,13 @@ You can also drop permissions:
|
||||
<TabItem value="console" label="Console">
|
||||
<Thumbnail src="/img/native-queries/delete-permissions.png" alt="Delete Permissions" width="800px" />
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="cli" label="CLI">
|
||||
|
||||
Remove the relevant permission from `metadata > databases.yaml`.
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="api" label="API">
|
||||
|
||||
```http
|
||||
|
@ -9,7 +9,6 @@ keywords:
|
||||
- schema
|
||||
- Logical Models
|
||||
- Native Queries
|
||||
sidebar_class_name: beta-tag
|
||||
---
|
||||
|
||||
import ProductBadge from '@site/src/components/ProductBadge';
|
||||
@ -19,10 +18,6 @@ import Thumbnail from '@site/src/components/Thumbnail';
|
||||
|
||||
# Postgres: Native Queries
|
||||
|
||||
<div className="badge-container">
|
||||
<div className="badge badge-gray heading-badge">Beta</div>
|
||||
</div>
|
||||
|
||||
## What are Native Queries?
|
||||
|
||||
:::tip Supported from
|
||||
@ -90,12 +85,6 @@ INSERT INTO article(title, date, content) VALUES
|
||||
When listing these articles in an index, we probably want to truncate the text to, let’s say, 20 characters. So let’s
|
||||
create a Logical Model representing the excerpted article:
|
||||
|
||||
:::info Only creatable via the Console and API
|
||||
|
||||
Currently, Native Queries can be created using the Console and the API. CLI support will be added in a future release.
|
||||
|
||||
:::
|
||||
|
||||
<Tabs groupId="user-preference" className="api-tabs">
|
||||
<TabItem value="console" label="Console">
|
||||
|
||||
@ -112,6 +101,27 @@ Once the modal is open, fill in the form.
|
||||
/>
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="cli" label="CLI">
|
||||
|
||||
Add the following to the `default` database definition in the `metadata > databases.yaml` file:
|
||||
|
||||
```yaml
|
||||
logical_models:
|
||||
- name: article_excerpt
|
||||
fields:
|
||||
id:
|
||||
type: integer
|
||||
title:
|
||||
type: text
|
||||
date:
|
||||
type: date
|
||||
excerpt:
|
||||
type: text
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="api" label="API">
|
||||
|
||||
```http
|
||||
@ -183,6 +193,23 @@ FROM article
|
||||
/>
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="cli" label="CLI">
|
||||
|
||||
Add the following to the `default` database definition in the `metadata > databases.yaml` file:
|
||||
|
||||
```yaml
|
||||
native_queries:
|
||||
- root_field_name: article_with_excerpt
|
||||
arguments:
|
||||
max_length:
|
||||
type: integer
|
||||
code: SELECT id, title, (substring(content, 1, {{max_length}}) || (CASE WHEN length(content) < {{max_length}} THEN '' else '...' END)) AS excerpt, date FROM article
|
||||
returns: article_excerpt
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="api" label="API">
|
||||
|
||||
```http
|
||||
@ -286,6 +313,25 @@ Once the modal is open, fill in the forms with:
|
||||
<Thumbnail src="/img/native-queries/logical-model-modal.png" alt="Create Logical Model" width="800px" />
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="cli" label="CLI">
|
||||
|
||||
You can create a logical model by adding it to the appropriate database definition in the `metadata > databases.yaml`
|
||||
file:
|
||||
|
||||
```yaml
|
||||
logical_models:
|
||||
- name: "<name>"
|
||||
fields:
|
||||
"<field name>":
|
||||
type: "<PostgreSQL field type>"
|
||||
nullable: false | true
|
||||
description: "<optional field description>"
|
||||
...
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="api" label="API">
|
||||
|
||||
```http
|
||||
@ -337,6 +383,33 @@ Fill in the form with the data required:
|
||||
<Thumbnail src="/img/native-queries/create-native-query.png" alt="Create Native Query Form" width="1146px" />
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="cli" label="CLI">
|
||||
|
||||
Add the following to the relevant database definition in the `metadata > databases.yaml` file:
|
||||
|
||||
```yaml
|
||||
native_queries:
|
||||
- root_field_name: "<root field name>"
|
||||
arguments:
|
||||
"<argument name>":
|
||||
type: "<PostgreSQL field type>"
|
||||
nullable: false | true
|
||||
description: "<optional field description>"
|
||||
array_relationships:
|
||||
- name: "<relationship name>"
|
||||
using:
|
||||
column_mapping:
|
||||
"<local column>": "<remote column>"
|
||||
remote_native_query: <remote native query name>"
|
||||
object_relationships: <same as array_relationships>
|
||||
description: "<text>"
|
||||
code: "<SQL query>"
|
||||
returns: "<logical model name>"
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
|
||||
<TabItem value="api" label="API">
|
||||
|
||||
```http
|
||||
@ -597,6 +670,7 @@ allows for mutual references.
|
||||
|
||||
</TabItem>
|
||||
<TabItem value="query" label="Query">
|
||||
|
||||
The Native Queries in this example enable queries like:
|
||||
|
||||
```graphql
|
||||
|
Loading…
Reference in New Issue
Block a user