Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add codeblock component #45

Merged
merged 13 commits into from
Sep 14, 2021
Prev Previous commit
Next Next commit
add code blocks component to updating-data
  • Loading branch information
fdmmarshall committed Sep 7, 2021
commit 62f758758230271d46ea92d0765f2a28d4c20f50
74 changes: 73 additions & 1 deletion website/docs/overview/transact/updating-data.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# Updating Data

## Updating {#updating}
Expand All @@ -6,7 +9,15 @@ In order to update data, you can reference an existing subject by using its `_id

When referencing an existing subject, `"_action": "update"` is inferred. Note: When updating and upserting, you can use [nested transactions](/docs/transact/adding-data#nested-transactions).

Update using a two-tuple with a unique predicate. i.e. `person/handle` and relevant object:
Update using a two-tuple with a unique predicate. i.e. `person/handle` and relevant object:

<Tabs
defaultValue="json"
values={[{label: 'JSON', value: 'json'},
{label: 'Curl', value: 'bash'},
{label: 'GraphQL', value: 'graphql'},
{label: 'Sparql', value: 'sparql'}]}>
<TabItem value="json">

```json
[{
Expand All @@ -15,6 +26,10 @@ Update using a two-tuple with a unique predicate. i.e. `person/handle` and relev
}]
```

</TabItem>

<TabItem value="bash">

```bash
curl \
-H "Content-Type: application/json" \
Expand All @@ -26,6 +41,10 @@ curl \
[HOST]/api/db/transact
```

</TabItem>

<TabItem value="graphql">

```graphql
mutation updatePerson($myUpdatePersonTx: JSON) {
transact(tx: $myUpdatePersonTx)
Expand All @@ -36,19 +55,38 @@ mutation updatePerson($myUpdatePersonTx: JSON) {
}
```

</TabItem>

<TabItem value="sparql">

```sparql
Transactions not supported in SPARQL
```

</TabItem>
</Tabs>

Update using subject id:

<Tabs
defaultValue="json"
values={[{label: 'JSON', value: 'json'},
{label: 'Curl', value: 'bash'},
{label: 'GraphQL', value: 'graphql'},
{label: 'Sparql', value: 'sparql'}]}>
<TabItem value="json">

```json
[{
"_id": 351843720888324,
"age": 71
}]
```

</TabItem>

<TabItem value="bash">

```bash
curl \
-H "Content-Type: application/json" \
Expand All @@ -60,6 +98,10 @@ curl \
[HOST]/api/db/transact
```

</TabItem>

<TabItem value="graphql">

```graphql
mutation updateById ($myUpdateByIdTx: JSON) {
transact(tx: $myUpdateByIdTx)
Expand All @@ -70,10 +112,17 @@ mutation updateById ($myUpdateByIdTx: JSON) {
}
```

</TabItem>

<TabItem value="sparql">

```sparql
Transactions not supported in SPARQL
```

</TabItem>
</Tabs>

## Upserting {#upserting}

You can upsert data if you have a unique predicate marked, `"upsert": true`. In this case, when a transaction with a tempid resolves to an existing subject, `"_action": "upsert"` is inferred.
Expand All @@ -89,6 +138,14 @@ We can make `person/handle` a upsertable predicate with the following

After issuing the above transaction, we can issue the below transaction, which will just update jdoe's age, rather than creating a new person.

<Tabs
defaultValue="json"
values={[{label: 'JSON', value: 'json'},
{label: 'Curl', value: 'bash'},
{label: 'GraphQL', value: 'graphql'},
{label: 'Sparql', value: 'sparql'}]}>
<TabItem value="json">

```json
[{
"_id": "person",
Expand All @@ -97,6 +154,10 @@ After issuing the above transaction, we can issue the below transaction, which w
}]
```

</TabItem>

<TabItem value="bash">

```bash
curl \
-H "Content-Type: application/json" \
Expand All @@ -109,6 +170,10 @@ curl \
https://$FLUREE_ACCOUNT.flur.ee/api/db/transact
```

</TabItem>

<TabItem value="graphql">

```graphql
mutation updateById ($myUpdateByIdTx: JSON) {
transact(tx: $myUpdateByIdTx)
Expand All @@ -119,6 +184,13 @@ mutation updateById ($myUpdateByIdTx: JSON) {
}
```

</TabItem>

<TabItem value="sparql">

```sparql
Transactions not supported in SPARQL
```

</TabItem>
</Tabs>