Skip to content

Commit

Permalink
Add more information to the write function and update syntax case
Browse files Browse the repository at this point in the history
  • Loading branch information
lsgunnlsgunn committed Oct 31, 2024
1 parent f52bf31 commit 2633cd6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions docs/builtins/Database/fold-db.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## fold-db

Use `fold-db` to select rows from a specified `table` using a predicate `query` with both a key and avalue, and then accumulate the results of the query using a `consumer` function.
Use `fold-db` to select rows from a specified `table` using a predicate `query` with both a key and a value, and then accumulate the results of the query using a `consumer` function.
The output is sorted by the ordering of keys.

### Basic syntax
Expand Down Expand Up @@ -40,6 +40,6 @@ The following example demonstrates how to use the `fold-db` function:

In this example:
- `(qry (lambda (k obj) true))` is a predicate that selects all rows.
- `(f (lambda (x) [(at 'firstName x), (at 'b x)]))` is a consumer function that selects the 'firstName' and 'b' fields from each row.
- `(f (lambda (x) [(at 'firstName x), (at 'b x)]))` is a consumer function that selects the "firstName" and "b" fields from each row.

The `fold-db` function is then used to select rows from the `people` table using the predicate `qry` and accumulate the results using the consumer function `f`. The result is a list of accumulated results based on the selected rows and the specified consumer function. The `fold-db` function is useful for iterating over rows in a table and performing operations in Pact contracts.
6 changes: 3 additions & 3 deletions docs/builtins/Database/txlog.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
## txlog

Use `txlog` to return all updates made to a specified table in a particular transaction identified by its transaction identifier.
Use `txlog` to return all updates made to a specified `table` in a particular transaction identified by its transaction identifier.

### Basic syntax

To retrieve all updates made to the specified `table` in a specific transaction identifier, use the following syntax:

```pact
(txlog TABLE TXID)
(txlog table txid)
```

### Arguments
Expand All @@ -17,7 +17,7 @@ Use the following arguments to specify the table and transaction identifier for
| Argument | Type | Description |
| --- | --- | --- |
| `table` | `table: <{row}>` | Specifies the table from which to retrieve updates. |
| `txid` | integer | Specifies the transaction ID (TXID) for which updates are to be retrieved. |
| `txid` | integer | Specifies the transaction identifier (TXID) for which updates are to be retrieved. |

### Return value

Expand Down
12 changes: 9 additions & 3 deletions docs/builtins/Database/write.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
## write

Use `write` to write an entry in the specified table for a given key with the data provided in the object column.
Use `write` to write the specified `{column:value}` object in the specified `table` for a given `key` row.
The `write` function is similar to the `insert` and `update` functions, except that:

- The `insert` function fails if data already exists for the specified `key` row.
- The `update` function fails if data does not exist for the specified `key` row.

In both of these cases, the `write` function can succeed and update the table without failing.

### Basic syntax

To write an entry in a specified `table` for a specific `key` with the provided `object` column data, use the following syntax:
To write an entry in a specified `table` for a specific `key` with the provided `object`, use the following syntax:

```pact
(write TABLE KEY OBJECT)
(write table key object)
```

### Arguments
Expand Down

0 comments on commit 2633cd6

Please sign in to comment.