Skip to content

Commit

Permalink
Docs: Add data modeling section
Browse files Browse the repository at this point in the history
  • Loading branch information
robertjdominguez committed Oct 23, 2024
1 parent 154d13f commit fd0535d
Show file tree
Hide file tree
Showing 6 changed files with 441 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/data-modeling/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"label": "Data Modeling",
"position": 3,
"className": "deployment",
"customProps": {
"sidebar_pathname": "data-modeling"
}
}
70 changes: 70 additions & 0 deletions docs/data-modeling/command.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
sidebar_position: 3
sidebar_label: "Commands modify data"
description: "Commands allow you to modify data in your data source."
keywords:
- command
- data modeling
---

import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";
import Thumbnail from "@site/src/components/Thumbnail";

# Commands Modify Data

## Introduction

Commands enable you to perform actions that modify data — such a perform updates or inserts — in your data source.
Commands also allow you to execute custom business logic directly via your API.

## Lifecycle

:::info New to Hasura DDN?

If you haven't already, have a run through our [Quickstart](/getting-started/quickstart.mdx) guide to set up your Hasura
DDN instance. In the sections below, we'll guide you through how to interact with your metadata and shape your API to
your liking!

:::

### Creating a command

To modify data, you first need to create a command that maps to a specific operation within your data source.

<Tabs groupId="source-preference" className="api-tabs">
<TabItem value="PostgreSQL" label="PostgreSQL"></TabItem>
<TabItem value="MongoDB" label="MongoDB"></TabItem>
<TabItem value="ClickHouse" label="ClickHouse"></TabItem>
</Tabs>

:::info Lambda connectors

Lambda connectors allow you to execute custom business logic directly via your API. You can learn more about Lambda
connectors in the [docs](/business-logic/overview.mdx).

:::

### Updating a command

Your underlying data source may change over time. You can update your command to reflect these changes.

<Tabs groupId="source-preference" className="api-tabs">
<TabItem value="PostgreSQL" label="PostgreSQL"></TabItem>
<TabItem value="MongoDB" label="MongoDB"></TabItem>
<TabItem value="ClickHouse" label="ClickHouse"></TabItem>
</Tabs>

### Deleting a command

If you no longer need a command, you can delete it.

<Tabs groupId="source-preference" className="api-tabs">
<TabItem value="PostgreSQL" label="PostgreSQL"></TabItem>
<TabItem value="MongoDB" label="MongoDB"></TabItem>
<TabItem value="ClickHouse" label="ClickHouse"></TabItem>
</Tabs>

## Reference

You can learn more about commands in the metadata reference [docs](/supergraph-modeling/commands.mdx).
166 changes: 166 additions & 0 deletions docs/data-modeling/model.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
---
sidebar_position: 2
sidebar_label: "Models read data"
description: "Models allow you to define the structure of your data and how it can be queried."
keywords:
- model
- data modeling
toc_max_heading_level: 4
---

import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";
import Thumbnail from "@site/src/components/Thumbnail";

# Models Read Data

## Introduction

Models represent the entities — such as tables, views, or collections — in your data source, defining the structure and
how the data can be accessed.

## Lifecycle

:::info New to Hasura DDN?

If you haven't already, have a run through our [Quickstart](/getting-started/quickstart.mdx) guide to set up your Hasura
DDN instance. In the sections below, we'll guide you through how to interact with your metadata and shape your API to
your liking!

:::

### Creating a model

To query data from your API, you'll first need to create a model that represents that data.

<Tabs groupId="source-preference" className="api-tabs">
<TabItem value="PostgreSQL" label="PostgreSQL">

**Via a new table or view**

```sql title="Create a new table or view in your PostgreSQL database:"
CREATE TABLE public.users (
id serial PRIMARY KEY,
name text NOT NULL
);
```

```bash title="Use the DDN CLI to introspect your PostgreSQL instance:"
ddn connector introspect <connector_name>
```

```bash title="Then, add your model:"
ddn model add <connector_name> users
```

**Via an existing table or view**

If you already have a table present, you can add it by introspecting your data source and referencing it by name.

```bash title="Use the DDN CLI to introspect your PostgreSQL instance:"
ddn connector introspect <connector_name>
```

```bash title="Then, add your model:"
ddn model add <connector_name> users
```

</TabItem>
<TabItem value="MongoDB" label="MongoDB"></TabItem>
<TabItem value="ClickHouse" label="ClickHouse"></TabItem>
</Tabs>

### Extending a model

Models can be extended, allowing for transformation and enrichment of the data.

#### Via a native query

<Tabs groupId="source-preference" className="api-tabs">
<TabItem value="PostgreSQL" label="PostgreSQL">

Within your connector's directory, you can add a new file with a `.sql` extension to define a native query.

```sh title="Create a new directory to store your native queries:"
mkdir -p <my_subgraph>/connector/<connector_name>/native_operations/queries/
```

```sql title="Create a new file in your connector's directory:"
-- native_operations/queries/user_by_name_between.sql
SELECT *
FROM "Users"
WHERE "Name" LIKE '%' || {{name}} || '%'
AND "Name" > {{lower_bound}}
AND "Name" < {{upper_bound}}
```

```sh title="Then, use the PostgreSQL connector's plugin to add the native query to your connector's configuration:"
ddn connector plugin --connector <my_subgraph>/connector/<my_connector>/connector.yaml -- \
native-operation create --operation-path native_operations/queries/user_by_name_between.sql --kind query
```

```sh title="Introspect your PostgreSQL instance:"
ddn connector introspect <connector_name>
```

```sh title="Then, update your models:"
ddn model update <connector_name> "*"
```

</TabItem>
<TabItem value="MongoDB" label="MongoDB"></TabItem>
<TabItem value="ClickHouse" label="ClickHouse"></TabItem>
</Tabs>

#### Via a lambda connector

<Tabs groupId="source-preference" className="api-tabs">
<TabItem value="PostgreSQL" label="PostgreSQL">

TODO: Fill in the details for extending a model via a lambda connector.

</TabItem>
<TabItem value="MongoDB" label="MongoDB"></TabItem>
<TabItem value="ClickHouse" label="ClickHouse"></TabItem>
</Tabs>

### Updating a model

Your underlying data source may change over time. You can update your model to reflect these changes.

You'll need to update the mapping of your model to the data source by updating the
[DataConnectorLink](/supergraph-modeling/data-connector-links.mdx) object.

<Tabs groupId="source-preference" className="api-tabs">
<TabItem value="PostgreSQL" label="PostgreSQL">

```bash title="Update your DataConnectorLink:"
ddn connector-link update <connector_name> --subgraph <path_to_subgraph.yaml>
```

```bash title="Then, update your model:"
ddn model update <connector_name> users
```

</TabItem>
<TabItem value="MongoDB" label="MongoDB"></TabItem>
<TabItem value="ClickHouse" label="ClickHouse"></TabItem>
</Tabs>

### Deleting a model

If you no longer need a model, you can delete it.

<Tabs groupId="source-preference" className="api-tabs">
<TabItem value="PostgreSQL" label="PostgreSQL">

TODO: The CLI team is in the process of implementing this feature. Stay tuned!

</TabItem>
<TabItem value="MongoDB" label="MongoDB"></TabItem>
<TabItem value="ClickHouse" label="ClickHouse"></TabItem>
</Tabs>

## Reference

You can learn more about models in the metadata reference [docs](/supergraph-modeling/models.mdx).
59 changes: 59 additions & 0 deletions docs/data-modeling/overview.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
sidebar_position: 1
sidebar_label: Overview
description:
"Data modeling with Hasura DDN is simultaneously simple and powerful. Learn how to model your data with Hasura DDN to
get the best API performance on top of your data."
keywords:
- hasura ddn
- data modeling
hide_table_of_contents: true
---

import { OverviewTopSectionIconNoVideo } from "@site/src/components/OverviewTopSectionIconNoVideo";
import { OverviewPlainCard } from "@site/src/components/OverviewPlainCard";
import Icon from "@site/static/icons/features/deployment.svg";

# Data Modeling

<OverviewTopSectionIconNoVideo
icon={<Icon />}
links={[]}
intro={
<div>
<p>
Experience seamless data modeling with Hasura DDN. Whether you're building a simple CRUD app or scaling to
complex data architectures, Hasura DDN offers the flexibility to adapt to your needs.
</p>
<p>
Effortlessly define data models, relationships, and permissions that power high-performance APIs. With minimal
setup, you can transform your raw data into production-ready APIs in minutes.
</p>
</div>
}
/>

<div className="overview-gallery card-wrapper">

<OverviewPlainCard
title="Models Read Data"
body="Architecture overview for Hasura DDN and various deployment options."
link="/data-modeling/model/"
linkText={"Learn more"}
/>

<OverviewPlainCard
title="Commands Modify Data"
body="Learn more about the serverless-edge capabilities of Hasura DDN."
link="/data-modeling/command/"
linkText={"Learn more"}
/>

<OverviewPlainCard
title="Relationships Connect Data"
body="See how you can privately deploy your own DDN instance."
link="/data-modeling/relationship/"
linkText={"Learn more"}
/>

</div>
76 changes: 76 additions & 0 deletions docs/data-modeling/permissions.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
sidebar_position: 5
sidebar_label: "Permissions protect data"
description: "Permissions allow you to control who can access your data and what they can do with it."
keywords:
- permissions
- data modeling
toc_max_heading_level: 4
---

import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";
import Thumbnail from "@site/src/components/Thumbnail";

# Permissions Protect Data

## Introduction

Permissions allow you to control who can access your data and what they can do with it. You can define permissions to
restrict access to certain models, the fields they contain, and the operations that can be performed on them.

## Lifecycle

:::info New to Hasura DDN?

If you haven't already, have a run through our [Quickstart](/getting-started/quickstart.mdx) guide to set up your Hasura
DDN instance. In the sections below, we'll guide you through how to interact with your metadata and shape your API to
your liking!

:::

### Creating permissions

#### Creating a ModelPermission

To implement row-level security, you can create a permission for a model.

<Tabs groupId="source-preference" className="api-tabs">
<TabItem value="PostgreSQL" label="PostgreSQL"></TabItem>
<TabItem value="MongoDB" label="MongoDB"></TabItem>
<TabItem value="ClickHouse" label="ClickHouse"></TabItem>
</Tabs>

#### Creating a TypePermission

To restrict which fields can be queried, you can create a permission for a type.

<Tabs groupId="source-preference" className="api-tabs">
<TabItem value="PostgreSQL" label="PostgreSQL"></TabItem>
<TabItem value="MongoDB" label="MongoDB"></TabItem>
<TabItem value="ClickHouse" label="ClickHouse"></TabItem>
</Tabs>

#### Creating a CommandPermission

To restrict which operations can be performed, you can create a permission for a command.

<Tabs groupId="source-preference" className="api-tabs">
<TabItem value="PostgreSQL" label="PostgreSQL"></TabItem>
<TabItem value="MongoDB" label="MongoDB"></TabItem>
<TabItem value="ClickHouse" label="ClickHouse"></TabItem>
</Tabs>

### Deleting permissions

If you no longer need a permission, you can delete it.

<Tabs groupId="source-preference" className="api-tabs">
<TabItem value="PostgreSQL" label="PostgreSQL"></TabItem>
<TabItem value="MongoDB" label="MongoDB"></TabItem>
<TabItem value="ClickHouse" label="ClickHouse"></TabItem>
</Tabs>

## Reference

You can learn more about permissions in the metadata reference [docs](/supergraph-modeling/permissions.mdx).
Loading

0 comments on commit fd0535d

Please sign in to comment.