Skip to content

Commit

Permalink
Merge pull request #3560 from dfinity/jessiemongeon1-patch-4
Browse files Browse the repository at this point in the history
fix: Heading size and code block
  • Loading branch information
jessiemongeon1 authored Oct 1, 2024
2 parents 95cf578 + 3648924 commit c151d3e
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Composite queries are enabled in the following releases:
| Azle | [0.11.0](https://github.com/demergent-labs/azle/releases/tag/0.11.0) |


## Code example
## Sample code
As an example, consider a partitioned key-value store, where a single frontend does the following for a `put` and `get` call:

- First, determines the ID of the data partition canister that holds the value with the given key.
Expand Down Expand Up @@ -75,28 +75,31 @@ fn get(key: u128) -> Option<u128> {
- [x] [Download and install the IC SDK.](/docs/current/developer-docs/getting-started/install/)
- [x] [Download and install git.](https://git-scm.com/downloads)

### Setting up the canisters
### Step 1: Open a terminal window and clone the DFINITY examples repo with the command:
### Setting up the example
- #### Step 1: Open a terminal window and clone the DFINITY examples repo with the command:

```bash
git clone https://github.com/dfinity/examples.git
```

### Step 2: Navigate into the `rust/composite_query/src` directory, start a local replica, and build the frontend canister with the commands:
- #### Step 2: Navigate into the `rust/composite_query/src` directory, start a local replica, and build the frontend canister with the commands:

```bash
cd rust/composite_query/src
dfx start
dfx canister create kv_frontend
dfx build kv_frontend
During compilation of the fronted canister, the backend canister's wasm code will be compiled and inlined in the frontend canister's wasm code.
```

- #### Step 3: Then, install the frontend canister with the command:

### Step 3: Then, install the frontend canister with the command:
```
dfx canister install kv_frontend
```

### Interacting with the canisters
### Step 1: To add a key-value pair via the frontend canister, run the following command:
- #### Step 1: To add a key-value pair via the frontend canister, run the following command:

```bash
dfx canister call kv_frontend put '(1, 1337)'
Expand All @@ -109,7 +112,7 @@ The first call to put might be slow to respond because the data partition canist
The output should resemble the following indicating that no value has previously been registered for this key:
```(null)```

### Step 2: Retrieve the value associated with a key using composite queries with the command:
- #### Step 2: Retrieve the value associated with a key using composite queries with the command:

```bash
dfx canister call kv_frontend get '(1)'
Expand All @@ -120,7 +123,7 @@ The output should resemble the following:

This workflow displays the ability to fetch the value using composite queries with very low latency.

### Comparing composite queries to calls from update functions
## Comparing composite queries to calls from update functions
Let’s now compare the performance of composite query calls with those of an equivalent implementation that leverages calls from update functions. To do this, you will use the `get_update` method, which contains the exact same logic, but is implemented based on update calls. Run the following command in your terminal window:

```bash
Expand Down

0 comments on commit c151d3e

Please sign in to comment.